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

Commit 99dc0d56 authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Remove duplicate icon from TwoTargetSwitchPreference

icon param is duplicated with the SwitchPreferenceModel.icon property,
remove to avoid confuse.

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


    override val icon = model.icon

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