This commit is contained in:
andrew 2023-05-23 14:56:03 +09:30
parent 8b39c4e56a
commit a295dfb248
2 changed files with 6 additions and 9 deletions

View File

@ -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<Any>) {
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) {

View File

@ -31,7 +31,7 @@ class BlockedContactsViewModel @Inject constructor(private val storage: Storage)
private val listUpdateChannel = Channel<Unit>(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<Recipient>,
val selectedItems: Set<Recipient>
val blockedContacts: List<Recipient> = emptyList(),
val selectedItems: Set<Recipient> = 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()