Prepare for export dialogs
This commit is contained in:
@@ -136,28 +136,46 @@ public class SettingsActivity extends PreferenceActivity {
|
|||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.export_identities:
|
case R.id.export_identities:
|
||||||
// TODO ask if file should be encrypted (remove .txt from filename if yes)
|
// TODO ask if file should be encrypted
|
||||||
// TODO ask for filename
|
askForExportFilename(null);
|
||||||
File exportFile = new File(Environment.getExternalStoragePublicDirectory(
|
|
||||||
Environment.DIRECTORY_DOCUMENTS
|
|
||||||
), "identities.txt");
|
|
||||||
try {
|
|
||||||
// TODO ask for password
|
|
||||||
I2PBote.getInstance().getIdentities().export(exportFile, null);
|
|
||||||
Toast.makeText(this, "Identities exported to Documents folder", Toast.LENGTH_SHORT).show();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (GeneralSecurityException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (PasswordException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void askForExportFilename(String password) {
|
||||||
|
// TODO ask for filename
|
||||||
|
String exportFilename = "identities";
|
||||||
|
checkIfExportFileExists(exportFilename, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkIfExportFileExists(String exportFilename, String password) {
|
||||||
|
File exportFile = new File(Environment.getExternalStoragePublicDirectory(
|
||||||
|
Environment.DIRECTORY_DOCUMENTS
|
||||||
|
), exportFilename + (password == null ? ".txt" : ".bote"));
|
||||||
|
if (exportFile.exists()) {
|
||||||
|
// TODO ask to rename or overwrite
|
||||||
|
//askForExportFilename(password);
|
||||||
|
exportIdentities(exportFile, password);
|
||||||
|
} else
|
||||||
|
exportIdentities(exportFile, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void exportIdentities(File exportFile, String password) {
|
||||||
|
try {
|
||||||
|
// TODO ask for password
|
||||||
|
I2PBote.getInstance().getIdentities().export(exportFile, password);
|
||||||
|
Toast.makeText(this, R.string.identities_exported, Toast.LENGTH_SHORT).show();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (GeneralSecurityException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (PasswordException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Building Headers
|
// Building Headers
|
||||||
|
|||||||
@@ -148,5 +148,6 @@
|
|||||||
<string name="delete_identity">Delete identity?</string>
|
<string name="delete_identity">Delete identity?</string>
|
||||||
<string name="identity_saved">Identity saved</string>
|
<string name="identity_saved">Identity saved</string>
|
||||||
<string name="export_identities">Export identities</string>
|
<string name="export_identities">Export identities</string>
|
||||||
|
<string name="identities_exported">Identities exported to Documents folder</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user