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

Commit 3ce7f371 authored by Fan Zhang's avatar Fan Zhang
Browse files

Auto set summary on preference during updateState

Change-Id: Ibc24f3f041841d9fe7d53674a672bc2bacad895b
Fixes: 73950519
Test: robotests
parent aec69501
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -37,7 +37,16 @@ public abstract class AbstractPreferenceController {
     * Updates the current status of preference (summary, switch state, etc)
     */
    public void updateState(Preference preference) {

        if (preference == null) {
            return;
        }
        final CharSequence summary = getSummary();
        if (summary == null) {
            // Default getSummary returns null. If subclass didn't override this, there is nothing
            // we need to do.
            return;
        }
        preference.setSummary(summary);
    }

    /**
+15 −1
Original line number Diff line number Diff line
@@ -82,8 +82,17 @@ public class AbstractPreferenceControllerTest {
        assertThat(mPreference.isVisible()).isFalse();
    }

    private class TestPrefController extends AbstractPreferenceController {
    @Test
    public void updateState_hasSummary_shouldSetSummary() {
        mTestPrefController.updateState(mPreference);

        assertThat(mPreference.getSummary()).isEqualTo(TestPrefController.TEST_SUMMARY);
    }

    private static class TestPrefController extends AbstractPreferenceController {
        private static final String KEY_PREF = "test_pref";
        private static final CharSequence TEST_SUMMARY = "Test";

        public boolean isAvailable;

        public TestPrefController(Context context) {
@@ -104,6 +113,11 @@ public class AbstractPreferenceControllerTest {
        public String getPreferenceKey() {
            return KEY_PREF;
        }

        @Override
        public CharSequence getSummary() {
            return TEST_SUMMARY;
        }
    }

}