mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 13:12:25 -05:00
Get rid of ExportListener
This commit is contained in:
parent
1d146278b0
commit
97f493c881
@ -1174,7 +1174,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
|||||||
File file = Utility.createUniqueFile(dir, "settings.k9s");
|
File file = Utility.createUniqueFile(dir, "settings.k9s");
|
||||||
mFileName = file.getAbsolutePath();
|
mFileName = file.getAbsolutePath();
|
||||||
StorageExporter.exportPreferences(Accounts.this, StorageFormat.ENCRYPTED_XML_FILE,
|
StorageExporter.exportPreferences(Accounts.this, StorageFormat.ENCRYPTED_XML_FILE,
|
||||||
mIncludeGlobals, mAccountUuids, mFileName, mEncryptionKey, null);
|
mIncludeGlobals, mAccountUuids, mFileName, mEncryptionKey);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.w(K9.LOG_TAG, "Exception during export", e);
|
Log.w(K9.LOG_TAG, "Exception during export", e);
|
||||||
return false;
|
return false;
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
package com.fsck.k9.activity;
|
|
||||||
|
|
||||||
public interface ExportListener {
|
|
||||||
public void success(String fileName);
|
|
||||||
public void success();
|
|
||||||
|
|
||||||
public void failure(String message, Exception e);
|
|
||||||
|
|
||||||
public void canceled();
|
|
||||||
|
|
||||||
public void started();
|
|
||||||
|
|
||||||
}
|
|
@ -12,10 +12,9 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.fsck.k9.K9;
|
import com.fsck.k9.K9;
|
||||||
import com.fsck.k9.R;
|
import com.fsck.k9.R;
|
||||||
import com.fsck.k9.activity.ExportListener;
|
|
||||||
|
|
||||||
public class StorageExporter {
|
public class StorageExporter {
|
||||||
private static void exportPreferences(Activity activity, String storageFormat, boolean includeGlobals, Set<String> accountUuids, String fileName, OutputStream os, String encryptionKey, final ExportListener listener) {
|
private static void exportPreferences(Activity activity, String storageFormat, boolean includeGlobals, Set<String> accountUuids, String fileName, OutputStream os, String encryptionKey) throws StorageImportExportException {
|
||||||
try {
|
try {
|
||||||
IStorageExporter storageExporter = StorageFormat.createExporter(storageFormat);
|
IStorageExporter storageExporter = StorageFormat.createExporter(storageFormat);
|
||||||
if (storageExporter == null) {
|
if (storageExporter == null) {
|
||||||
@ -24,26 +23,21 @@ public class StorageExporter {
|
|||||||
if (storageExporter.needsKey() && encryptionKey == null) {
|
if (storageExporter.needsKey() && encryptionKey == null) {
|
||||||
throw new StorageImportExportException("Encryption key required, but none supplied");
|
throw new StorageImportExportException("Encryption key required, but none supplied");
|
||||||
} else {
|
} else {
|
||||||
finishExport(activity, storageFormat, storageExporter, includeGlobals, accountUuids, fileName, os, encryptionKey, listener);
|
finishExport(activity, storageFormat, storageExporter, includeGlobals, accountUuids, fileName, os, encryptionKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
if (listener != null) {
|
//FIXME: get this right
|
||||||
listener.failure(e.getLocalizedMessage(), e);
|
throw new StorageImportExportException();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void exportPreferences(Activity activity, String storageFormat, boolean includeGlobals, Set<String> accountUuids, String fileName, String encryptionKey, final ExportListener listener) throws StorageImportExportException {
|
public static void exportPreferences(Activity activity, String storageFormat, boolean includeGlobals, Set<String> accountUuids, String fileName, String encryptionKey) throws StorageImportExportException {
|
||||||
exportPreferences(activity, storageFormat, includeGlobals, accountUuids, fileName, null, encryptionKey, listener);
|
exportPreferences(activity, storageFormat, includeGlobals, accountUuids, fileName, null, encryptionKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void finishExport(Activity activity, String storageFormat, IStorageExporter storageExporter, boolean includeGlobals, Set<String> accountUuids, String fileName, OutputStream os, String encryptionKey, ExportListener listener) throws StorageImportExportException {
|
private static void finishExport(Activity activity, String storageFormat, IStorageExporter storageExporter, boolean includeGlobals, Set<String> accountUuids, String fileName, OutputStream os, String encryptionKey) throws StorageImportExportException {
|
||||||
boolean needToClose = false;
|
boolean needToClose = false;
|
||||||
if (listener != null) {
|
|
||||||
listener.started();
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
// This needs to be after the password prompt. If the user cancels the password, we do not want
|
// This needs to be after the password prompt. If the user cancels the password, we do not want
|
||||||
// to create the file needlessly
|
// to create the file needlessly
|
||||||
@ -65,13 +59,6 @@ public class StorageExporter {
|
|||||||
|
|
||||||
pf.println("</k9settings>");
|
pf.println("</k9settings>");
|
||||||
pf.flush();
|
pf.flush();
|
||||||
if (listener != null) {
|
|
||||||
if (fileName != null) {
|
|
||||||
listener.success(fileName);
|
|
||||||
} else {
|
|
||||||
listener.success();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw new StorageImportExportException("Internal error; no fileName or OutputStream", null);
|
throw new StorageImportExportException("Internal error; no fileName or OutputStream", null);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user