1
0
Fork 0

disabled the suggestion scrolling animation when there are too many words for even better performance

This commit is contained in:
sspanak 2025-03-26 11:15:24 +02:00 committed by Dimo Karaivanov
parent 62f8409a34
commit dcdd78486a

View file

@ -38,6 +38,7 @@ public class SuggestionsBar {
@Nullable private List<String> suggestions = new ArrayList<>(); @Nullable private List<String> suggestions = new ArrayList<>();
@NonNull private final List<String> visibleSuggestions = new ArrayList<>(); @NonNull private final List<String> visibleSuggestions = new ArrayList<>();
private final DefaultItemAnimator animator = new DefaultItemAnimator();
private final ResizableMainView mainView; private final ResizableMainView mainView;
private final Runnable onItemClick; private final Runnable onItemClick;
@Nullable private final RecyclerView mView; @Nullable private final RecyclerView mView;
@ -73,8 +74,6 @@ public class SuggestionsBar {
return; return;
} }
DefaultItemAnimator animator = new DefaultItemAnimator();
animator.setMoveDuration(SettingsStore.SUGGESTIONS_SELECT_ANIMATION_DURATION); animator.setMoveDuration(SettingsStore.SUGGESTIONS_SELECT_ANIMATION_DURATION);
animator.setChangeDuration(SettingsStore.SUGGESTIONS_TRANSLATE_ANIMATION_DURATION); animator.setChangeDuration(SettingsStore.SUGGESTIONS_TRANSLATE_ANIMATION_DURATION);
animator.setAddDuration(SettingsStore.SUGGESTIONS_TRANSLATE_ANIMATION_DURATION); animator.setAddDuration(SettingsStore.SUGGESTIONS_TRANSLATE_ANIMATION_DURATION);
@ -197,7 +196,7 @@ public class SuggestionsBar {
setStem(newSuggestions, containsGenerated); setStem(newSuggestions, containsGenerated);
addManySuggestions(newSuggestions, mView != null ? SettingsStore.SUGGESTIONS_MAX : Integer.MAX_VALUE); addManySuggestions(newSuggestions, mView != null ? SettingsStore.SUGGESTIONS_MAX : Integer.MAX_VALUE);
selectedIndex = Math.min(selectedIndex, visibleSuggestions.size() - 1); selectedIndex = Math.min(selectedIndex, visibleSuggestions.size() - 1);
displaySuggestions(); displaySuggestions(visibleSuggestions.size() <= SettingsStore.SUGGESTIONS_MAX);
} }
@ -267,11 +266,12 @@ public class SuggestionsBar {
} }
private void displaySuggestions() { private void displaySuggestions(boolean withScrollAnimation) {
if (mView == null) { if (mView == null) {
return; return;
} }
mView.setItemAnimator(withScrollAnimation ? animator : null);
mSuggestionsAdapter.resetItems(selectedIndex); mSuggestionsAdapter.resetItems(selectedIndex);
if (selectedIndex > 0) { if (selectedIndex > 0) {
mView.scrollToPosition(selectedIndex); mView.scrollToPosition(selectedIndex);