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

Commit 6b27dc75 authored by Haijie Hong's avatar Haijie Hong
Browse files

Fix MultiTogglePreference highlight issue

Add a boolean field to indicate whether we need to highlight the button in the UI

BUG: 343317785
Test: atest MultiTogglePreferenceTest
Flag: com.android.settings.flags.enable_bluetooth_device_details_polish
Change-Id: Ib5fd57b31ca26aa69ad7fe80da5af94c6139ca3a
parent c72852fa
Loading
Loading
Loading
Loading
+32 −2
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ public class MultiTogglePreference extends DeviceSettingPreference implements Pa
    private final String mTitle;
    private final ImmutableList<ToggleInfo> mToggleInfos;
    private final int mState;
    private final boolean mIsActive;
    private final boolean mIsAllowedChangingState;
    private final Bundle mExtras;

@@ -40,6 +41,7 @@ public class MultiTogglePreference extends DeviceSettingPreference implements Pa
            @NonNull String title,
            List<ToggleInfo> toggleInfos,
            int state,
            boolean isActive,
            boolean allowChangingState,
            Bundle extras) {
        super(DeviceSettingType.DEVICE_SETTING_TYPE_MULTI_TOGGLE);
@@ -47,6 +49,7 @@ public class MultiTogglePreference extends DeviceSettingPreference implements Pa
        mTitle = title;
        mToggleInfos = ImmutableList.copyOf(toggleInfos);
        mState = state;
        mIsActive = isActive;
        mIsAllowedChangingState = allowChangingState;
        mExtras = extras;
    }
@@ -67,9 +70,11 @@ public class MultiTogglePreference extends DeviceSettingPreference implements Pa
        List<ToggleInfo> toggleInfos = new ArrayList<>();
        in.readTypedList(toggleInfos, ToggleInfo.CREATOR);
        int state = in.readInt();
        boolean isActive = in.readBoolean();
        boolean allowChangingState = in.readBoolean();
        Bundle extras = in.readBundle(Bundle.class.getClassLoader());
        return new MultiTogglePreference(title, toggleInfos, state, allowChangingState, extras);
        return new MultiTogglePreference(
                title, toggleInfos, state, isActive, allowChangingState, extras);
    }

    public static final Creator<MultiTogglePreference> CREATOR =
@@ -99,6 +104,7 @@ public class MultiTogglePreference extends DeviceSettingPreference implements Pa
        dest.writeString(mTitle);
        dest.writeTypedList(mToggleInfos, flags);
        dest.writeInt(mState);
        dest.writeBoolean(mIsActive);
        dest.writeBoolean(mIsAllowedChangingState);
        dest.writeBundle(mExtras);
    }
@@ -108,6 +114,7 @@ public class MultiTogglePreference extends DeviceSettingPreference implements Pa
        private String mTitle;
        private ImmutableList.Builder<ToggleInfo> mToggleInfos = new ImmutableList.Builder<>();
        private int mState;
        private boolean mIsActive;
        private boolean mAllowChangingState;
        private Bundle mExtras = Bundle.EMPTY;

@@ -147,6 +154,19 @@ public class MultiTogglePreference extends DeviceSettingPreference implements Pa
            return this;
        }

        /**
         * Sets whether the current state is considered as an "active" state. If it's set to true,
         * the toggle will be highlighted in UI.
         *
         * @param isActive The active state.
         * @return Returns the Builder object.
         */
        @NonNull
        public Builder setIsActive(boolean isActive) {
            mIsActive = isActive;
            return this;
        }

        /**
         * Sets whether state can be changed by user.
         *
@@ -178,7 +198,7 @@ public class MultiTogglePreference extends DeviceSettingPreference implements Pa
        @NonNull
        public MultiTogglePreference build() {
            return new MultiTogglePreference(
                    mTitle, mToggleInfos.build(), mState, mAllowChangingState, mExtras);
                    mTitle, mToggleInfos.build(), mState, mIsActive, mAllowChangingState, mExtras);
        }
    }

@@ -201,6 +221,16 @@ public class MultiTogglePreference extends DeviceSettingPreference implements Pa
        return mState;
    }

    /**
     * Whether the current state is considered as an active state. If it's set to true, the toggle
     * will be highlighted in UI.
     *
     * @return Returns the active state.
     */
    public boolean isActive() {
        return mIsActive;
    }

    /**
     * Gets the toggle list in the preference.
     *
+1 −1
Original line number Diff line number Diff line
@@ -159,7 +159,7 @@ class DeviceSettingRepositoryImpl(
                    title = pref.title,
                    toggles = pref.toggleInfos.map { it.toModel() },
                    isAllowedChangingState = pref.isAllowedChangingState,
                    isActive = true,
                    isActive = pref.isActive,
                    state = DeviceSettingStateModel.MultiTogglePreferenceState(pref.state),
                    updateState = { newState ->
                        coroutineScope.launch(backgroundCoroutineContext) {
+2 −0
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ public final class MultiTogglePreferenceTest {
                        .addToggleInfo(TOGGLE_INFO_1)
                        .addToggleInfo(TOGGLE_INFO_2)
                        .setState(123)
                        .setIsActive(true)
                        .setAllowChangingState(true)
                        .setExtras(buildBundle("key1", "value1"))
                        .build();
@@ -130,6 +131,7 @@ public final class MultiTogglePreferenceTest {
        assertThat(fromParcel.getToggleInfos().stream().map(ToggleInfo::getLabel).toList())
                .containsExactly("label1", "label2");
        assertThat(fromParcel.getState()).isEqualTo(preference.getState());
        assertThat(fromParcel.isActive()).isEqualTo(preference.isActive());
        assertThat(fromParcel.isAllowedChangingState())
                .isEqualTo(preference.isAllowedChangingState());
        assertThat(fromParcel.getExtras().getString("key1"))