Show time zone used in or after 2018 only

- Year 2018 is picked as the new time zone data
for picker is introduced in 2018. I can be adjusted
in the future to show more merged time zones.
- Add test to ensure each region has at least
one time zone.
- Fix a issue not using a singleton of TimeZoneData
  in commit 6c33caad4b

Bug: 72142943
Test: atest SettingsUnitTests:TimeZoneDataTest
Change-Id: I5eba7fbd59a2d3fd2e8062c9615946dc4bbb6314
This commit is contained in:
Victor Chang
2018-03-15 21:17:31 +00:00
parent 9cc92cd90e
commit 490e46e01b
4 changed files with 89 additions and 16 deletions

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) {