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

Commit f891cef5 authored by Arc Wang's avatar Arc Wang
Browse files

Fix UsageProgressBarPreference progress bug when zero total size

When zero total size, should update progress to zero.

Bug: 185869705
Test: atest UsageProgressBarPreferenceTest
Change-Id: I02dae2fbea23b56dad07941c614d9ef3500eeae4
parent 05ccc44c
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -113,7 +113,14 @@ public class UsageProgressBarPreference extends Preference {

    /** Set percentage of the progress bar. */
    public void setPercent(long usage, long total) {
        if (total == 0L || usage >  total) {
        if (usage >  total) {
            return;
        }
        if (total == 0L) {
            if (mPercent != 0) {
                mPercent = 0;
                notifyChanged();
            }
            return;
        }
        final int percent = (int) (usage / (double) total * 100);
+11 −0
Original line number Diff line number Diff line
@@ -124,6 +124,17 @@ public class UsageProgressBarPreferenceTest {
        assertThat(progressBar.getProgress()).isEqualTo((int) (31.0f / 80 * 100));
    }

    @Test
    public void setPercent_totalSizeZero_getProgressZero() {
        mUsageProgressBarPreference.setPercent(0 /* usage */, 0 /* total */);

        mUsageProgressBarPreference.onBindViewHolder(mViewHolder);

        final ProgressBar progressBar = (ProgressBar) mViewHolder
                .findViewById(android.R.id.progress);
        assertThat(progressBar.getProgress()).isEqualTo(0);
    }

    @Test
    public void setCustomContent_setNullImageView_noChild() {
        mUsageProgressBarPreference.setCustomContent(null /* imageView */);