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

Commit c6d11de8 authored by Zaiyue Xue's avatar Zaiyue Xue Committed by Automerger Merge Worker
Browse files

Merge "String change to highlight calculation stopped at last even hour" into...

Merge "String change to highlight calculation stopped at last even hour" into tm-qpr-dev am: 6aba1663

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/22635696



Change-Id: I4cb41677f4c7bd55cd92440e6a0e59a8d3a878eb
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents a6f06629 6aba1663
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -7047,6 +7047,10 @@
    <string name="battery_system_usage_for">System usage for <xliff:g id="slot">%s</xliff:g></string>
    <!-- [CHAR_LIMIT=NONE] Battery app usage section header -->
    <string name="battery_app_usage_for">App usage for <xliff:g id="slot">%s</xliff:g></string>
    <!-- [CHAR_LIMIT=NONE] Battery system usage section header since last full charge to slot_timestamp. Please use similar text with tc/3248552137819897140 -->
    <string name="battery_system_usage_since_last_full_charge_to">System usage since last full charge to <xliff:g id="slot_timestamp" example="Friday 10 am">%s</xliff:g></string>
    <!-- [CHAR_LIMIT=NONE] Battery app usage section header since last full charge to slot_timestamp. Please use similar text with tc/7309909074935858949 -->
    <string name="battery_app_usage_since_last_full_charge_to">App usage since last full charge to <xliff:g id="slot_timestamp" example="Friday 10 am">%s</xliff:g></string>
    <!-- [CHAR_LIMIT=NONE] Battery usage item for total usage time less than a minute -->
    <string name="battery_usage_total_less_than_one_minute">Total: less than a min</string>
    <!-- [CHAR_LIMIT=NONE] Battery usage item for total background time less than a minute -->
+22 −6
Original line number Diff line number Diff line
@@ -593,8 +593,19 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll

    private String getSlotInformation(boolean isApp, String slotInformation) {
        // TODO: Updates the right slot information from daily and hourly chart selection.
        // Null means we show all information without a specific time slot.
        if (slotInformation == null) {
        if (mDailyViewModel != null && mHourlyViewModels != null && isAllSelected()) {
            int lastDailyChartIndex = mDailyViewModel.size() - 2;
            int lastHourlyChartIndex = mHourlyViewModels.get(lastDailyChartIndex).size() - 1;
            String lastSlotInformation = getSlotInformation(
                    lastDailyChartIndex, lastHourlyChartIndex, /*isDayTextOnly=*/ false);
            return isApp
                    ? mPrefContext.getString(
                            R.string.battery_app_usage_since_last_full_charge_to,
                            lastSlotInformation)
                    : mPrefContext.getString(
                            R.string.battery_system_usage_since_last_full_charge_to,
                            lastSlotInformation);
        } else if (slotInformation == null) {
            return isApp
                    ? mPrefContext.getString(R.string.battery_app_usage)
                    : mPrefContext.getString(R.string.battery_system_usage);
@@ -614,14 +625,19 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
        if (isAllSelected()) {
            return null;
        }
        return getSlotInformation(mDailyChartIndex, mHourlyChartIndex,
                /*isDayTextOnly=*/ mHourlyChartIndex == BatteryChartViewModel.SELECTED_INDEX_ALL);
    }

        final String selectedDayText = mDailyViewModel.getFullText(mDailyChartIndex);
        if (mHourlyChartIndex == BatteryChartViewModel.SELECTED_INDEX_ALL) {
    private String getSlotInformation(
            int dailyChartIndex, int hourlyChartIndex, boolean isDayTextOnly) {
        final String selectedDayText = mDailyViewModel.getFullText(dailyChartIndex);
        if (isDayTextOnly) {
            return selectedDayText;
        }

        final String selectedHourText = mHourlyViewModels.get(mDailyChartIndex).getFullText(
                mHourlyChartIndex);
        final String selectedHourText = mHourlyViewModels.get(dailyChartIndex).getFullText(
                hourlyChartIndex);
        if (isBatteryLevelDataInOneDay()) {
            return selectedHourText;
        }
+34 −3
Original line number Diff line number Diff line
@@ -571,12 +571,43 @@ public final class BatteryChartPreferenceControllerTest {
    }

    @Test
    public void refreshCategoryTitle_setLastFullChargeIntoBothTitleTextView() {
    public void refreshCategoryTitle_singleDayData_setLastFullChargeIntoBothTitleTextView() {
        mBatteryChartPreferenceController = createController();
        mBatteryChartPreferenceController.mAppListPrefGroup =
                spy(new PreferenceCategory(mContext));
        mBatteryChartPreferenceController.mExpandDividerPreference =
                spy(new ExpandDividerPreference(mContext));
        mBatteryChartPreferenceController.setBatteryHistoryMap(createBatteryHistoryMap(6));
        // Simulates select all condition.
        mBatteryChartPreferenceController.mDailyChartIndex =
                BatteryChartViewModel.SELECTED_INDEX_ALL;
        mBatteryChartPreferenceController.mHourlyChartIndex =
                BatteryChartViewModel.SELECTED_INDEX_ALL;

        mBatteryChartPreferenceController.refreshCategoryTitle();

        ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
        // Verifies the title in the preference group.
        verify(mBatteryChartPreferenceController.mAppListPrefGroup)
                .setTitle(captor.capture());
        assertThat(captor.getValue())
                .isEqualTo("App usage since last full charge to 12 PM");
        // Verifies the title in the expandable divider.
        captor = ArgumentCaptor.forClass(String.class);
        verify(mBatteryChartPreferenceController.mExpandDividerPreference)
                .setTitle(captor.capture());
        assertThat(captor.getValue())
                .isEqualTo("System usage since last full charge to 12 PM");
    }

    @Test
    public void refreshCategoryTitle_multiDaysData_setLastFullChargeIntoBothTitleTextView() {
        mBatteryChartPreferenceController = createController();
        mBatteryChartPreferenceController.mAppListPrefGroup =
                spy(new PreferenceCategory(mContext));
        mBatteryChartPreferenceController.mExpandDividerPreference =
                spy(new ExpandDividerPreference(mContext));
        mBatteryChartPreferenceController.setBatteryHistoryMap(createBatteryHistoryMap(60));
        // Simulates select all condition.
        mBatteryChartPreferenceController.mDailyChartIndex =
                BatteryChartViewModel.SELECTED_INDEX_ALL;
@@ -590,13 +621,13 @@ public final class BatteryChartPreferenceControllerTest {
        verify(mBatteryChartPreferenceController.mAppListPrefGroup)
                .setTitle(captor.capture());
        assertThat(captor.getValue())
                .isEqualTo("App usage since last full charge");
                .isEqualTo("App usage since last full charge to Monday 6 PM");
        // Verifies the title in the expandable divider.
        captor = ArgumentCaptor.forClass(String.class);
        verify(mBatteryChartPreferenceController.mExpandDividerPreference)
                .setTitle(captor.capture());
        assertThat(captor.getValue())
                .isEqualTo("System usage since last full charge");
                .isEqualTo("System usage since last full charge to Monday 6 PM");
    }

    @Test