Fixed favourite status in contacts list not matching reality after a change

This commit is contained in:
Sylvain Berfini 2023-11-29 09:40:25 +01:00
parent 9070b77b30
commit 3e7e2000d5
4 changed files with 9 additions and 4 deletions

View file

@ -143,6 +143,7 @@ class ContactsListAdapter(
override fun areContentsTheSame(oldItem: ContactAvatarModel, newItem: ContactAvatarModel): Boolean { override fun areContentsTheSame(oldItem: ContactAvatarModel, newItem: ContactAvatarModel): Boolean {
return oldItem.presenceStatus.value == newItem.presenceStatus.value && return oldItem.presenceStatus.value == newItem.presenceStatus.value &&
oldItem.isFavourite.value == newItem.isFavourite.value &&
(newItem.presenceStatus.value == ConsolidatedPresence.Busy || newItem.presenceStatus.value == ConsolidatedPresence.Online) (newItem.presenceStatus.value == ConsolidatedPresence.Busy || newItem.presenceStatus.value == ConsolidatedPresence.Online)
} }
} }

View file

@ -202,7 +202,7 @@ class ContactsListFragment : AbstractTopBarFragment() {
adapter.contactLongClickedEvent.observe(viewLifecycleOwner) { adapter.contactLongClickedEvent.observe(viewLifecycleOwner) {
it.consume { model -> it.consume { model ->
val modalBottomSheet = ContactsListMenuDialogFragment( val modalBottomSheet = ContactsListMenuDialogFragment(
model.starred, model.isFavourite.value == true,
{ // onDismiss { // onDismiss
adapter.resetSelection() adapter.resetSelection()
}, },
@ -211,7 +211,7 @@ class ContactsListFragment : AbstractTopBarFragment() {
model.friend.edit() model.friend.edit()
val starred = !model.friend.starred val starred = !model.friend.starred
Log.i( Log.i(
"$TAG Friend [${model.name.value}] will be ${if (starred) "added" else "removed"} from favourites" "$TAG Friend [${model.name.value}] will be ${if (starred) "added to" else "removed from"} favourites"
) )
model.friend.starred = starred model.friend.starred = starred
model.friend.done() model.friend.done()

View file

@ -44,7 +44,7 @@ class ContactAvatarModel @WorkerThread constructor(val friend: Friend) : Abstrac
val contactName = friend.name val contactName = friend.name
val starred = friend.starred val isFavourite = MutableLiveData<Boolean>()
val lastPresenceInfo = MutableLiveData<String>() val lastPresenceInfo = MutableLiveData<String>()
@ -69,6 +69,7 @@ class ContactAvatarModel @WorkerThread constructor(val friend: Friend) : Abstrac
friend.addListener(friendListener) friend.addListener(friendListener)
} }
isFavourite.postValue(friend.starred)
initials.postValue(AppUtils.getInitials(friend.name.orEmpty())) initials.postValue(AppUtils.getInitials(friend.name.orEmpty()))
trust.postValue(SecurityLevel.Encrypted) // TODO FIXME: use API trust.postValue(SecurityLevel.Encrypted) // TODO FIXME: use API
showTrust.postValue(coreContext.core.defaultAccount?.isInSecureMode()) showTrust.postValue(coreContext.core.defaultAccount?.isInSecureMode())

View file

@ -78,6 +78,7 @@ class ContactsListViewModel @UiThread constructor() : AbstractTopBarViewModel()
@WorkerThread @WorkerThread
override fun onContactsLoaded() { override fun onContactsLoaded() {
Log.i("$TAG Contacts have been (re)loaded, updating list") Log.i("$TAG Contacts have been (re)loaded, updating list")
magicSearch.resetSearchCache()
applyFilter( applyFilter(
currentFilter, currentFilter,
if (limitSearchToLinphoneAccounts) corePreferences.defaultDomain else "", if (limitSearchToLinphoneAccounts) corePreferences.defaultDomain else "",
@ -226,7 +227,9 @@ class ContactsListViewModel @UiThread constructor() : AbstractTopBarViewModel()
list.add(model) list.add(model)
count += 1 count += 1
if (friend?.starred == true) { val starred = friend?.starred ?: false
model.isFavourite.postValue(starred)
if (starred) {
favouritesList.add(model) favouritesList.add(model)
} }