Fix reload of chat rooms when toggling one of the two hide chat room setting

This commit is contained in:
Sylvain Berfini 2022-04-19 10:54:08 +02:00
parent 0d363a6868
commit 8f291145d2
9 changed files with 28 additions and 3 deletions

View file

@ -141,7 +141,7 @@ class ChatRoomsListViewModel : MessageNotifierViewModel() {
}
}
private fun updateChatRooms() {
fun updateChatRooms() {
chatRooms.value.orEmpty().forEach(ChatRoomViewModel::destroy)
val list = arrayListOf<ChatRoomViewModel>()

View file

@ -26,6 +26,7 @@ import android.provider.Settings
import android.view.View
import androidx.lifecycle.ViewModelProvider
import org.linphone.R
import org.linphone.activities.main.chat.viewmodels.ChatRoomsListViewModel
import org.linphone.activities.main.settings.viewmodels.ChatSettingsViewModel
import org.linphone.activities.navigateToEmptySetting
import org.linphone.compatibility.Compatibility
@ -81,6 +82,12 @@ class ChatSettingsFragment : GenericSettingFragment<SettingsChatFragmentBinding>
}
}
}
viewModel.reloadChatRoomsEvent.observe(viewLifecycleOwner) {
it.consume {
reloadChatRooms()
}
}
}
override fun goBack() {
@ -90,4 +97,11 @@ class ChatSettingsFragment : GenericSettingFragment<SettingsChatFragmentBinding>
navigateToEmptySetting()
}
}
private fun reloadChatRooms() {
val listViewModel = requireActivity().run {
ViewModelProvider(this)[ChatRoomsListViewModel::class.java]
}
listViewModel.updateChatRooms()
}
}

View file

@ -116,6 +116,7 @@ class ChatSettingsViewModel : GenericSettingsViewModel() {
val hideEmptyRoomsListener = object : SettingListenerStub() {
override fun onBoolValueChanged(newValue: Boolean) {
prefs.hideEmptyRooms = newValue
reloadChatRoomsEvent.value = Event(true)
}
}
val hideEmptyRooms = MutableLiveData<Boolean>()
@ -123,6 +124,7 @@ class ChatSettingsViewModel : GenericSettingsViewModel() {
val hideRoomsRemovedProxiesListener = object : SettingListenerStub() {
override fun onBoolValueChanged(newValue: Boolean) {
prefs.hideRoomsFromRemovedProxies = newValue
reloadChatRoomsEvent.value = Event(true)
}
}
val hideRoomsRemovedProxies = MutableLiveData<Boolean>()
@ -136,6 +138,10 @@ class ChatSettingsViewModel : GenericSettingsViewModel() {
val vfs = MutableLiveData<Boolean>()
val reloadChatRoomsEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
init {
markAsReadNotifDismissal.value = prefs.markAsReadUponChatMessageNotificationDismissal
downloadedMediaPublic.value = prefs.makePublicMediaFilesDownloaded && !prefs.vfsEnabled

View file

@ -2,6 +2,7 @@
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/assistant_nav_graph"
app:startDestination="@id/welcomeFragment">
<fragment

View file

@ -2,7 +2,7 @@
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/chat_nav_graph.xml"
android:id="@+id/chat_nav_graph"
app:startDestination="@id/emptyChatFragment">
<fragment

View file

@ -2,6 +2,7 @@
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/contacts_nav_graph"
app:startDestination="@id/emptyContactFragment">
<fragment
@ -25,7 +26,7 @@
<action
android:id="@+id/action_detailContactFragment_to_detailChatRoomFragment"
app:destination="@id/chat_nav_graph.xml" />
app:destination="@id/chat_nav_graph" />
</fragment>
<action

View file

@ -2,6 +2,7 @@
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/history_nav_graph"
app:startDestination="@id/emptyCallHistoryFragment">
<fragment

View file

@ -2,6 +2,7 @@
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_nav_graph"
app:startDestination="@id/dialerFragment">
<fragment

View file

@ -2,6 +2,7 @@
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/settings_nav_graph"
app:startDestination="@id/emptySettingsFragment">
<fragment