2011-10-08 15:30:45 -04:00
|
|
|
package com.fsck.k9.preferences;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.Map;
|
2011-12-10 22:57:47 -05:00
|
|
|
import java.util.Set;
|
2011-12-10 23:16:22 -05:00
|
|
|
import java.util.TreeMap;
|
|
|
|
|
2011-10-08 15:30:45 -04:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
|
|
|
import com.fsck.k9.mail.Folder.FolderClass;
|
|
|
|
import com.fsck.k9.preferences.Settings.*;
|
|
|
|
|
|
|
|
public class FolderSettings {
|
2011-12-10 23:16:22 -05:00
|
|
|
public static final Map<String, TreeMap<Integer, SettingsDescription>> SETTINGS;
|
2011-12-10 22:57:47 -05:00
|
|
|
public static final Map<Integer, SettingsUpgrader> UPGRADERS;
|
2011-10-08 15:30:45 -04:00
|
|
|
|
|
|
|
static {
|
2011-12-10 23:16:22 -05:00
|
|
|
Map<String, TreeMap<Integer, SettingsDescription>> s =
|
|
|
|
new LinkedHashMap<String, TreeMap<Integer, SettingsDescription>>();
|
|
|
|
|
2012-04-08 18:27:39 -04:00
|
|
|
/**
|
|
|
|
* When adding new settings here, be sure to increment {@link Settings.VERSION}
|
|
|
|
* and use that for whatever you add here.
|
|
|
|
*/
|
|
|
|
|
2011-12-10 23:16:22 -05:00
|
|
|
s.put("displayMode", Settings.versions(
|
2013-02-04 05:18:49 -05:00
|
|
|
new V(1, new EnumSetting<FolderClass>(FolderClass.class, FolderClass.NO_CLASS))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
2014-08-06 05:04:07 -04:00
|
|
|
s.put("notifyMode", Settings.versions(
|
2014-09-04 17:00:29 -04:00
|
|
|
new V(34, new EnumSetting<FolderClass>(FolderClass.class, FolderClass.INHERITED))
|
2014-08-06 05:04:07 -04:00
|
|
|
));
|
2011-12-10 23:16:22 -05:00
|
|
|
s.put("syncMode", Settings.versions(
|
2013-02-04 05:18:49 -05:00
|
|
|
new V(1, new EnumSetting<FolderClass>(FolderClass.class, FolderClass.INHERITED))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("pushMode", Settings.versions(
|
2013-02-04 05:18:49 -05:00
|
|
|
new V(1, new EnumSetting<FolderClass>(FolderClass.class, FolderClass.INHERITED))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("inTopGroup", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(false))
|
|
|
|
));
|
|
|
|
s.put("integrate", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(false))
|
|
|
|
));
|
2011-10-08 15:30:45 -04:00
|
|
|
|
|
|
|
SETTINGS = Collections.unmodifiableMap(s);
|
2011-12-10 22:57:47 -05:00
|
|
|
|
|
|
|
Map<Integer, SettingsUpgrader> u = new HashMap<Integer, SettingsUpgrader>();
|
|
|
|
UPGRADERS = Collections.unmodifiableMap(u);
|
2011-10-08 15:30:45 -04:00
|
|
|
}
|
|
|
|
|
2011-12-11 00:02:31 -05:00
|
|
|
public static Map<String, Object> validate(int version, Map<String, String> importedSettings,
|
2011-10-08 15:30:45 -04:00
|
|
|
boolean useDefaultValues) {
|
2011-12-10 23:16:22 -05:00
|
|
|
return Settings.validate(version, SETTINGS, importedSettings, useDefaultValues);
|
2011-10-08 15:30:45 -04:00
|
|
|
}
|
|
|
|
|
2011-12-11 00:02:31 -05:00
|
|
|
public static Set<String> upgrade(int version, Map<String, Object> validatedSettings) {
|
2011-12-10 22:57:47 -05:00
|
|
|
return Settings.upgrade(version, UPGRADERS, SETTINGS, validatedSettings);
|
|
|
|
}
|
|
|
|
|
2011-12-11 00:02:31 -05:00
|
|
|
public static Map<String, String> convert(Map<String, Object> settings) {
|
|
|
|
return Settings.convert(settings, SETTINGS);
|
|
|
|
}
|
|
|
|
|
2011-10-08 15:30:45 -04:00
|
|
|
public static Map<String, String> getFolderSettings(SharedPreferences storage, String uuid,
|
|
|
|
String folderName) {
|
|
|
|
Map<String, String> result = new HashMap<String, String>();
|
|
|
|
String prefix = uuid + "." + folderName + ".";
|
|
|
|
for (String key : SETTINGS.keySet()) {
|
|
|
|
String value = storage.getString(prefix + key, null);
|
|
|
|
if (value != null) {
|
|
|
|
result.put(key, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|