Rename Export/Import to Backup/Restore

This commit is contained in:
Jakob Nixdorf 2017-07-26 14:04:28 +02:00
parent 2063510e7a
commit 85ee5db28c
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC
3 changed files with 41 additions and 41 deletions

View file

@ -100,17 +100,17 @@ public class BackupActivity extends AppCompatActivity {
settings = PreferenceManager.getDefaultSharedPreferences(this); settings = PreferenceManager.getDefaultSharedPreferences(this);
LinearLayout exportPlain = (LinearLayout) v.findViewById(R.id.button_export_plain); LinearLayout backupPlain = (LinearLayout) v.findViewById(R.id.button_backup_plain);
LinearLayout importPlain = (LinearLayout) v.findViewById(R.id.button_import_plain); LinearLayout restorePlain = (LinearLayout) v.findViewById(R.id.button_restore_plain);
exportPlain.setOnClickListener(new View.OnClickListener() { backupPlain.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
exportJSONWithWarning(); backupPlainWithWarning();
} }
}); });
importPlain.setOnClickListener(new View.OnClickListener() { restorePlain.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
openFileWithPermissions(INTENT_OPEN_DOCUMENT_PLAIN, PERMISSIONS_REQUEST_READ_IMPORT_PLAIN); openFileWithPermissions(INTENT_OPEN_DOCUMENT_PLAIN, PERMISSIONS_REQUEST_READ_IMPORT_PLAIN);
@ -121,29 +121,29 @@ public class BackupActivity extends AppCompatActivity {
pgpKeyId = settings.getLong(getString(R.string.settings_key_openpgp_keyid), 0); pgpKeyId = settings.getLong(getString(R.string.settings_key_openpgp_keyid), 0);
TextView setupPGP = (TextView) v.findViewById(R.id.msg_openpgp_setup); TextView setupPGP = (TextView) v.findViewById(R.id.msg_openpgp_setup);
LinearLayout exportPGP = (LinearLayout) v.findViewById(R.id.button_export_openpgp); LinearLayout backupPGP = (LinearLayout) v.findViewById(R.id.button_backup_openpgp);
LinearLayout importPGP = (LinearLayout) v.findViewById(R.id.button_import_openpgp); LinearLayout restorePGP = (LinearLayout) v.findViewById(R.id.button_restore_openpgp);
if (TextUtils.isEmpty(PGPProvider)) { if (TextUtils.isEmpty(PGPProvider)) {
setupPGP.setVisibility(View.VISIBLE); setupPGP.setVisibility(View.VISIBLE);
exportPGP.setVisibility(View.GONE); backupPGP.setVisibility(View.GONE);
importPGP.setVisibility(View.GONE); restorePGP.setVisibility(View.GONE);
} else if (pgpKeyId == 0){ } else if (pgpKeyId == 0){
setupPGP.setVisibility(View.VISIBLE); setupPGP.setVisibility(View.VISIBLE);
setupPGP.setText(R.string.backup_desc_openpgp_keyid); setupPGP.setText(R.string.backup_desc_openpgp_keyid);
exportPGP.setVisibility(View.GONE); backupPGP.setVisibility(View.GONE);
} else { } else {
pgpServiceConnection = new OpenPgpServiceConnection(BackupActivity.this.getApplicationContext(), PGPProvider); pgpServiceConnection = new OpenPgpServiceConnection(BackupActivity.this.getApplicationContext(), PGPProvider);
pgpServiceConnection.bindToService(); pgpServiceConnection.bindToService();
exportPGP.setOnClickListener(new View.OnClickListener() { backupPGP.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
saveFileWithPermissions(DEFAULT_BACKUP_MIMETYPE_PGP, DEFAULT_BACKUP_FILENAME_PGP, INTENT_SAVE_DOCUMENT_PGP, PERMISSIONS_REQUEST_WRITE_EXPORT_PGP); saveFileWithPermissions(DEFAULT_BACKUP_MIMETYPE_PGP, DEFAULT_BACKUP_FILENAME_PGP, INTENT_SAVE_DOCUMENT_PGP, PERMISSIONS_REQUEST_WRITE_EXPORT_PGP);
} }
}); });
importPGP.setOnClickListener(new View.OnClickListener() { restorePGP.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
openFileWithPermissions(INTENT_OPEN_DOCUMENT_PGP, PERMISSIONS_REQUEST_READ_IMPORT_PGP); openFileWithPermissions(INTENT_OPEN_DOCUMENT_PGP, PERMISSIONS_REQUEST_READ_IMPORT_PGP);
@ -221,22 +221,22 @@ public class BackupActivity extends AppCompatActivity {
if (requestCode == INTENT_OPEN_DOCUMENT_PLAIN && resultCode == RESULT_OK) { if (requestCode == INTENT_OPEN_DOCUMENT_PLAIN && resultCode == RESULT_OK) {
if (intent != null) { if (intent != null) {
doImportJSON(intent.getData()); doRestorePlain(intent.getData());
} }
} else if (requestCode == INTENT_SAVE_DOCUMENT_PLAIN && resultCode == RESULT_OK) { } else if (requestCode == INTENT_SAVE_DOCUMENT_PLAIN && resultCode == RESULT_OK) {
if (intent != null) { if (intent != null) {
doExportJSON(intent.getData()); doBackupPlain(intent.getData());
} }
} else if (requestCode == INTENT_OPEN_DOCUMENT_PGP && resultCode == RESULT_OK) { } else if (requestCode == INTENT_OPEN_DOCUMENT_PGP && resultCode == RESULT_OK) {
if (intent != null) if (intent != null)
importEncryptedWithPGP(intent.getData()); restoreEncryptedWithPGP(intent.getData());
} else if (requestCode == INTENT_SAVE_DOCUMENT_PGP && resultCode == RESULT_OK) { } else if (requestCode == INTENT_SAVE_DOCUMENT_PGP && resultCode == RESULT_OK) {
if (intent != null) if (intent != null)
exportEncryptedWithPGP(intent.getData()); backupEncryptedWithPGP(intent.getData());
} else if (requestCode == INTENT_ENCRYPT_PGP && resultCode == RESULT_OK) { } else if (requestCode == INTENT_ENCRYPT_PGP && resultCode == RESULT_OK) {
exportEncryptedWithPGP(encryptTargetFile); backupEncryptedWithPGP(encryptTargetFile);
} else if (requestCode == INTENT_DECRYPT_PGP && resultCode == RESULT_OK) { } else if (requestCode == INTENT_DECRYPT_PGP && resultCode == RESULT_OK) {
importEncryptedWithPGP(decryptSourceFile); restoreEncryptedWithPGP(decryptSourceFile);
} }
} }
@ -275,7 +275,7 @@ public class BackupActivity extends AppCompatActivity {
/* Plain-text backup functions */ /* Plain-text backup functions */
private void doImportJSON(Uri uri) { private void doRestorePlain(Uri uri) {
if (StorageHelper.isExternalStorageReadable()) { if (StorageHelper.isExternalStorageReadable()) {
boolean success = DatabaseHelper.importFromJSON(this, uri); boolean success = DatabaseHelper.importFromJSON(this, uri);
@ -292,7 +292,7 @@ public class BackupActivity extends AppCompatActivity {
finishWithResult(); finishWithResult();
} }
private void doExportJSON(Uri uri) { private void doBackupPlain(Uri uri) {
if (StorageHelper.isExternalStorageWritable()) { if (StorageHelper.isExternalStorageWritable()) {
boolean success = DatabaseHelper.exportAsJSON(this, uri); boolean success = DatabaseHelper.exportAsJSON(this, uri);
@ -307,7 +307,7 @@ public class BackupActivity extends AppCompatActivity {
finishWithResult(); finishWithResult();
} }
private void exportJSONWithWarning() { private void backupPlainWithWarning() {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.backup_dialog_title_security_warning) builder.setTitle(R.string.backup_dialog_title_security_warning)
@ -329,7 +329,7 @@ public class BackupActivity extends AppCompatActivity {
/* OpenPGP backup functions */ /* OpenPGP backup functions */
private void doImportEncrypted(String content) { private void doRestoreEncrypted(String content) {
if (StorageHelper.isExternalStorageReadable()) { if (StorageHelper.isExternalStorageReadable()) {
ArrayList<Entry> entries = DatabaseHelper.stringToEntries(this, content); ArrayList<Entry> entries = DatabaseHelper.stringToEntries(this, content);
@ -348,7 +348,7 @@ public class BackupActivity extends AppCompatActivity {
finishWithResult(); finishWithResult();
} }
private void importEncryptedWithPGP(Uri uri) { private void restoreEncryptedWithPGP(Uri uri) {
Intent decryptIntent = new Intent(OpenPgpApi.ACTION_DECRYPT_VERIFY); Intent decryptIntent = new Intent(OpenPgpApi.ACTION_DECRYPT_VERIFY);
String input = FileHelper.readFileToString(this, uri); String input = FileHelper.readFileToString(this, uri);
@ -367,7 +367,7 @@ public class BackupActivity extends AppCompatActivity {
handleOpenPGPResult(result, os, uri, INTENT_DECRYPT_PGP); handleOpenPGPResult(result, os, uri, INTENT_DECRYPT_PGP);
} }
private void doExportEncrypted(Uri uri, String data) { private void doBackupEncrypted(Uri uri, String data) {
if (StorageHelper.isExternalStorageWritable()) { if (StorageHelper.isExternalStorageWritable()) {
boolean success = FileHelper.writeStringToFile(this, uri, data); boolean success = FileHelper.writeStringToFile(this, uri, data);
@ -382,7 +382,7 @@ public class BackupActivity extends AppCompatActivity {
finishWithResult(); finishWithResult();
} }
private void exportEncryptedWithPGP(Uri uri) { private void backupEncryptedWithPGP(Uri uri) {
String plainJSON = DatabaseHelper.entriesToString(this); String plainJSON = DatabaseHelper.entriesToString(this);
Intent encryptIntent = new Intent(); Intent encryptIntent = new Intent();
@ -425,19 +425,19 @@ public class BackupActivity extends AppCompatActivity {
if (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR) == OpenPgpApi.RESULT_CODE_SUCCESS) { if (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR) == OpenPgpApi.RESULT_CODE_SUCCESS) {
if (requestCode == INTENT_ENCRYPT_PGP) { if (requestCode == INTENT_ENCRYPT_PGP) {
if (os != null) if (os != null)
doExportEncrypted(file, outputStreamToString(os)); doBackupEncrypted(file, outputStreamToString(os));
} else if (requestCode == INTENT_DECRYPT_PGP) { } else if (requestCode == INTENT_DECRYPT_PGP) {
if (os != null) { if (os != null) {
if (settings.getBoolean(getString(R.string.settings_key_openpgp_verify), false)) { if (settings.getBoolean(getString(R.string.settings_key_openpgp_verify), false)) {
OpenPgpSignatureResult sigResult = result.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE); OpenPgpSignatureResult sigResult = result.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE);
if (sigResult.getResult() == OpenPgpSignatureResult.RESULT_VALID_KEY_CONFIRMED) { if (sigResult.getResult() == OpenPgpSignatureResult.RESULT_VALID_KEY_CONFIRMED) {
doImportEncrypted(outputStreamToString(os)); doRestoreEncrypted(outputStreamToString(os));
} else { } else {
Toast.makeText(this, R.string.backup_toast_openpgp_not_verified, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.backup_toast_openpgp_not_verified, Toast.LENGTH_LONG).show();
} }
} else { } else {
doImportEncrypted(outputStreamToString(os)); doRestoreEncrypted(outputStreamToString(os));
} }
} }
} }

View file

@ -15,7 +15,7 @@
android:text="@string/backup_category_plain" /> android:text="@string/backup_category_plain" />
<LinearLayout <LinearLayout
android:id="@+id/button_export_plain" android:id="@+id/button_backup_plain"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -37,7 +37,7 @@
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/button_import_plain" android:id="@+id/button_restore_plain"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -77,7 +77,7 @@
android:text="@string/backup_desc_openpgp_provider"/> android:text="@string/backup_desc_openpgp_provider"/>
<LinearLayout <LinearLayout
android:id="@+id/button_export_openpgp" android:id="@+id/button_backup_openpgp"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -99,7 +99,7 @@
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/button_import_openpgp" android:id="@+id/button_restore_openpgp"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View file

@ -3,17 +3,17 @@
<string name="backup_activity_title">Backups</string> <string name="backup_activity_title">Backups</string>
<string name="backup_category_plain">Plain-text backups</string> <string name="backup_category_plain">Plain-text backups</string>
<string name="backup_category_openpgp">OpenPGP encrypted backups</string> <string name="backup_category_openpgp">OpenPGP backups</string>
<string name="backup_title_export_plain">Export to JSON</string> <string name="backup_title_export_plain">Backup (plain-text)</string>
<string name="backup_title_export_openpgp">Export to encrypted file</string> <string name="backup_title_export_openpgp">Backup (OpenPGP)</string>
<string name="backup_title_import_plain">Import from JSON</string> <string name="backup_title_import_plain">Restore (plain-text)</string>
<string name="backup_title_import_openpgp">Import from encrypted file</string> <string name="backup_title_import_openpgp">Restore (OpenPGP)</string>
<string name="backup_desc_export_plain">Export all accounts to a plain-text JSON file</string> <string name="backup_desc_export_plain">Backup all accounts in a plain-text JSON file</string>
<string name="backup_desc_export_openpgp">Export all accounts to an OpenPGP-encrypted JSON file</string> <string name="backup_desc_export_openpgp">Backup all accounts in an OpenPGP-encrypted JSON file</string>
<string name="backup_desc_import_plain">Import accounts from a plain-text JSON file</string> <string name="backup_desc_import_plain">Restore accounts from a plain-text JSON file</string>
<string name="backup_desc_import_openpgp">Import accounts from an OpenPGP-encrypted JSON file</string> <string name="backup_desc_import_openpgp">Restore accounts from an OpenPGP-encrypted JSON file</string>
<string name="backup_desc_openpgp_provider">You need to install an OpenPGP provider and enable <string name="backup_desc_openpgp_provider">You need to install an OpenPGP provider and enable
it in the Settings to use this feature. it in the Settings to use this feature.