mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 11:59:12 +03:00
Select all/Deselect all actions
This commit is contained in:
parent
2fc2665ff3
commit
a703b8ae10
3 changed files with 20 additions and 0 deletions
|
@ -24,4 +24,6 @@ sealed class OtherSessionsAction : VectorViewModelAction {
|
|||
data class EnableSelectMode(val deviceId: String?) : OtherSessionsAction()
|
||||
object DisableSelectMode : OtherSessionsAction()
|
||||
data class ToggleSelectionForDevice(val deviceId: String) : OtherSessionsAction()
|
||||
object SelectAll : OtherSessionsAction()
|
||||
object DeselectAll : OtherSessionsAction()
|
||||
}
|
||||
|
|
|
@ -85,6 +85,14 @@ class OtherSessionsFragment :
|
|||
enableSelectMode(true)
|
||||
true
|
||||
}
|
||||
R.id.otherSessionsSelectAll -> {
|
||||
viewModel.handle(OtherSessionsAction.SelectAll)
|
||||
true
|
||||
}
|
||||
R.id.otherSessionsDeselectAll -> {
|
||||
viewModel.handle(OtherSessionsAction.DeselectAll)
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,6 +72,8 @@ class OtherSessionsViewModel @AssistedInject constructor(
|
|||
OtherSessionsAction.DisableSelectMode -> handleDisableSelectMode()
|
||||
is OtherSessionsAction.EnableSelectMode -> handleEnableSelectMode(action.deviceId)
|
||||
is OtherSessionsAction.ToggleSelectionForDevice -> handleToggleSelectionForDevice(action.deviceId)
|
||||
OtherSessionsAction.DeselectAll -> handleDeselectAll()
|
||||
OtherSessionsAction.SelectAll -> handleSelectAll()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,6 +120,14 @@ class OtherSessionsViewModel @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleSelectAll() = withState { state ->
|
||||
setSelectionForAllDevices(isSelected = true, enableSelectMode = state.isSelectModeEnabled)
|
||||
}
|
||||
|
||||
private fun handleDeselectAll() = withState { state ->
|
||||
setSelectionForAllDevices(isSelected = false, enableSelectMode = state.isSelectModeEnabled)
|
||||
}
|
||||
|
||||
private fun setSelectionForAllDevices(isSelected: Boolean, enableSelectMode: Boolean) = withState { state ->
|
||||
val updatedDevices = if (state.devices is Success) {
|
||||
val updatedDevices = state.devices.invoke().map { it.copy(isSelected = isSelected) }
|
||||
|
|
Loading…
Reference in a new issue