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

Commit 637d34ed authored by ykhung's avatar ykhung Committed by YUKAI HUNG
Browse files

Wrap generating battery history keys into another method

Bug: 188123855
Test: make SettingsRoboTests
Change-Id: I82a48e66ec4f7b4c0d9a6756799aa8d7a3a96848
parent f6712e33
Loading
Loading
Loading
Loading
+14 −11
Original line number Diff line number Diff line
@@ -236,16 +236,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
            mBatteryHistoryLevels = null;
            return;
        }
        // Generates battery history timestamp slots.
        final List<Long> batteryHistoryKeyList =
            new ArrayList<>(batteryHistoryMap.keySet());
        Collections.sort(batteryHistoryKeyList);
        mBatteryHistoryKeys = new long[CHART_KEY_ARRAY_SIZE];
        for (int index = 0; index < CHART_KEY_ARRAY_SIZE; index++) {
            mBatteryHistoryKeys[index] = batteryHistoryKeyList.get(index);
        }

        // Generates the battery history levels for chart graph.
        mBatteryHistoryKeys = getBatteryHistoryKeys(batteryHistoryMap);
        mBatteryHistoryLevels = new int[CHART_LEVEL_ARRAY_SIZE];
        for (int index = 0; index < CHART_LEVEL_ARRAY_SIZE; index++) {
            final long timestamp = mBatteryHistoryKeys[index * 2];
@@ -273,7 +264,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll

        Log.d(TAG, String.format(
            "setBatteryHistoryMap() size=%d\nkeys=%s\nlevels=%s",
            batteryHistoryKeyList.size(),
            batteryHistoryMap.size(),
            utcToLocalTime(mBatteryHistoryKeys),
            Arrays.toString(mBatteryHistoryLevels)));
    }
@@ -599,4 +590,16 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
        }
        return true;
    }

    private static long[] getBatteryHistoryKeys(
            final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap) {
        final List<Long> batteryHistoryKeyList =
            new ArrayList<>(batteryHistoryMap.keySet());
        Collections.sort(batteryHistoryKeyList);
        final long[] batteryHistoryKeys = new long[CHART_KEY_ARRAY_SIZE];
        for (int index = 0; index < CHART_KEY_ARRAY_SIZE; index++) {
            batteryHistoryKeys[index] = batteryHistoryKeyList.get(index);
        }
        return batteryHistoryKeys;
    }
}