Fixed missed call(s) indicator not visible or not hidden in drawer menu

This commit is contained in:
Sylvain Berfini 2024-05-17 15:47:28 +02:00
parent 701117474e
commit 458f817142
5 changed files with 21 additions and 3 deletions

View file

@ -78,6 +78,10 @@ abstract class AbstractMainFragment : GenericMainFragment() {
viewModel.applyFilter(filter.trim())
}
viewModel.missedCallsCount.observe(viewLifecycleOwner) {
sharedViewModel.refreshDrawerMenuAccountsListEvent.value = Event(false)
}
viewModel.navigateToContactsEvent.observe(viewLifecycleOwner) {
it.consume {
if (currentFragmentId != R.id.contactsListFragment) {

View file

@ -129,8 +129,12 @@ class DrawerMenuFragment : GenericMainFragment() {
}
sharedViewModel.refreshDrawerMenuAccountsListEvent.observe(viewLifecycleOwner) {
it.consume {
viewModel.updateAccountsList()
it.consume { recreate ->
if (recreate) {
viewModel.updateAccountsList()
} else {
viewModel.refreshAccountsNotificationsCount()
}
}
}
}

View file

@ -261,6 +261,7 @@ 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)

View file

@ -230,7 +230,7 @@ class AccountModel @WorkerThread constructor(
}
@WorkerThread
private fun computeNotificationsCount() {
fun computeNotificationsCount() {
notificationsCount.postValue(account.unreadChatMessageCount + account.missedCallsCount)
}
}

View file

@ -148,6 +148,15 @@ class DrawerMenuViewModel @UiThread constructor() : GenericViewModel() {
}
}
@UiThread
fun refreshAccountsNotificationsCount() {
coreContext.postOnCoreThread {
for (model in accounts.value.orEmpty()) {
model.computeNotificationsCount()
}
}
}
@WorkerThread
private fun computeAccountsList() {
accounts.value.orEmpty().forEach(AccountModel::destroy)