Handling press on multi signout action in other sessions list screen

This commit is contained in:
Maxime NATUREL 2022-10-20 16:45:31 +02:00
parent 1ed92e5215
commit ae4a728358
3 changed files with 29 additions and 9 deletions

View file

@ -26,4 +26,5 @@ sealed class OtherSessionsAction : VectorViewModelAction {
data class ToggleSelectionForDevice(val deviceId: String) : OtherSessionsAction()
object SelectAll : OtherSessionsAction()
object DeselectAll : OtherSessionsAction()
object MultiSignout : OtherSessionsAction()
}

View file

@ -78,18 +78,27 @@ class OtherSessionsFragment :
menu.findItem(R.id.otherSessionsSelectAll).isVisible = isSelectModeEnabled
menu.findItem(R.id.otherSessionsDeselectAll).isVisible = isSelectModeEnabled
menu.findItem(R.id.otherSessionsSelect).isVisible = !isSelectModeEnabled && state.devices()?.isNotEmpty().orFalse()
val multiSignoutItem = menu.findItem(R.id.otherSessionsMultiSignout)
multiSignoutItem.title = if (isSelectModeEnabled) {
getString(R.string.device_manager_other_sessions_multi_signout_selection).uppercase()
} else {
getString(R.string.device_manager_other_sessions_multi_signout_all)
}
val showAsActionFlag = if (isSelectModeEnabled) MenuItem.SHOW_AS_ACTION_ALWAYS else MenuItem.SHOW_AS_ACTION_NEVER
multiSignoutItem.setShowAsAction(showAsActionFlag or MenuItem.SHOW_AS_ACTION_WITH_TEXT)
changeTextColorOfDestructiveAction(multiSignoutItem)
updateMultiSignoutMenuItem(menu, state)
}
}
private fun updateMultiSignoutMenuItem(menu: Menu, viewState: OtherSessionsViewState) {
val multiSignoutItem = menu.findItem(R.id.otherSessionsMultiSignout)
multiSignoutItem.title = if (viewState.isSelectModeEnabled) {
getString(R.string.device_manager_other_sessions_multi_signout_selection).uppercase()
} else {
getString(R.string.device_manager_other_sessions_multi_signout_all)
}
multiSignoutItem.isVisible = if (viewState.isSelectModeEnabled) {
viewState.devices.invoke()?.any { it.isSelected }.orFalse()
} else {
viewState.devices.invoke()?.isNotEmpty().orFalse()
}
val showAsActionFlag = if (viewState.isSelectModeEnabled) MenuItem.SHOW_AS_ACTION_ALWAYS else MenuItem.SHOW_AS_ACTION_NEVER
multiSignoutItem.setShowAsAction(showAsActionFlag or MenuItem.SHOW_AS_ACTION_WITH_TEXT)
changeTextColorOfDestructiveAction(multiSignoutItem)
}
private fun changeTextColorOfDestructiveAction(menuItem: MenuItem) {
val titleColor = colorProvider.getColorFromAttribute(R.attr.colorError)
menuItem.setTextColor(titleColor)
@ -109,6 +118,10 @@ class OtherSessionsFragment :
viewModel.handle(OtherSessionsAction.DeselectAll)
true
}
R.id.otherSessionsMultiSignout -> {
viewModel.handle(OtherSessionsAction.MultiSignout)
true
}
else -> false
}
}

View file

@ -65,6 +65,7 @@ class OtherSessionsViewModel @AssistedInject constructor(
}
}
// TODO update unit tests
override fun handle(action: OtherSessionsAction) {
when (action) {
is OtherSessionsAction.FilterDevices -> handleFilterDevices(action)
@ -73,6 +74,7 @@ class OtherSessionsViewModel @AssistedInject constructor(
is OtherSessionsAction.ToggleSelectionForDevice -> handleToggleSelectionForDevice(action.deviceId)
OtherSessionsAction.DeselectAll -> handleDeselectAll()
OtherSessionsAction.SelectAll -> handleSelectAll()
OtherSessionsAction.MultiSignout -> handleMultiSignout()
}
}
@ -142,4 +144,8 @@ class OtherSessionsViewModel @AssistedInject constructor(
)
}
}
private fun handleMultiSignout() {
// TODO call multi signout use case with all or only selected devices depending on the ViewState
}
}