From d2ea531bc4cdd4117dc3f1c64b14aa5010a4ee22 Mon Sep 17 00:00:00 2001 From: Matt Pietal Date: Mon, 6 Apr 2020 11:27:02 -0400 Subject: [PATCH] Controls UI - Direct 'add controls' to the proper activity If there's more than one structure, set to the proper page in the ViewPager. Fix the backstack so 'see other apps' works properly. Bug: 153017283 Test: manual, use 'add controls' menu Change-Id: Ie99537dee841817c8d790e00fe50c800a90c6158 --- .../management/ControlsFavoritingActivity.kt | 18 ++++++- .../controls/ui/ControlsUiControllerImpl.kt | 48 +++++++++---------- 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsFavoritingActivity.kt b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsFavoritingActivity.kt index f2303e622f8de..fe1e6328820dc 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsFavoritingActivity.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsFavoritingActivity.kt @@ -55,13 +55,19 @@ class ControlsFavoritingActivity @Inject constructor( companion object { private const val TAG = "ControlsFavoritingActivity" + + // If provided and no structure is available, use as the title const val EXTRA_APP = "extra_app_label" + + // If provided, show this structure page first + const val EXTRA_STRUCTURE = "extra_structure" private const val TOOLTIP_PREFS_KEY = Prefs.Key.CONTROLS_STRUCTURE_SWIPE_TOOLTIP_COUNT private const val TOOLTIP_MAX_SHOWN = 2 } private var component: ComponentName? = null private var appName: CharSequence? = null + private var structureExtra: CharSequence? = null private lateinit var structurePager: ViewPager2 private lateinit var statusText: TextView @@ -111,6 +117,7 @@ class ControlsFavoritingActivity @Inject constructor( val collator = Collator.getInstance(resources.configuration.locales[0]) comparator = compareBy(collator) { it.structureName } appName = intent.getCharSequenceExtra(EXTRA_APP) + structureExtra = intent.getCharSequenceExtra(EXTRA_STRUCTURE) ?: "" component = intent.getParcelableExtra(Intent.EXTRA_COMPONENT_NAME) bindViews() @@ -137,9 +144,15 @@ class ControlsFavoritingActivity @Inject constructor( listOfStructures = controlsByStructure.map { StructureContainer(it.key, AllModel(it.value, favoriteKeys, emptyZoneString)) }.sortedWith(comparator) + + val structureIndex = listOfStructures.indexOfFirst { + sc -> sc.structureName == structureExtra + }.let { if (it == -1) 0 else it } + executor.execute { doneButton.isEnabled = true structurePager.adapter = StructureAdapter(listOfStructures) + structurePager.setCurrentItem(structureIndex) if (error) { statusText.text = resources.getText(R.string.controls_favorite_load_error) } else { @@ -247,7 +260,10 @@ class ControlsFavoritingActivity @Inject constructor( requireViewById