From 3359fbcbd7b99e7dc4d9e6a4f6fa4acd59ea4661 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 29 Aug 2024 17:06:03 +0200 Subject: [PATCH] Fixed history/conversations list scroll position not retained upon rotation --- .../ui/main/chat/fragment/ConversationsListFragment.kt | 3 --- .../ui/main/history/fragment/HistoryListFragment.kt | 10 +++++++--- .../ui/main/history/viewmodel/HistoryListViewModel.kt | 7 ++++++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationsListFragment.kt b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationsListFragment.kt index 19e8e9c99..6a7458ac6 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationsListFragment.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationsListFragment.kt @@ -337,9 +337,6 @@ class ConversationsListFragment : AbstractMainFragment() { } catch (e: IllegalStateException) { Log.e("$TAG Failed to unregister data observer to adapter: $e") } - - // Scroll to top when fragment is resumed - binding.conversationsList.scrollToPosition(0) } override fun onPause() { diff --git a/app/src/main/java/org/linphone/ui/main/history/fragment/HistoryListFragment.kt b/app/src/main/java/org/linphone/ui/main/history/fragment/HistoryListFragment.kt index 434118732..de9c5f35b 100644 --- a/app/src/main/java/org/linphone/ui/main/history/fragment/HistoryListFragment.kt +++ b/app/src/main/java/org/linphone/ui/main/history/fragment/HistoryListFragment.kt @@ -195,6 +195,13 @@ class HistoryListFragment : AbstractMainFragment() { listViewModel.fetchInProgress.value = false } + listViewModel.historyInsertedEvent.observe(viewLifecycleOwner) { + it.consume { + // Scroll to top to display latest call log + binding.historyList.scrollToPosition(0) + } + } + listViewModel.historyDeletedEvent.observe(viewLifecycleOwner) { it.consume { Log.w("$TAG All call logs have been deleted") @@ -262,9 +269,6 @@ class HistoryListFragment : AbstractMainFragment() { Log.i("$TAG Fragment is resumed, resetting missed calls count") sharedViewModel.resetMissedCallsCountEvent.value = Event(true) sharedViewModel.refreshDrawerMenuAccountsListEvent.value = Event(false) - - // Scroll to top to display latest call logs - binding.historyList.scrollToPosition(0) } private fun copyNumberOrAddressToClipboard(value: String) { diff --git a/app/src/main/java/org/linphone/ui/main/history/viewmodel/HistoryListViewModel.kt b/app/src/main/java/org/linphone/ui/main/history/viewmodel/HistoryListViewModel.kt index d0f3ca464..bb480311a 100644 --- a/app/src/main/java/org/linphone/ui/main/history/viewmodel/HistoryListViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/history/viewmodel/HistoryListViewModel.kt @@ -43,6 +43,10 @@ class HistoryListViewModel @UiThread constructor() : AbstractMainViewModel() { val fetchInProgress = MutableLiveData() + val historyInsertedEvent: MutableLiveData> by lazy { + MutableLiveData>() + } + val historyDeletedEvent: MutableLiveData> by lazy { MutableLiveData>() } @@ -56,8 +60,9 @@ class HistoryListViewModel @UiThread constructor() : AbstractMainViewModel() { } override fun onCallLogUpdated(core: Core, callLog: CallLog) { - Log.i("$TAG A call log was updated, updating list") + Log.i("$TAG A call log was created, updating list") computeCallLogsList(currentFilter) + historyInsertedEvent.postValue(Event(true)) } }