1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Get rid of ExportListener

This commit is contained in:
cketti 2011-03-28 07:18:47 +02:00
parent 1d146278b0
commit 97f493c881
3 changed files with 8 additions and 34 deletions

View File

@ -1174,7 +1174,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
File file = Utility.createUniqueFile(dir, "settings.k9s");
mFileName = file.getAbsolutePath();
StorageExporter.exportPreferences(Accounts.this, StorageFormat.ENCRYPTED_XML_FILE,
mIncludeGlobals, mAccountUuids, mFileName, mEncryptionKey, null);
mIncludeGlobals, mAccountUuids, mFileName, mEncryptionKey);
} catch (Exception e) {
Log.w(K9.LOG_TAG, "Exception during export", e);
return false;

View File

@ -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();
}

View File

@ -12,10 +12,9 @@ import android.util.Log;
import com.fsck.k9.K9;
import com.fsck.k9.R;
import com.fsck.k9.activity.ExportListener;
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 {
IStorageExporter storageExporter = StorageFormat.createExporter(storageFormat);
if (storageExporter == null) {
@ -24,26 +23,21 @@ public class StorageExporter {
if (storageExporter.needsKey() && encryptionKey == null) {
throw new StorageImportExportException("Encryption key required, but none supplied");
} else {
finishExport(activity, storageFormat, storageExporter, includeGlobals, accountUuids, fileName, os, encryptionKey, listener);
finishExport(activity, storageFormat, storageExporter, includeGlobals, accountUuids, fileName, os, encryptionKey);
}
}
catch (Exception e) {
if (listener != null) {
listener.failure(e.getLocalizedMessage(), e);
}
//FIXME: get this right
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 {
exportPreferences(activity, storageFormat, includeGlobals, accountUuids, fileName, null, encryptionKey, listener);
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);
}
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;
if (listener != null) {
listener.started();
}
try {
// This needs to be after the password prompt. If the user cancels the password, we do not want
// to create the file needlessly
@ -65,13 +59,6 @@ public class StorageExporter {
pf.println("</k9settings>");
pf.flush();
if (listener != null) {
if (fileName != null) {
listener.success(fileName);
} else {
listener.success();
}
}
} else {
throw new StorageImportExportException("Internal error; no fileName or OutputStream", null);
}