@@ -403,11 +403,6 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
403
403
lifecycleCoroutineScope = lifecycleScope
404
404
)
405
405
adapter.visibleMessageViewDelegate = this
406
-
407
- // Register an AdapterDataObserver to scroll us to the bottom of the RecyclerView for if
408
- // we're already near the the bottom and the data changes.
409
- adapter.registerAdapterDataObserver(ConversationAdapterDataObserver (binding.conversationRecyclerView, adapter))
410
-
411
406
adapter
412
407
}
413
408
@@ -817,6 +812,12 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
817
812
}
818
813
}
819
814
}
815
+ } else {
816
+ // If there are new data updated, we'll try to stay scrolled at the bottom (if we were at the bottom).
817
+ // scrolled to bottom has a leniency of 50dp, so if we are within the 50dp but not fully at the bottom, scroll down
818
+ if (binding.conversationRecyclerView.isNearBottom && ! binding.conversationRecyclerView.isFullyScrolled) {
819
+ binding.conversationRecyclerView.smoothScrollToPosition(adapter.itemCount)
820
+ }
820
821
}
821
822
822
823
handleRecyclerViewScrolled()
@@ -2754,17 +2755,4 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
2754
2755
}
2755
2756
}
2756
2757
}
2757
-
2758
- // AdapterDataObserver implementation to scroll us to the bottom of the ConversationRecyclerView
2759
- // when we're already near the bottom and we send or receive a message.
2760
- inner class ConversationAdapterDataObserver (val recyclerView : ConversationRecyclerView , val adapter : ConversationAdapter ) : RecyclerView.AdapterDataObserver() {
2761
- override fun onChanged () {
2762
- super .onChanged()
2763
- // scrolled to bottom has a leniency of 50dp, so if we are within the 50dp but not fully at the bottom, scroll down
2764
- if (recyclerView.isNearBottom && ! recyclerView.isFullyScrolled) {
2765
- recyclerView.smoothScrollToPosition(adapter.itemCount)
2766
- }
2767
- }
2768
- }
2769
-
2770
2758
}
0 commit comments