Clicking on already selected contact will remove it from the selection

This commit is contained in:
Sylvain Berfini 2024-11-05 17:01:28 +01:00
parent c88917ac68
commit 135ca527ee
2 changed files with 19 additions and 2 deletions

View file

@ -147,6 +147,23 @@ abstract class GenericAddressPickerFragment : GenericMainFragment() {
}
private fun handleClickOnContactModel(model: ConversationContactOrSuggestionModel) {
if (model.selected.value == true) {
Log.i(
"$TAG User clicked on already selected item [${model.name}], removing it from selection"
)
val found = viewModel.selection.value.orEmpty().find {
it.address.weakEqual(model.address) || it.avatarModel?.friend == model.friend
}
if (found != null) {
coreContext.postOnCoreThread {
viewModel.removeAddressModelFromSelection(found)
}
return
} else {
Log.e("$TAG Failed to find already selected entry matching the one clicked")
}
}
coreContext.postOnCoreThread { core ->
val friend = model.friend
if (friend == null) {

View file

@ -159,7 +159,7 @@ abstract class AddressSelectionViewModel @UiThread constructor() : DefaultAccoun
list.addAll(actual)
val found = modelsList.value.orEmpty().find {
it.address.weakEqual(model.address)
it.address.weakEqual(model.address) || it.friend == model.avatarModel?.friend
}
found?.selected?.postValue(true)
@ -191,7 +191,7 @@ abstract class AddressSelectionViewModel @UiThread constructor() : DefaultAccoun
list.remove(model)
val found = modelsList.value.orEmpty().find {
it.address.weakEqual(model.address)
it.address.weakEqual(model.address) || it.friend == model.avatarModel?.friend
}
found?.selected?.postValue(false)