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

Commit 2c5079c6 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Auto set summary on preference during updateState"

parents 3266b45d 3ce7f371
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;
        }
    }

}