diff options
5 files changed, 38 insertions, 23 deletions
diff --git a/packages/SystemUI/res/layout/screenshot_shelf.xml b/packages/SystemUI/res/layout/screenshot_shelf.xml index c988b4afcf74..eeb64bd8460e 100644 --- a/packages/SystemUI/res/layout/screenshot_shelf.xml +++ b/packages/SystemUI/res/layout/screenshot_shelf.xml @@ -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" diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotActionsProvider.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotActionsProvider.kt index 19c0b16d8986..60c44309fb07 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotActionsProvider.kt +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotActionsProvider.kt @@ -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) } diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ui/binder/ActionButtonViewBinder.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ui/binder/ActionButtonViewBinder.kt index c7fe3f608a2f..a6374ae3304d 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ui/binder/ActionButtonViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ui/binder/ActionButtonViewBinder.kt @@ -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 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 b191a1a52616..32e9296107a3 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 @@ -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,21 +70,36 @@ 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) } } } 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 05bfed159527..97b24c1b7df7 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 @@ -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 } + } +} |