Avoid add preferenc again if it already in the PreferenceGroup

Bug: 177406865
Bug: 185187729
Test: make SettingsRoboTests
Test: make SettingsGoogleRoboTests
Change-Id: I69f5033c0a07d846c340b9871e69a2cdbe0bb2aa
This commit is contained in:
ykhung
2021-04-23 01:07:09 +08:00
parent 09f6086bea
commit 5c23d65901
5 changed files with 76 additions and 27 deletions

View File

@@ -71,6 +71,7 @@ public final class ConvertUtils {
private static String sZoneId;
private static SimpleDateFormat sSimpleDateFormat;
private static SimpleDateFormat sSimpleDateFormatForHour;
private ConvertUtils() {}
@@ -139,10 +140,27 @@ public final class ConvertUtils {
sZoneId = currentZoneId;
sSimpleDateFormat =
new SimpleDateFormat("MMM dd,yyyy HH:mm:ss", Locale.ENGLISH);
sSimpleDateFormatForHour = null;
}
return sSimpleDateFormat.format(new Date(timestamp));
}
/** Converts UTC timestamp to local time hour data. */
public static int utcToLocalTimeHour(long timestamp) {
final String currentZoneId = TimeZone.getDefault().getID();
if (!currentZoneId.equals(sZoneId) || sSimpleDateFormatForHour == null) {
sZoneId = currentZoneId;
sSimpleDateFormat = null;
sSimpleDateFormatForHour = new SimpleDateFormat("HH", Locale.ENGLISH);
}
try {
return Integer.parseInt(
sSimpleDateFormatForHour.format(new Date(timestamp)));
} catch (NumberFormatException e) {
return Integer.MIN_VALUE;
}
}
/** Gets indexed battery usage data for each corresponding time slot. */
public static Map<Integer, List<BatteryDiffEntry>> getIndexedUsageMap(
final Context context,