From 25e82ff5e4192568be92d10167e86c94b98d2abc Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Thu, 24 Jan 2019 03:06:39 -0800 Subject: [PATCH] Fixed issue where we'd incorrectly show input shadow. We might have also scrolled with typing indicators when we shouldn't of. All came down to #isAtBottom() being calculated incorrectly. --- .../securesms/ConversationFragment.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationFragment.java b/src/org/thoughtcrime/securesms/ConversationFragment.java index bd6d1c2efb..19284a1f0f 100644 --- a/src/org/thoughtcrime/securesms/ConversationFragment.java +++ b/src/org/thoughtcrime/securesms/ConversationFragment.java @@ -292,7 +292,7 @@ public class ConversationFragment extends Fragment } if (recipients.size() > 0) { - if (adapter.getHeaderView() == null && getListLayoutManager().findFirstCompletelyVisibleItemPosition() == 0) { + if (adapter.getHeaderView() == null && isAtBottom()) { list.setVerticalScrollBarEnabled(false); list.post(() -> getListLayoutManager().smoothScrollToPosition(requireContext(), 0, 250)); list.postDelayed(() -> list.setVerticalScrollBarEnabled(true), 300); @@ -405,7 +405,7 @@ public class ConversationFragment extends Fragment } public void scrollToBottom() { - if (((LinearLayoutManager) list.getLayoutManager()).findFirstVisibleItemPosition() < SCROLL_ANIMATION_THRESHOLD) { + if (getListLayoutManager().findFirstVisibleItemPosition() < SCROLL_ANIMATION_THRESHOLD) { list.smoothScrollToPosition(0); } else { list.scrollToPosition(0); @@ -644,13 +644,13 @@ public class ConversationFragment extends Fragment } firstLoad = false; } else if (previousOffset > 0) { - int scrollPosition = previousOffset + ((LinearLayoutManager) list.getLayoutManager()).findFirstVisibleItemPosition(); + int scrollPosition = previousOffset + getListLayoutManager().findFirstVisibleItemPosition(); scrollPosition = Math.min(scrollPosition, count - 1); View firstView = list.getLayoutManager().getChildAt(scrollPosition); int pixelOffset = (firstView == null) ? 0 : (firstView.getBottom() - list.getPaddingBottom()); - ((LinearLayoutManager) list.getLayoutManager()).scrollToPositionWithOffset(scrollPosition, pixelOffset); + getListLayoutManager().scrollToPositionWithOffset(scrollPosition, pixelOffset); previousOffset = 0; } @@ -711,10 +711,23 @@ public class ConversationFragment extends Fragment private void scrollToLastSeenPosition(final int lastSeenPosition) { if (lastSeenPosition > 0) { - list.post(() -> ((LinearLayoutManager)list.getLayoutManager()).scrollToPositionWithOffset(lastSeenPosition, list.getHeight())); + list.post(() -> getListLayoutManager().scrollToPositionWithOffset(lastSeenPosition, list.getHeight())); } } + private boolean isAtBottom() { + if (list.getChildCount() == 0) return true; + + int firstVisiblePosition = getListLayoutManager().findFirstVisibleItemPosition(); + + if (getListAdapter().getHeaderView() == typingView) { + RecyclerView.ViewHolder item1 = list.findViewHolderForAdapterPosition(1); + return firstVisiblePosition <= 1 && item1 != null && item1.itemView.getBottom() <= list.getHeight(); + } + + return firstVisiblePosition == 0 && list.getChildAt(0).getBottom() <= list.getHeight(); + } + public interface ConversationFragmentListener { void setThreadId(long threadId); void handleReplyMessage(MessageRecord messageRecord); @@ -774,23 +787,12 @@ public class ConversationFragment extends Fragment } } - private boolean isAtBottom() { - if (list.getChildCount() == 0) return true; - - int firstCompletelyVisiblePosition = ((LinearLayoutManager) list.getLayoutManager()).findFirstCompletelyVisibleItemPosition(); - - if (getListAdapter().getHeaderView() == typingView) { - return firstCompletelyVisiblePosition <= 1; - } - return firstCompletelyVisiblePosition == 0; - } - private boolean isAtZoomScrollHeight() { - return ((LinearLayoutManager) list.getLayoutManager()).findFirstCompletelyVisibleItemPosition() > 4; + return getListLayoutManager().findFirstCompletelyVisibleItemPosition() > 4; } private int getHeaderPositionId() { - return ((LinearLayoutManager)list.getLayoutManager()).findLastVisibleItemPosition(); + return getListLayoutManager().findLastVisibleItemPosition(); } private void bindScrollHeader(HeaderViewHolder headerViewHolder, int positionId) {