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

Commit 8fd912f6 authored by Matt Casey's avatar Matt Casey Committed by Android (Google) Code Review
Browse files

Merge "Apply diffs to screenshot action updates" into main

parents 0504c11c 0d04bdb4
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 }
    }
}