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

Commit 413d7716 authored by Chaohui Wang's avatar Chaohui Wang Committed by Android (Google) Code Review
Browse files

Merge "Remove duplicate icon from TwoTargetSwitchPreference" into main

parents 71fc2139 99dc0d56
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import com.android.settingslib.spa.widget.ui.SettingsSwitch
@Composable
fun TwoTargetSwitchPreference(
    model: SwitchPreferenceModel,
    icon: @Composable (() -> Unit)? = null,
    primaryEnabled: () -> Boolean = { true },
    primaryOnClick: (() -> Unit)?,
) {
@@ -33,7 +32,7 @@ fun TwoTargetSwitchPreference(
            summary = model.summary,
            primaryEnabled = primaryEnabled,
            primaryOnClick = primaryOnClick,
            icon = icon,
            icon = model.icon,
        ) {
            SettingsSwitch(
                checked = model.checked(),
+3 −1
Original line number Diff line number Diff line
@@ -33,11 +33,13 @@ fun <T : AppRecord> AppListItemModel<T>.AppListTwoTargetSwitchItem(
        model = object : SwitchPreferenceModel {
            override val title = label
            override val summary = this@AppListTwoTargetSwitchItem.summary
            override val icon = @Composable {
                AppIcon(record.app, SettingsDimension.appIconItemSize)
            }
            override val checked = checked
            override val changeable = changeable
            override val onCheckedChange = onCheckedChange
        },
        icon = { AppIcon(record.app, SettingsDimension.appIconItemSize) },
        primaryOnClick = onClick,
    )
}
+2 −0
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ internal class RestrictedSwitchPreferenceModel(
        checked = model.checked,
    )

    override val icon = model.icon

    override val checked = when (restrictedMode) {
        null -> ({ null })
        is NoRestricted -> model.checked
+1 −5
Original line number Diff line number Diff line
@@ -29,14 +29,12 @@ import com.android.settingslib.spaprivileged.template.preference.RestrictedSwitc
@Composable
fun RestrictedTwoTargetSwitchPreference(
    model: SwitchPreferenceModel,
    icon: @Composable (() -> Unit)? = null,
    restrictions: Restrictions,
    primaryEnabled: () -> Boolean = { true },
    primaryOnClick: (() -> Unit)?,
) {
    RestrictedTwoTargetSwitchPreference(
        model = model,
        icon = icon,
        primaryEnabled = primaryEnabled,
        primaryOnClick = primaryOnClick,
        restrictions = restrictions,
@@ -48,21 +46,19 @@ fun RestrictedTwoTargetSwitchPreference(
@Composable
internal fun RestrictedTwoTargetSwitchPreference(
    model: SwitchPreferenceModel,
    icon: @Composable (() -> Unit)? = null,
    primaryEnabled: () -> Boolean = { true },
    primaryOnClick: (() -> Unit)?,
    restrictions: Restrictions,
    restrictionsProviderFactory: RestrictionsProviderFactory,
) {
    if (restrictions.isEmpty()) {
        TwoTargetSwitchPreference(model, icon, primaryEnabled, primaryOnClick)
        TwoTargetSwitchPreference(model, primaryEnabled, primaryOnClick)
        return
    }
    val restrictedMode = restrictionsProviderFactory.rememberRestrictedMode(restrictions).value
    RestrictedSwitchWrapper(model, restrictedMode) { restrictedModel ->
        TwoTargetSwitchPreference(
            model = restrictedModel,
            icon = icon,
            primaryEnabled = restrictedMode.restrictEnabled(primaryEnabled),
            primaryOnClick = restrictedMode.restrictOnClick(primaryOnClick),
        )