mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-25 00:58:50 -05:00
First step at replacing the term "version" with "storageFormat"
This commit is contained in:
parent
4bdc20c127
commit
087feb478b
@ -41,7 +41,7 @@ public class AsyncUIProcessor {
|
|||||||
public void execute(Runnable runnable) {
|
public void execute(Runnable runnable) {
|
||||||
threadPool.execute(runnable);
|
threadPool.execute(runnable);
|
||||||
}
|
}
|
||||||
public void exportSettings(final Activity activity, final String version, final HashSet<String> accountUuids, final ExportListener listener) {
|
public void exportSettings(final Activity activity, final String storageFormat, final HashSet<String> accountUuids, final ExportListener listener) {
|
||||||
threadPool.execute(new Runnable() {
|
threadPool.execute(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -54,7 +54,7 @@ public class AsyncUIProcessor {
|
|||||||
dir.mkdirs();
|
dir.mkdirs();
|
||||||
File file = Utility.createUniqueFile(dir, "settings.k9s");
|
File file = Utility.createUniqueFile(dir, "settings.k9s");
|
||||||
String fileName = file.getAbsolutePath();
|
String fileName = file.getAbsolutePath();
|
||||||
StorageExporter.exportPreferences(activity, version, accountUuids, fileName, null, listener);
|
StorageExporter.exportPreferences(activity, storageFormat, accountUuids, fileName, null, listener);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.w(K9.LOG_TAG, "Exception during export", e);
|
Log.w(K9.LOG_TAG, "Exception during export", e);
|
||||||
listener.failure(e.getLocalizedMessage(), e);
|
listener.failure(e.getLocalizedMessage(), e);
|
||||||
|
@ -11,9 +11,9 @@ import com.fsck.k9.preferences.StorageFormat;
|
|||||||
|
|
||||||
public class ExportHelper {
|
public class ExportHelper {
|
||||||
public static void exportSettings(final Activity activity, final HashSet<String> accountUuids, final ExportListener listener) {
|
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:
|
// Once there are more file formats, build a UI to select which one to use. For now, use the encrypted/encoded format:
|
||||||
String version = StorageFormat.ENCRYPTED_XML_FILE;
|
String storageFormat = StorageFormat.ENCRYPTED_XML_FILE;
|
||||||
AsyncUIProcessor.getInstance(activity.getApplication()).exportSettings(activity, version, accountUuids, new ExportListener() {
|
AsyncUIProcessor.getInstance(activity.getApplication()).exportSettings(activity, storageFormat, accountUuids, new ExportListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void canceled() {
|
public void canceled() {
|
||||||
|
@ -15,11 +15,11 @@ import com.fsck.k9.activity.ExportListener;
|
|||||||
import com.fsck.k9.activity.PasswordEntryDialog;
|
import com.fsck.k9.activity.PasswordEntryDialog;
|
||||||
|
|
||||||
public class StorageExporter {
|
public class StorageExporter {
|
||||||
private static void exportPreferences(Activity activity, String version, HashSet<String> accountUuids, String fileName, OutputStream os, String encryptionKey, final ExportListener listener) {
|
private static void exportPreferences(Activity activity, String storageFormat, HashSet<String> accountUuids, String fileName, OutputStream os, String encryptionKey, final ExportListener listener) {
|
||||||
try {
|
try {
|
||||||
IStorageExporter storageExporter = StorageFormat.createExporter(version);
|
IStorageExporter storageExporter = StorageFormat.createExporter(storageFormat);
|
||||||
if (storageExporter == null) {
|
if (storageExporter == null) {
|
||||||
throw new StorageImportExportException(activity.getString(R.string.settings_unknown_version, version), null);
|
throw new StorageImportExportException(activity.getString(R.string.settings_unknown_version, storageFormat), null);
|
||||||
}
|
}
|
||||||
if (storageExporter.needsKey() && encryptionKey == null) {
|
if (storageExporter.needsKey() && encryptionKey == null) {
|
||||||
gatherPassword(activity, storageExporter, accountUuids, fileName, os, listener);
|
gatherPassword(activity, storageExporter, accountUuids, fileName, os, listener);
|
||||||
@ -35,12 +35,12 @@ public class StorageExporter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void exportPreferences(Activity activity, String version, HashSet<String> accountUuids, String fileName, String encryptionKey, final ExportListener listener) throws StorageImportExportException {
|
public static void exportPreferences(Activity activity, String storageFormat, HashSet<String> accountUuids, String fileName, String encryptionKey, final ExportListener listener) throws StorageImportExportException {
|
||||||
exportPreferences(activity, version, accountUuids, fileName, null, encryptionKey, listener);
|
exportPreferences(activity, storageFormat, accountUuids, fileName, null, encryptionKey, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void exportPrefererences(Activity activity, String version, HashSet<String> accountUuids, OutputStream os, String encryptionKey, final ExportListener listener) throws StorageImportExportException {
|
public static void exportPrefererences(Activity activity, String storageFormat, HashSet<String> accountUuids, OutputStream os, String encryptionKey, final ExportListener listener) throws StorageImportExportException {
|
||||||
exportPreferences(activity, version, accountUuids, null, os, encryptionKey, listener);
|
exportPreferences(activity, storageFormat, accountUuids, null, os, encryptionKey, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void gatherPassword(final Activity activity, final IStorageExporter storageExporter, final HashSet<String> accountUuids, final String fileName, final OutputStream os, final ExportListener listener) {
|
private static void gatherPassword(final Activity activity, final IStorageExporter storageExporter, final HashSet<String> accountUuids, final String fileName, final OutputStream os, final ExportListener listener) {
|
||||||
|
@ -14,7 +14,7 @@ import com.fsck.k9.Account;
|
|||||||
import com.fsck.k9.K9;
|
import com.fsck.k9.K9;
|
||||||
import com.fsck.k9.Preferences;
|
import com.fsck.k9.Preferences;
|
||||||
|
|
||||||
public class StorageExporterVersion1 implements IStorageExporter {
|
public class StorageExporterEncryptedXml implements IStorageExporter {
|
||||||
public void exportPreferences(Context context, HashSet<String> accountUuids, OutputStream os, String encryptionKey) throws StorageImportExportException {
|
public void exportPreferences(Context context, HashSet<String> accountUuids, OutputStream os, String encryptionKey) throws StorageImportExportException {
|
||||||
try {
|
try {
|
||||||
Log.i(K9.LOG_TAG, "Exporting preferences");
|
Log.i(K9.LOG_TAG, "Exporting preferences");
|
@ -8,29 +8,29 @@ public class StorageFormat {
|
|||||||
// Never, ever re-use these numbers!
|
// Never, ever re-use these numbers!
|
||||||
public static final String ENCRYPTED_XML_FILE = "1";
|
public static final String ENCRYPTED_XML_FILE = "1";
|
||||||
|
|
||||||
public static Map<String, StorageFormat> versionMap = new HashMap<String, StorageFormat>();
|
public static Map<String, StorageFormat> storageFormatMap = new HashMap<String, StorageFormat>();
|
||||||
static {
|
static {
|
||||||
versionMap.put(ENCRYPTED_XML_FILE, new StorageFormat(StorageImporterVersion1.class, StorageExporterVersion1.class, true));
|
storageFormatMap.put(ENCRYPTED_XML_FILE, new StorageFormat(StorageImporterEncryptedXml.class, StorageExporterEncryptedXml.class, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IStorageImporter createImporter(String version) throws InstantiationException, IllegalAccessException {
|
public static IStorageImporter createImporter(String storageFormat) throws InstantiationException, IllegalAccessException {
|
||||||
StorageFormat storageVersion = versionMap.get(version);
|
StorageFormat storageVersion = storageFormatMap.get(storageFormat);
|
||||||
if (storageVersion == null) {
|
if (storageVersion == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return storageVersion.importerClass.newInstance();
|
return storageVersion.importerClass.newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IStorageExporter createExporter(String version) throws InstantiationException, IllegalAccessException {
|
public static IStorageExporter createExporter(String storageFormat) throws InstantiationException, IllegalAccessException {
|
||||||
StorageFormat storageVersion = versionMap.get(version);
|
StorageFormat storageVersion = storageFormatMap.get(storageFormat);
|
||||||
if (storageVersion == null) {
|
if (storageVersion == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return storageVersion.exporterClass.newInstance();
|
return storageVersion.exporterClass.newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Boolean needsKey(String version) {
|
public static Boolean needsKey(String storageFormat) {
|
||||||
StorageFormat storageVersion = versionMap.get(version);
|
StorageFormat storageVersion = storageFormatMap.get(storageFormat);
|
||||||
if (storageVersion == null) {
|
if (storageVersion == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -39,12 +39,12 @@ public class StorageImporter {
|
|||||||
xr.parse(new InputSource(is));
|
xr.parse(new InputSource(is));
|
||||||
|
|
||||||
ImportElement dataset = handler.getRootElement();
|
ImportElement dataset = handler.getRootElement();
|
||||||
String version = dataset.attributes.get("version");
|
String storageFormat = dataset.attributes.get("version");
|
||||||
Log.i(K9.LOG_TAG, "Got settings file version " + version);
|
Log.i(K9.LOG_TAG, "Got settings file version " + storageFormat);
|
||||||
|
|
||||||
IStorageImporter storageImporter = StorageFormat.createImporter(version);
|
IStorageImporter storageImporter = StorageFormat.createImporter(storageFormat);
|
||||||
if (storageImporter == null) {
|
if (storageImporter == null) {
|
||||||
throw new StorageImportExportException(activity.getString(R.string.settings_unknown_version, version));
|
throw new StorageImportExportException(activity.getString(R.string.settings_unknown_version, storageFormat));
|
||||||
}
|
}
|
||||||
if (storageImporter.needsKey() && providedEncryptionKey == null) {
|
if (storageImporter.needsKey() && providedEncryptionKey == null) {
|
||||||
gatherPassword(activity, storageImporter, dataset, listener);
|
gatherPassword(activity, storageImporter, dataset, listener);
|
||||||
|
@ -16,7 +16,7 @@ import com.fsck.k9.K9;
|
|||||||
import com.fsck.k9.Preferences;
|
import com.fsck.k9.Preferences;
|
||||||
import com.fsck.k9.preferences.StorageImporter.ImportElement;
|
import com.fsck.k9.preferences.StorageImporter.ImportElement;
|
||||||
|
|
||||||
public class StorageImporterVersion1 implements IStorageImporter {
|
public class StorageImporterEncryptedXml implements IStorageImporter {
|
||||||
public int importPreferences(Preferences preferences, SharedPreferences.Editor editor, ImportElement dataset, String encryptionKey) throws StorageImportExportException {
|
public int importPreferences(Preferences preferences, SharedPreferences.Editor editor, ImportElement dataset, String encryptionKey) throws StorageImportExportException {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user