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

Commit 71fd3759 authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Add search highlight for mobile data

Fix: 411421672
Flag: EXEMPT bug fix
Test: manual - search mobile data
Change-Id: Ie9c848f575864316c2642cb2dd921234dd2b137c
parent 06e64c1e
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -25,12 +25,17 @@ import com.android.settingslib.spa.framework.util.appendSpaParams

data class SpaDestination(
    val destination: String,
    val highlightMenuKey: String?,
    /** The key to highlight the item. */
    val highlightItemKey: String? = null,
    /** The key to highlight the top level menu, when multi pane is enabled. */
    val highlightMenuKey: String? = null,
) {
    fun startFromExportedActivity(context: Context) {
        val intent = Intent(context, SpaActivity::class.java)
        val intent =
            Intent(context, SpaActivity::class.java)
                .appendSpaParams(
                    destination = destination,
                    highlightItemKey = highlightItemKey,
                    sessionName = SESSION_EXTERNAL,
                )
        if (!ActivityEmbeddingUtils.isEmbeddingActivityEnabled(context) ||
+19 −6
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settings.spa.network

import android.content.Context
import androidx.annotation.VisibleForTesting
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
@@ -28,14 +29,25 @@ import com.android.settings.R
import com.android.settings.network.telephony.MobileDataRepository
import com.android.settings.network.telephony.SubscriptionActivationRepository
import com.android.settings.network.telephony.subscriptionManager
import com.android.settingslib.spa.framework.compose.HighlightBox
import com.android.settingslib.spa.framework.compose.rememberContext
import com.android.settingslib.spa.search.SearchablePage.SearchItem
import com.android.settingslib.spa.widget.preference.SwitchPreference
import com.android.settingslib.spa.widget.preference.SwitchPreferenceModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

private const val MOBILE_DATA_HIGHLIGHT_KEY = "mobile_data"

fun getMobileDataSearchItem(context: Context) =
    SearchItem(
        highlightItemKey = MOBILE_DATA_HIGHLIGHT_KEY,
        itemTitle = context.getString(R.string.mobile_data_settings_title),
    )

@Composable
fun MobileDataSwitchPreference(subId: Int) {
    HighlightBox(highlightItemKey = MOBILE_DATA_HIGHLIGHT_KEY) {
        MobileDataSwitchPreference(
            subId = subId,
            mobileDataRepository = rememberContext(::MobileDataRepository),
@@ -43,6 +55,7 @@ fun MobileDataSwitchPreference(subId: Int) {
            setMobileData = setMobileDataImpl(subId),
        )
    }
}

@VisibleForTesting
@Composable
+1 −1
Original line number Diff line number Diff line
@@ -200,7 +200,7 @@ open class NetworkCellularGroupProvider : SettingsPageProvider, SearchablePage {
        if (!isPageSearchable(context)) return emptyList()
        return buildList {
            if (context.requireSubscriptionManager().activeSubscriptionInfoCount > 0) {
                add(SearchItem(context.getString(R.string.mobile_data_settings_title)))
                add(getMobileDataSearchItem(context))
            }
        }
    }
+2 −2
Original line number Diff line number Diff line
@@ -37,8 +37,8 @@ class SettingsSpaSearchLandingActivity : SpaSearchLandingActivity() {
            featureFactory.searchFeatureProvider.getSettingsIntelligencePkgName(this)
    }

    override fun startSpaPage(destination: String) {
        SpaDestination(destination = destination, highlightMenuKey = null)
    override fun startSpaPage(destination: String, highlightItemKey: String) {
        SpaDestination(destination = destination, highlightItemKey = highlightItemKey)
            .startFromExportedActivity(this)
    }

+3 −3
Original line number Diff line number Diff line
@@ -79,10 +79,10 @@ class SpaBridgeActivityTest {
                META_DATA_KEY_HIGHLIGHT_MENU_KEY to HIGHLIGHT_MENU_KEY,
            )

        val (destination, highlightMenuKey) = activity.getDestination()!!
        val spaDestination = activity.getDestination()!!

        assertThat(destination).isEqualTo(DESTINATION)
        assertThat(highlightMenuKey).isEqualTo(HIGHLIGHT_MENU_KEY)
        assertThat(spaDestination.destination).isEqualTo(DESTINATION)
        assertThat(spaDestination.highlightMenuKey).isEqualTo(HIGHLIGHT_MENU_KEY)
    }

    private companion object {
Loading