Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 99565919 authored by Matt Casey's avatar Matt Casey
Browse files

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
parent efc35f89
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -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
+2 −1
Original line number Diff line number Diff line
@@ -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)
    }
}
+23 −1
Original line number Diff line number Diff line
@@ -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")