Fix scrolling to last seen.

This commit is contained in:
Greyson Parrelli
2022-05-18 17:51:00 -04:00
committed by GitHub
parent 153feb002e
commit 05975a0068

View File

@@ -203,6 +203,7 @@ public class ConversationFragment extends LoggingFragment implements Multiselect
private static final int SCROLL_ANIMATION_THRESHOLD = 50;
private static final int CODE_ADD_EDIT_CONTACT = 77;
private static final int MAX_SCROLL_DELAY_COUNT = 5;
private final ActionModeCallback actionModeCallback = new ActionModeCallback();
private final ItemClickListener selectionClickListener = new ConversationFragmentItemClickListener();
@@ -1196,7 +1197,7 @@ public class ConversationFragment extends LoggingFragment implements Multiselect
.submit();
} else if (conversation.getMessageRequestData().isMessageRequestAccepted()) {
snapToTopDataObserver.buildScrollPosition(conversation.shouldScrollToLastSeen() ? lastSeenPosition : lastScrolledPosition)
.withOnPerformScroll((layoutManager, position) -> layoutManager.scrollToPositionWithOffset(position, list.getHeight() - (conversation.shouldScrollToLastSeen() ? lastSeenScrollOffset : 0)))
.withOnPerformScroll((layoutManager, position) -> scrollToLastSeenIfNecessary(conversation, layoutManager, position, 0))
.withOnScrollRequestComplete(afterScroll)
.submit();
} else {
@@ -1206,6 +1207,25 @@ public class ConversationFragment extends LoggingFragment implements Multiselect
}
}
private void scrollToLastSeenIfNecessary(ConversationData conversation, LinearLayoutManager layoutManager, int position, int count) {
if (getView() == null) {
Log.w(TAG, "[scrollToLastSeenIfNecessary] No view! Skipping.");
return;
}
if (count < MAX_SCROLL_DELAY_COUNT && (list.getHeight() == 0 || lastSeenScrollOffset == 0)) {
Log.w(TAG, "[scrollToLastSeenIfNecessary] List height or scroll offsets not available yet. Delaying jumping to last seen.");
requireView().post(() -> scrollToLastSeenIfNecessary(conversation, layoutManager, position, count + 1));
} else {
if (count >= MAX_SCROLL_DELAY_COUNT) {
Log.w(TAG, "[scrollToLastSeeenIfNecessary] Hit maximum call count! Doing default behavior.");
}
int offset = list.getHeight() - (conversation.shouldScrollToLastSeen() ? lastSeenScrollOffset : 0);
layoutManager.scrollToPositionWithOffset(position, offset);
}
}
private void updateNotificationProfileStatus(@NonNull Optional<NotificationProfile> activeProfile) {
if (activeProfile.isPresent() && activeProfile.get().getId() != SignalStore.notificationProfileValues().getLastProfilePopup()) {
requireView().postDelayed(() -> {