diff options
3 files changed, 30 insertions, 5 deletions
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 32e9296107a3..d9a51029d346 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 @@ object ScreenshotShelfViewBinder { } 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 @@ object ScreenshotShelfViewBinder { // 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 @@ object ScreenshotShelfViewBinder { } } - 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 64b0105a98a0..c5fa8db953fa 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 @@ package com.android.systemui.screenshot.ui.viewmodel data class ActionButtonViewModel( val appearance: ActionButtonAppearance, val id: Int, + val visible: Boolean, val onClicked: (() -> Unit)?, ) { companion object { @@ -29,6 +30,6 @@ data class ActionButtonViewModel( 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 fa3480343ea0..f67ad402a738 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 @@ class ScreenshotViewModel(private val accessibilityManager: AccessibilityManager 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") |