diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsAdapter.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsAdapter.kt index 1bd3b28610..a75d53c4f1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsAdapter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsAdapter.kt @@ -28,14 +28,12 @@ class BlockedContactsAdapter(val viewModel: BlockedContactsViewModel) : ListAdap .let(::ViewHolder) override fun onBindViewHolder(holder: ViewHolder, position: Int) { - val selectable = getItem(position) - holder.bind(selectable, viewModel::toggle) + holder.bind(getItem(position), viewModel::toggle) } override fun onBindViewHolder(holder: ViewHolder, position: Int, payloads: MutableList) { - val selectable = getItem(position) - if (payloads.isEmpty()) holder.bind(selectable, viewModel::toggle) - else holder.select(selectable.isSelected) + if (payloads.isEmpty()) holder.bind(getItem(position), viewModel::toggle) + else holder.select(getItem(position).isSelected) } override fun onViewRecycled(holder: ViewHolder) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsViewModel.kt index 0c93b2cc09..b5d7995506 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsViewModel.kt @@ -31,7 +31,7 @@ class BlockedContactsViewModel @Inject constructor(private val storage: Storage) private val listUpdateChannel = Channel(capacity = Channel.CONFLATED) - private val _state = MutableLiveData(BlockedContactsViewState(emptyList(), emptySet())) + private val _state = MutableLiveData(BlockedContactsViewState()) val state get() = _state.value!! @@ -110,12 +110,11 @@ class BlockedContactsViewModel @Inject constructor(private val storage: Storage) } data class BlockedContactsViewState( - val blockedContacts: List, - val selectedItems: Set + val blockedContacts: List = emptyList(), + val selectedItems: Set = emptySet() ) { val items = blockedContacts.map { SelectableItem(it, it in selectedItems) } - val isEmpty get() = blockedContacts.isEmpty() val unblockButtonEnabled get() = selectedItems.isNotEmpty() val emptyStateMessageTextViewVisible get() = blockedContacts.isEmpty() val nonEmptyStateGroupVisible get() = blockedContacts.isNotEmpty()