mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-15 14:05:05 -05:00
Avoid using TreeMap methods introduced with API 9
This commit is contained in:
parent
ffa77ad288
commit
a191415860
@ -5,6 +5,7 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.SortedMap;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
@ -44,15 +45,25 @@ public class Settings {
|
|||||||
for (Map.Entry<String, TreeMap<Integer, SettingsDescription>> versionedSetting :
|
for (Map.Entry<String, TreeMap<Integer, SettingsDescription>> versionedSetting :
|
||||||
settings.entrySet()) {
|
settings.entrySet()) {
|
||||||
|
|
||||||
Entry<Integer, SettingsDescription> setting =
|
// Get the setting description with the highest version lower than or equal to the
|
||||||
versionedSetting.getValue().floorEntry(version);
|
// supplied content version.
|
||||||
|
TreeMap<Integer, SettingsDescription> versions = versionedSetting.getValue();
|
||||||
|
SortedMap<Integer, SettingsDescription> headMap = versions.headMap(version + 1);
|
||||||
|
|
||||||
if (setting == null) {
|
// Skip this setting if it was introduced after 'version'
|
||||||
|
if (headMap.size() == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer settingVersion = headMap.lastKey();
|
||||||
|
SettingsDescription desc = versions.get(settingVersion);
|
||||||
|
|
||||||
|
// Skip this setting if it is no longer used in 'version'
|
||||||
|
if (desc == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String key = versionedSetting.getKey();
|
String key = versionedSetting.getKey();
|
||||||
SettingsDescription desc = setting.getValue();
|
|
||||||
|
|
||||||
boolean useDefaultValue;
|
boolean useDefaultValue;
|
||||||
if (!importedSettings.containsKey(key)) {
|
if (!importedSettings.containsKey(key)) {
|
||||||
@ -127,7 +138,7 @@ public class Settings {
|
|||||||
// Check if it was already added to upgradedSettings by the SettingsUpgrader
|
// Check if it was already added to upgradedSettings by the SettingsUpgrader
|
||||||
if (!upgradedSettings.containsKey(settingName)) {
|
if (!upgradedSettings.containsKey(settingName)) {
|
||||||
// Insert default value to upgradedSettings
|
// Insert default value to upgradedSettings
|
||||||
SettingsDescription setting = versionedSettings.firstEntry().getValue();
|
SettingsDescription setting = versionedSettings.get(toVersion);
|
||||||
Object defaultValue = setting.getDefaultValue();
|
Object defaultValue = setting.getDefaultValue();
|
||||||
upgradedSettings.put(settingName, defaultValue);
|
upgradedSettings.put(settingName, defaultValue);
|
||||||
|
|
||||||
@ -140,8 +151,9 @@ public class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle removed settings
|
// Handle removed settings
|
||||||
Entry<Integer, SettingsDescription> lastEntry = versionedSettings.lastEntry();
|
Integer highestVersion = versionedSettings.lastKey();
|
||||||
if (lastEntry.getKey().intValue() == toVersion && lastEntry.getValue() == null) {
|
if (highestVersion.intValue() == toVersion &&
|
||||||
|
versionedSettings.get(highestVersion) == null) {
|
||||||
upgradedSettings.remove(settingName);
|
upgradedSettings.remove(settingName);
|
||||||
if (deletedSettings == null) {
|
if (deletedSettings == null) {
|
||||||
deletedSettings = new HashSet<String>();
|
deletedSettings = new HashSet<String>();
|
||||||
@ -179,8 +191,10 @@ public class Settings {
|
|||||||
String settingName = setting.getKey();
|
String settingName = setting.getKey();
|
||||||
Object internalValue = setting.getValue();
|
Object internalValue = setting.getValue();
|
||||||
|
|
||||||
SettingsDescription settingDesc =
|
TreeMap<Integer, SettingsDescription> versionedSetting =
|
||||||
settingDescriptions.get(settingName).lastEntry().getValue();
|
settingDescriptions.get(settingName);
|
||||||
|
Integer highestVersion = versionedSetting.lastKey();
|
||||||
|
SettingsDescription settingDesc = versionedSetting.get(highestVersion);
|
||||||
|
|
||||||
if (settingDesc != null) {
|
if (settingDesc != null) {
|
||||||
String stringValue = settingDesc.toString(internalValue);
|
String stringValue = settingDesc.toString(internalValue);
|
||||||
|
@ -172,7 +172,9 @@ public class SettingsExporter {
|
|||||||
|
|
||||||
String key = versionedSetting.getKey();
|
String key = versionedSetting.getKey();
|
||||||
String valueString = (String) prefs.get(key);
|
String valueString = (String) prefs.get(key);
|
||||||
SettingsDescription setting = versionedSetting.getValue().lastEntry().getValue();
|
TreeMap<Integer, SettingsDescription> versions = versionedSetting.getValue();
|
||||||
|
Integer highestVersion = versions.lastKey();
|
||||||
|
SettingsDescription setting = versions.get(highestVersion);
|
||||||
if (setting == null) {
|
if (setting == null) {
|
||||||
// Setting was removed.
|
// Setting was removed.
|
||||||
continue;
|
continue;
|
||||||
@ -322,7 +324,8 @@ public class SettingsExporter {
|
|||||||
AccountSettings.SETTINGS.get(keyPart);
|
AccountSettings.SETTINGS.get(keyPart);
|
||||||
|
|
||||||
if (versionedSetting != null) {
|
if (versionedSetting != null) {
|
||||||
SettingsDescription setting = versionedSetting.lastEntry().getValue();
|
Integer highestVersion = versionedSetting.lastKey();
|
||||||
|
SettingsDescription setting = versionedSetting.get(highestVersion);
|
||||||
|
|
||||||
if (setting != null) {
|
if (setting != null) {
|
||||||
// Only export account settings that can be found in AccountSettings.SETTINGS
|
// Only export account settings that can be found in AccountSettings.SETTINGS
|
||||||
@ -416,7 +419,8 @@ public class SettingsExporter {
|
|||||||
IdentitySettings.SETTINGS.get(identityKey);
|
IdentitySettings.SETTINGS.get(identityKey);
|
||||||
|
|
||||||
if (versionedSetting != null) {
|
if (versionedSetting != null) {
|
||||||
SettingsDescription setting = versionedSetting.lastEntry().getValue();
|
Integer highestVersion = versionedSetting.lastKey();
|
||||||
|
SettingsDescription setting = versionedSetting.get(highestVersion);
|
||||||
|
|
||||||
if (setting != null) {
|
if (setting != null) {
|
||||||
// Only write settings that have an entry in IdentitySettings.SETTINGS
|
// Only write settings that have an entry in IdentitySettings.SETTINGS
|
||||||
@ -467,7 +471,8 @@ public class SettingsExporter {
|
|||||||
FolderSettings.SETTINGS.get(folderKey);
|
FolderSettings.SETTINGS.get(folderKey);
|
||||||
|
|
||||||
if (versionedSetting != null) {
|
if (versionedSetting != null) {
|
||||||
SettingsDescription setting = versionedSetting.lastEntry().getValue();
|
Integer highestVersion = versionedSetting.lastKey();
|
||||||
|
SettingsDescription setting = versionedSetting.get(highestVersion);
|
||||||
|
|
||||||
if (setting != null) {
|
if (setting != null) {
|
||||||
// Only write settings that have an entry in FolderSettings.SETTINGS
|
// Only write settings that have an entry in FolderSettings.SETTINGS
|
||||||
|
Loading…
Reference in New Issue
Block a user