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

Commit 6af09306 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Controls UI - Direct 'add controls' to the proper activity" into rvc-dev am: 4552718e

Change-Id: If40eced3b54b8ea96fe11aa0c6bf58aa7124bf67
parents e9f55064 4552718e
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -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)
            }
        }

+23 −23
Original line number Diff line number Diff line
@@ -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")
                            }