Skip to content

Commit

Permalink
Remove sticky header on list reinitailization.
Browse files Browse the repository at this point in the history
When we forward a message or share into the app, it is possible that we are going to reuse the same activity. In this case, when the adapter was reinitialized, we were just adding a new ItemDecoration every time.

This fix checks if we've already added one and removes it if necessary, just like the last seen decorator.
  • Loading branch information
alex-signal committed Jul 31, 2020
1 parent eeb0c83 commit 0db73e7
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public class ConversationFragment extends LoggingFragment {
private Locale locale;
private RecyclerView list;
private RecyclerView.ItemDecoration lastSeenDecoration;
private RecyclerView.ItemDecoration stickyHeaderDecoration;
private ViewSwitcher topLoadMoreView;
private ViewSwitcher bottomLoadMoreView;
private ConversationTypingView typingView;
Expand Down Expand Up @@ -435,7 +436,7 @@ private void initializeListAdapter() {
Log.d(TAG, "Initializing adapter for " + recipient.getId());
ConversationAdapter adapter = new ConversationAdapter(GlideApp.with(this), locale, selectionClickListener, this.recipient.get());
list.setAdapter(adapter);
list.addItemDecoration(new StickyHeaderDecoration(adapter, false, false));
setStickyHeaderDecoration(adapter);
ConversationAdapter.initializePool(list.getRecycledViewPool());

adapter.registerAdapterDataObserver(snapToTopDataObserver);
Expand Down Expand Up @@ -573,6 +574,15 @@ public void scrollToBottom() {
}
}

public void setStickyHeaderDecoration(@NonNull ConversationAdapter adapter) {
if (stickyHeaderDecoration != null) {
list.removeItemDecoration(stickyHeaderDecoration);
}

stickyHeaderDecoration = new StickyHeaderDecoration(adapter, false, false);
list.addItemDecoration(stickyHeaderDecoration);
}

public void setLastSeen(long lastSeen) {
if (lastSeenDecoration != null) {
list.removeItemDecoration(lastSeenDecoration);
Expand Down

0 comments on commit 0db73e7

Please sign in to comment.