Fix behavior of the new entry highlight in case no scroll is needed

This commit is contained in:
Alexander Bakker 2021-01-27 20:42:39 +01:00
parent f4bdf4645b
commit ad138e4a4c

View file

@ -287,7 +287,6 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
public void addEntry(VaultEntry entry) { public void addEntry(VaultEntry entry) {
addEntry(entry, false); addEntry(entry, false);
} }
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
@ -295,16 +294,19 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
int position = _adapter.addEntry(entry); int position = _adapter.addEntry(entry);
updateEmptyState(); updateEmptyState();
LinearLayoutManager layoutManager = (LinearLayoutManager) _recyclerView.getLayoutManager();
if (focusEntry && position >= 0) { if (focusEntry && position >= 0) {
int last = layoutManager.findLastVisibleItemPosition();
int first = layoutManager.findFirstVisibleItemPosition();
if ((_recyclerView.canScrollVertically(1) && position > layoutManager.findLastCompletelyVisibleItemPosition())
|| (_recyclerView.canScrollVertically(-1) && position < layoutManager.findFirstCompletelyVisibleItemPosition())) {
RecyclerView.OnScrollListener scrollListener = new RecyclerView.OnScrollListener() { RecyclerView.OnScrollListener scrollListener = new RecyclerView.OnScrollListener() {
@Override @Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_IDLE) { if (newState == RecyclerView.SCROLL_STATE_IDLE) {
_recyclerView.removeOnScrollListener(this); _recyclerView.removeOnScrollListener(this);
_adapter.setTempHighlightEntry(true); _recyclerView.setOnTouchListener(null);
tempHighlightEntry(entry);
final int secondsToFocus = 3;
_adapter.focusEntry(entry, secondsToFocus);
} }
} }
}; };
@ -319,8 +321,18 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
return false; return false;
}); });
_recyclerView.smoothScrollToPosition(position); _recyclerView.smoothScrollToPosition(position);
} else {
tempHighlightEntry(entry);
} }
} }
}
public void tempHighlightEntry(VaultEntry entry) {
_adapter.setTempHighlightEntry(true);
final int secondsToFocus = 3;
_adapter.focusEntry(entry, secondsToFocus);
}
public void addEntries(Collection<VaultEntry> entries) { public void addEntries(Collection<VaultEntry> entries) {
_adapter.addEntries(entries); _adapter.addEntries(entries);