Deselect all sessions when leaving select mode
This commit is contained in:
parent
5b1bf8a68e
commit
2fc2665ff3
@ -154,7 +154,7 @@ class OtherSessionsFragment :
|
|||||||
|
|
||||||
override fun invalidate() = withState(viewModel) { state ->
|
override fun invalidate() = withState(viewModel) { state ->
|
||||||
if (state.devices is Success) {
|
if (state.devices is Success) {
|
||||||
val devices = state.devices().orEmpty()
|
val devices = state.devices.invoke()
|
||||||
renderDevices(devices, state.currentFilter)
|
renderDevices(devices, state.currentFilter)
|
||||||
updateToolbar(devices, state.isSelectModeEnabled)
|
updateToolbar(devices, state.isSelectModeEnabled)
|
||||||
}
|
}
|
||||||
|
@ -85,16 +85,15 @@ class OtherSessionsViewModel @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleDisableSelectMode() {
|
private fun handleDisableSelectMode() {
|
||||||
// TODO deselect all selected sessions
|
setSelectionForAllDevices(isSelected = false, enableSelectMode = false)
|
||||||
setState { copy(isSelectModeEnabled = false) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleEnableSelectMode(deviceId: String?) {
|
private fun handleEnableSelectMode(deviceId: String?) {
|
||||||
toggleSelectionForDevice(deviceId, true)
|
toggleSelectionForDevice(deviceId, enableSelectMode = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleToggleSelectionForDevice(deviceId: String) = withState { state ->
|
private fun handleToggleSelectionForDevice(deviceId: String) = withState { state ->
|
||||||
toggleSelectionForDevice(deviceId, state.isSelectModeEnabled)
|
toggleSelectionForDevice(deviceId, enableSelectMode = state.isSelectModeEnabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleSelectionForDevice(deviceId: String?, enableSelectMode: Boolean) = withState { state ->
|
private fun toggleSelectionForDevice(deviceId: String?, enableSelectMode: Boolean) = withState { state ->
|
||||||
@ -118,4 +117,20 @@ class OtherSessionsViewModel @AssistedInject constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) }
|
||||||
|
Success(updatedDevices)
|
||||||
|
} else {
|
||||||
|
state.devices
|
||||||
|
}
|
||||||
|
|
||||||
|
setState {
|
||||||
|
copy(
|
||||||
|
devices = updatedDevices,
|
||||||
|
isSelectModeEnabled = enableSelectMode
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user