Allow action visibility to be toggled.
Adding the bit to the ActionButtonViewModel instead of the appearance
to make it simpler to toggle visibility without having to re-provide all
the labels/images each time.
Bug: 329659738
Test: manual test with toggling visibility in the actions provider after
various delays.
Flag: ACONFIG com.android.systemui.screenshot_shelf_ui DEVELOPMENT
Change-Id: I3c5cae3ff91b364c427394d801fb09a08bdea803
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ui/binder/ScreenshotShelfViewBinder.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ui/binder/ScreenshotShelfViewBinder.kt
index 32e9296..d9a5102 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ui/binder/ScreenshotShelfViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ui/binder/ScreenshotShelfViewBinder.kt
@@ -65,7 +65,9 @@
}
launch {
viewModel.actions.collect { actions ->
- if (actions.isNotEmpty()) {
+ val visibleActions = actions.filter { it.visible }
+
+ if (visibleActions.isNotEmpty()) {
view
.requireViewById<View>(R.id.actions_container_background)
.visibility = View.VISIBLE
@@ -75,7 +77,7 @@
// any new actions and update any that are already there.
// This assumes that actions can never change order and that each action
// ID is unique.
- val newIds = actions.map { it.id }
+ val newIds = visibleActions.map { it.id }
for (view in actionsContainer.children.toList()) {
if (view.tag !in newIds) {
@@ -83,7 +85,7 @@
}
}
- for ((index, action) in actions.withIndex()) {
+ for ((index, action) in visibleActions.withIndex()) {
val currentView: View? = actionsContainer.getChildAt(index)
if (action.id == currentView?.tag) {
// Same ID, update the display
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ui/viewmodel/ActionButtonViewModel.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ui/viewmodel/ActionButtonViewModel.kt
index 64b0105..c5fa8db 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ui/viewmodel/ActionButtonViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ui/viewmodel/ActionButtonViewModel.kt
@@ -19,6 +19,7 @@
data class ActionButtonViewModel(
val appearance: ActionButtonAppearance,
val id: Int,
+ val visible: Boolean,
val onClicked: (() -> Unit)?,
) {
companion object {
@@ -29,6 +30,6 @@
fun withNextId(
appearance: ActionButtonAppearance,
onClicked: (() -> Unit)?
- ): ActionButtonViewModel = ActionButtonViewModel(appearance, getId(), onClicked)
+ ): ActionButtonViewModel = ActionButtonViewModel(appearance, getId(), true, onClicked)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ui/viewmodel/ScreenshotViewModel.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ui/viewmodel/ScreenshotViewModel.kt
index fa34803..f67ad40 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ui/viewmodel/ScreenshotViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ui/viewmodel/ScreenshotViewModel.kt
@@ -48,12 +48,34 @@
return action.id
}
+ fun setActionVisibility(actionId: Int, visible: Boolean) {
+ val actionList = _actions.value.toMutableList()
+ val index = actionList.indexOfFirst { it.id == actionId }
+ if (index >= 0) {
+ actionList[index] =
+ ActionButtonViewModel(
+ actionList[index].appearance,
+ actionId,
+ visible,
+ actionList[index].onClicked
+ )
+ _actions.value = actionList
+ } else {
+ Log.w(TAG, "Attempted to update unknown action id $actionId")
+ }
+ }
+
fun updateActionAppearance(actionId: Int, appearance: ActionButtonAppearance) {
val actionList = _actions.value.toMutableList()
val index = actionList.indexOfFirst { it.id == actionId }
if (index >= 0) {
actionList[index] =
- ActionButtonViewModel(appearance, actionId, actionList[index].onClicked)
+ ActionButtonViewModel(
+ appearance,
+ actionId,
+ actionList[index].visible,
+ actionList[index].onClicked
+ )
_actions.value = actionList
} else {
Log.w(TAG, "Attempted to update unknown action id $actionId")