mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 19:52:17 -05:00
Moved password input dialog for export to Accounts activity.
This commit is contained in:
parent
a559a35249
commit
1d146278b0
@ -1120,28 +1120,38 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
|||||||
public void onExport(final boolean includeGlobals, final Account account) {
|
public void onExport(final boolean includeGlobals, final Account account) {
|
||||||
|
|
||||||
// TODO, prompt to allow a user to choose which accounts to export
|
// TODO, prompt to allow a user to choose which accounts to export
|
||||||
HashSet<String> accountUuids;
|
final Set<String> accountUuids = new HashSet<String>();
|
||||||
accountUuids = new HashSet<String>();
|
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
accountUuids.add(account.getUuid());
|
accountUuids.add(account.getUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Once there are more file formats, build a UI to select which one to use. For now, use the encrypted/encoded format:
|
// Prompt the user for a password
|
||||||
String storageFormat = StorageFormat.ENCRYPTED_XML_FILE;
|
new PasswordEntryDialog(this,
|
||||||
new ExportAsyncTask(storageFormat, includeGlobals, accountUuids).execute();
|
getString(R.string.settings_export_encryption_password_prompt),
|
||||||
|
new PasswordEntryDialog.PasswordEntryListener() {
|
||||||
|
public void passwordChosen(final String chosenPassword) {
|
||||||
|
// Got the password. Now run export task in the background.
|
||||||
|
new ExportAsyncTask(includeGlobals, accountUuids, chosenPassword).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancel() {
|
||||||
|
// User cancelled the export. Nothing more to do.
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ExportAsyncTask extends AsyncTask<Void, Void, Boolean> {
|
private class ExportAsyncTask extends AsyncTask<Void, Void, Boolean> {
|
||||||
private boolean mIncludeGlobals;
|
private boolean mIncludeGlobals;
|
||||||
private Set<String> mAccountUuids;
|
private Set<String> mAccountUuids;
|
||||||
private String mStorageFormat;
|
private String mEncryptionKey;
|
||||||
private String mFileName;
|
private String mFileName;
|
||||||
|
|
||||||
private ExportAsyncTask(String storageFormat, boolean includeGlobals,
|
private ExportAsyncTask(boolean includeGlobals, Set<String> accountUuids,
|
||||||
Set<String> accountUuids) {
|
String encryptionKey) {
|
||||||
mStorageFormat = storageFormat;
|
|
||||||
mIncludeGlobals = includeGlobals;
|
mIncludeGlobals = includeGlobals;
|
||||||
mAccountUuids = accountUuids;
|
mAccountUuids = accountUuids;
|
||||||
|
mEncryptionKey = encryptionKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1163,8 +1173,8 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
|||||||
dir.mkdirs();
|
dir.mkdirs();
|
||||||
File file = Utility.createUniqueFile(dir, "settings.k9s");
|
File file = Utility.createUniqueFile(dir, "settings.k9s");
|
||||||
mFileName = file.getAbsolutePath();
|
mFileName = file.getAbsolutePath();
|
||||||
StorageExporter.exportPreferences(Accounts.this, mStorageFormat, mIncludeGlobals,
|
StorageExporter.exportPreferences(Accounts.this, StorageFormat.ENCRYPTED_XML_FILE,
|
||||||
mAccountUuids, mFileName, null, null);
|
mIncludeGlobals, mAccountUuids, mFileName, mEncryptionKey, null);
|
||||||
} 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;
|
||||||
@ -1185,5 +1195,4 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,7 @@ 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.AsyncUIProcessor;
|
|
||||||
import com.fsck.k9.activity.ExportListener;
|
import com.fsck.k9.activity.ExportListener;
|
||||||
import com.fsck.k9.activity.PasswordEntryDialog;
|
|
||||||
|
|
||||||
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, final ExportListener listener) {
|
||||||
@ -24,7 +22,7 @@ public class StorageExporter {
|
|||||||
throw new StorageImportExportException(activity.getString(R.string.settings_unknown_version, storageFormat), 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, storageFormat, storageExporter, includeGlobals, accountUuids, fileName, os, listener);
|
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, listener);
|
||||||
}
|
}
|
||||||
@ -41,48 +39,6 @@ public class StorageExporter {
|
|||||||
exportPreferences(activity, storageFormat, includeGlobals, accountUuids, fileName, null, encryptionKey, listener);
|
exportPreferences(activity, storageFormat, includeGlobals, accountUuids, fileName, null, encryptionKey, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void exportPrefererences(Activity activity, String storageFormat, boolean includeGlobals, Set<String> accountUuids, OutputStream os, String encryptionKey, final ExportListener listener) throws StorageImportExportException {
|
|
||||||
exportPreferences(activity, storageFormat, includeGlobals, accountUuids, null, os, encryptionKey, listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void gatherPassword(final Activity activity, final String storageFormat, final IStorageExporter storageExporter, final boolean includeGlobals, final Set<String> accountUuids, final String fileName, final OutputStream os, final ExportListener listener) {
|
|
||||||
activity.runOnUiThread(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
PasswordEntryDialog dialog = new PasswordEntryDialog(activity, activity.getString(R.string.settings_export_encryption_password_prompt),
|
|
||||||
new PasswordEntryDialog.PasswordEntryListener() {
|
|
||||||
public void passwordChosen(final String chosenPassword) {
|
|
||||||
|
|
||||||
AsyncUIProcessor.getInstance(activity.getApplication()).execute(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
finishExport(activity, storageFormat, storageExporter, includeGlobals, accountUuids, fileName, os, chosenPassword, listener);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.w(K9.LOG_TAG, "Exception while finishing export", e);
|
|
||||||
if (listener != null) {
|
|
||||||
listener.failure(e.getLocalizedMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cancel() {
|
|
||||||
if (listener != null) {
|
|
||||||
listener.canceled();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
dialog.show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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, ExportListener listener) throws StorageImportExportException {
|
||||||
boolean needToClose = false;
|
boolean needToClose = false;
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user