1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-25 00:58:50 -05:00

Get rid of the STORAGE_VERSION enum in StorageVersioning

This commit is contained in:
cketti 2011-03-26 06:59:45 +01:00
parent 26258d7666
commit 18cefedf32
2 changed files with 21 additions and 49 deletions

View File

@ -12,7 +12,7 @@ import com.fsck.k9.preferences.StorageVersioning;
public class ExportHelper {
public static void exportSettings(final Activity activity, final HashSet<String> accountUuids, final ExportListener listener) {
// Once there are more versions, build a UI to select which one to use. For now, use the encrypted/encoded version:
String version = StorageVersioning.STORAGE_VERSION.VERSION1.getVersionString();
String version = StorageVersioning.ENCRYPTED_XML_FILE;
AsyncUIProcessor.getInstance(activity.getApplication()).exportSettings(activity, version, accountUuids, new ExportListener() {
@Override

View File

@ -5,74 +5,46 @@ import java.util.Map;
public class StorageVersioning {
public enum STORAGE_VERSION {
VERSION1(StorageImporterVersion1.class, StorageExporterVersion1.class, true, STORAGE_VERSION_1);
private Class <? extends IStorageImporter > importerClass;
private Class <? extends IStorageExporter > exporterClass;
private boolean needsKey;
private String versionString;
private STORAGE_VERSION(Class <? extends IStorageImporter > imclass, Class <? extends IStorageExporter > exclass, boolean nk, String vs) {
importerClass = imclass;
exporterClass = exclass;
needsKey = nk;
versionString = vs;
}
public Class <? extends IStorageImporter > getImporterClass() {
return importerClass;
}
public IStorageImporter createImporter() throws InstantiationException, IllegalAccessException {
IStorageImporter storageImporter = importerClass.newInstance();
return storageImporter;
}
public Class <? extends IStorageExporter > getExporterClass() {
return exporterClass;
}
public IStorageExporter createExporter() throws InstantiationException, IllegalAccessException {
IStorageExporter storageExporter = exporterClass.newInstance();
return storageExporter;
}
public boolean needsKey() {
return needsKey;
}
public String getVersionString() {
return versionString;
}
}
// Never, ever re-use these numbers!
private static final String STORAGE_VERSION_1 = "1";
public static final String ENCRYPTED_XML_FILE = "1";
public static Map<String, STORAGE_VERSION> versionMap = new HashMap<String, STORAGE_VERSION>();
public static Map<String, StorageVersioning> versionMap = new HashMap<String, StorageVersioning>();
static {
versionMap.put(STORAGE_VERSION.VERSION1.getVersionString(), STORAGE_VERSION.VERSION1);
versionMap.put(ENCRYPTED_XML_FILE, new StorageVersioning(StorageImporterVersion1.class, StorageExporterVersion1.class, true));
}
public static IStorageImporter createImporter(String version) throws InstantiationException, IllegalAccessException {
STORAGE_VERSION storageVersion = versionMap.get(version);
StorageVersioning storageVersion = versionMap.get(version);
if (storageVersion == null) {
return null;
}
return storageVersion.createImporter();
return storageVersion.importerClass.newInstance();
}
public static IStorageExporter createExporter(String version) throws InstantiationException, IllegalAccessException {
STORAGE_VERSION storageVersion = versionMap.get(version);
StorageVersioning storageVersion = versionMap.get(version);
if (storageVersion == null) {
return null;
}
return storageVersion.createExporter();
return storageVersion.exporterClass.newInstance();
}
public Boolean needsKey(String version) {
STORAGE_VERSION storageVersion = versionMap.get(version);
public static Boolean needsKey(String version) {
StorageVersioning storageVersion = versionMap.get(version);
if (storageVersion == null) {
return null;
}
return storageVersion.needsKey();
return storageVersion.needsKey;
}
private final Class <? extends IStorageImporter > importerClass;
private final Class <? extends IStorageExporter > exporterClass;
private final boolean needsKey;
private StorageVersioning(Class <? extends IStorageImporter > imclass, Class <? extends IStorageExporter > exclass, boolean nk) {
importerClass = imclass;
exporterClass = exclass;
needsKey = nk;
}
}