summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/controls/management/ControlsFavoritingActivity.kt18
-rw-r--r--packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt46
2 files changed, 40 insertions, 24 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 f2303e622f8d..fe1e6328820d 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<ComponentName>(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<Button>(R.id.other_apps).apply {
visibility = View.VISIBLE
setOnClickListener {
- this@ControlsFavoritingActivity.onBackPressed()
+ val i = Intent()
+ i.setComponent(
+ ComponentName(context, ControlsProviderSelectorActivity::class.java))
+ context.startActivity(i)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt
index 6e527e29a848..208d9117e088 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt
@@ -45,6 +45,7 @@ import com.android.systemui.controls.ControlsServiceInfo
import com.android.systemui.controls.controller.ControlInfo
import com.android.systemui.controls.controller.ControlsController
import com.android.systemui.controls.controller.StructureInfo
+import com.android.systemui.controls.management.ControlsFavoritingActivity
import com.android.systemui.controls.management.ControlsListingController
import com.android.systemui.controls.management.ControlsProviderSelectorActivity
import com.android.systemui.dagger.qualifiers.Background
@@ -92,21 +93,8 @@ class ControlsUiControllerImpl @Inject constructor (
private lateinit var lastItems: List<SelectionItem>
private var popup: ListPopupWindow? = null
private var activeDialog: Dialog? = null
- private val addControlsItem: SelectionItem
private var hidden = true
- init {
- val addDrawable = context.getDrawable(R.drawable.ic_add).apply {
- setTint(context.resources.getColor(R.color.control_secondary_text, null))
- }
- addControlsItem = SelectionItem(
- context.resources.getString(R.string.controls_providers_title),
- "",
- addDrawable,
- EMPTY_COMPONENT
- )
- }
-
override val available: Boolean
get() = controlsController.get().available
@@ -184,7 +172,7 @@ class ControlsUiControllerImpl @Inject constructor (
inflater.inflate(R.layout.controls_no_favorites, parent, true)
val viewGroup = parent.requireViewById(R.id.controls_no_favorites_group) as ViewGroup
- viewGroup.setOnClickListener(launchSelectorActivityListener(context))
+ viewGroup.setOnClickListener { v: View -> startProviderSelectorActivity(v.context) }
val subtitle = parent.requireViewById<TextView>(R.id.controls_subtitle)
subtitle.setText(context.resources.getString(R.string.quick_controls_subtitle))
@@ -198,16 +186,28 @@ class ControlsUiControllerImpl @Inject constructor (
}
}
- private fun launchSelectorActivityListener(context: Context): (View) -> Unit {
- return { _ ->
- val closeDialog = Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)
- context.sendBroadcast(closeDialog)
+ private fun startFavoritingActivity(context: Context, si: StructureInfo) {
+ val i = Intent(context, ControlsFavoritingActivity::class.java).apply {
+ putExtra(ControlsFavoritingActivity.EXTRA_APP,
+ controlsListingController.get().getAppLabel(si.componentName))
+ putExtra(ControlsFavoritingActivity.EXTRA_STRUCTURE, si.structure)
+ putExtra(Intent.EXTRA_COMPONENT_NAME, si.componentName)
+ addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
+ }
+ startActivity(context, i)
+ }
- val i = Intent()
- i.setComponent(ComponentName(context, ControlsProviderSelectorActivity::class.java))
- i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
- context.startActivity(i)
+ private fun startProviderSelectorActivity(context: Context) {
+ val i = Intent(context, ControlsProviderSelectorActivity::class.java).apply {
+ addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
}
+ startActivity(context, i)
+ }
+
+ private fun startActivity(context: Context, intent: Intent) {
+ val closeDialog = Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)
+ context.sendBroadcast(closeDialog)
+ context.startActivity(intent)
}
private fun showControlsView(items: List<SelectionItem>) {
@@ -248,7 +248,7 @@ class ControlsUiControllerImpl @Inject constructor (
) {
when (pos) {
// 0: Add Control
- 0 -> launchSelectorActivityListener(view.context)(parent)
+ 0 -> startFavoritingActivity(view.context, selectedStructure)
else -> Log.w(ControlsUiController.TAG,
"Unsupported index ($pos) on 'more' menu selection")
}