Merge "Show time zone used in or after 2018 only" into pi-dev

This commit is contained in:
Neil Fuller
2018-03-23 17:18:36 +00:00
committed by Android (Google) Code Review
4 changed files with 89 additions and 16 deletions

View File

@@ -27,13 +27,19 @@ import java.util.stream.Collectors;
*/
public class FilteredCountryTimeZones {
// New timezone list and the meta data of time zone, notUsedAfter, is introduced in Android P
// in 2018. Only show time zone used in or after 2018.
private static final long MIN_USE_DATE_OF_TIMEZONE = 1514764800000L; // 1/1/2018 00:00 UTC
private final CountryTimeZones mCountryTimeZones;
private final List<String> mTimeZoneIds;
public FilteredCountryTimeZones(CountryTimeZones countryTimeZones) {
mCountryTimeZones = countryTimeZones;
List<String> timeZoneIds = countryTimeZones.getTimeZoneMappings().stream()
.filter(timeZoneMapping -> timeZoneMapping.showInPicker)
.filter(timeZoneMapping ->
timeZoneMapping.showInPicker && (timeZoneMapping.notUsedAfter == null
|| timeZoneMapping.notUsedAfter >= MIN_USE_DATE_OF_TIMEZONE))
.map(timeZoneMapping -> timeZoneMapping.timeZoneId)
.collect(Collectors.toList());
mTimeZoneIds = Collections.unmodifiableList(timeZoneIds);

View File

@@ -16,6 +16,7 @@
package com.android.settings.datetime.timezone.model;
import android.support.annotation.VisibleForTesting;
import android.support.v4.util.ArraySet;
import libcore.util.CountryTimeZones;
import libcore.util.CountryZonesFinder;
@@ -27,12 +28,11 @@ import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Wrapper of CountryZonesFinder to normalize the country code and only show the regions that are
* has time zone shown in the time zone picker.
* The constructor reads the data from underlying file, and this means it should not be called
* getInstance() reads the data from underlying file, and this means it should not be called
* from the UI thread.
*/
public class TimeZoneData {
@@ -47,15 +47,11 @@ public class TimeZoneData {
if (data != null) {
return data;
}
data = new TimeZoneData();
data = new TimeZoneData(TimeZoneFinder.getInstance().getCountryZonesFinder());
sCache = new WeakReference<>(data);
return data;
}
public TimeZoneData() {
this(TimeZoneFinder.getInstance().getCountryZonesFinder());
}
@VisibleForTesting
public TimeZoneData(CountryZonesFinder countryZonesFinder) {
mCountryZonesFinder = countryZonesFinder;
@@ -70,13 +66,16 @@ public class TimeZoneData {
if (tzId == null) {
return Collections.emptySet();
}
return mCountryZonesFinder.lookupCountryTimeZonesForZoneId(tzId).stream()
.filter(countryTimeZones ->
countryTimeZones.getTimeZoneMappings().stream()
.anyMatch(mapping ->
mapping.timeZoneId.equals(tzId) && mapping.showInPicker))
.map(countryTimeZones -> normalizeRegionId(countryTimeZones.getCountryIso()))
.collect(Collectors.toSet());
List<CountryTimeZones> countryTimeZones = mCountryZonesFinder
.lookupCountryTimeZonesForZoneId(tzId);
Set<String> regionIds = new ArraySet<>();
for (CountryTimeZones countryTimeZone : countryTimeZones) {
FilteredCountryTimeZones filteredZones = new FilteredCountryTimeZones(countryTimeZone);
if (filteredZones.getTimeZoneIds().contains(tzId)) {
regionIds.add(filteredZones.getRegionId());
}
}
return regionIds;
}
public FilteredCountryTimeZones lookupCountryTimeZones(String regionId) {

View File

@@ -32,7 +32,7 @@ public class TimeZoneDataLoader extends AsyncLoader<TimeZoneData> {
@Override
public TimeZoneData loadInBackground() {
// Heavy operation due to reading the underlying file
return new TimeZoneData();
return TimeZoneData.getInstance();
}
@Override