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

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

Apply diffs to screenshot action updates

Adds a button ID so that updates can be differentiated from
adds/removes.

System assumes that IDs are unique and that actions do not swap order
(would have to be an remove/add with a novel ID).

Bug: 329659738
Test: manual test with logging
Flag: ACONFIG com.android.systemui.screenshot_shelf_ui DEVELOPMENT
Change-Id: I5753511ad7c3ebbe189948ffc10cf2c02ef5b688
Merged-In: I5753511ad7c3ebbe189948ffc10cf2c02ef5b688
parent f13c08bc
Loading
Loading
Loading
Loading
+1 −9
Original line number Diff line number Diff line
@@ -51,15 +51,7 @@
        <LinearLayout
            android:id="@+id/screenshot_actions"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <include layout="@layout/overlay_action_chip"
                     android:id="@+id/screenshot_share_chip"/>
            <include layout="@layout/overlay_action_chip"
                     android:id="@+id/screenshot_edit_chip"/>
            <include layout="@layout/overlay_action_chip"
                     android:id="@+id/screenshot_scroll_chip"
                     android:visibility="gone" />
        </LinearLayout>
            android:layout_height="wrap_content" />
    </HorizontalScrollView>
    <View
        android:id="@+id/screenshot_preview_border"
+2 −2
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ constructor(
                        ActionButtonViewModel(
                            quickShare.getIcon().loadDrawable(context),
                            quickShare.title,
                            quickShare.title
                            quickShare.title,
                        ) {
                            debugLog(LogConfig.DEBUG_ACTIONS) { "Quickshare tapped" }
                            onDeferrableActionTapped { result ->
@@ -180,7 +180,7 @@ constructor(
                        ActionButtonViewModel(
                            it.getIcon().loadDrawable(context),
                            it.title,
                            it.title
                            it.title,
                        ) {
                            sendPendingIntent(it.actionIntent)
                        }
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ object ActionButtonViewBinder {
        } else {
            view.setOnClickListener(null)
        }
        view.tag = viewModel.id
        view.contentDescription = viewModel.description
        view.visibility = View.VISIBLE
        view.alpha = 1f
+24 −10
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.systemui.screenshot.ui.binder

import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -71,22 +70,37 @@ object ScreenshotShelfViewBinder {
                                    .requireViewById<View>(R.id.actions_container_background)
                                    .visibility = View.VISIBLE
                            }
                            val viewPool = actionsContainer.children.toList()
                            actionsContainer.removeAllViews()
                            val actionButtons =
                                List(actions.size) {
                                    viewPool.getOrElse(it) {

                            // Remove any buttons not in the new list, then do another pass to add
                            // 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 }

                            for (view in actionsContainer.children.toList()) {
                                if (view.tag !in newIds) {
                                    actionsContainer.removeView(view)
                                }
                            }

                            for ((index, action) in actions.withIndex()) {
                                val currentView: View? = actionsContainer.getChildAt(index)
                                if (action.id == currentView?.tag) {
                                    // Same ID, update the display
                                    ActionButtonViewBinder.bind(currentView, action)
                                } else {
                                    // Different ID. Removals have already happened so this must
                                    // mean that the new action must be inserted here.
                                    val actionButton =
                                        layoutInflater.inflate(
                                            R.layout.overlay_action_chip,
                                            actionsContainer,
                                            false
                                        )
                                    actionsContainer.addView(actionButton, index)
                                    ActionButtonViewBinder.bind(actionButton, action)
                                }
                            }
                            actionButtons.zip(actions).forEach {
                                actionsContainer.addView(it.first)
                                ActionButtonViewBinder.bind(it.first, it.second)
                            }
                        }
                    }
                }
+10 −2
Original line number Diff line number Diff line
@@ -22,5 +22,13 @@ data class ActionButtonViewModel(
    val icon: Drawable?,
    val name: CharSequence?,
    val description: CharSequence,
    val onClicked: (() -> Unit)?
)
    val onClicked: (() -> Unit)?,
) {
    val id: Int = getId()

    companion object {
        private var nextId = 0

        private fun getId() = nextId.also { nextId += 1 }
    }
}