From cb1feab350fb5cf90ecefe75b354472e492fa1c9 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 17 Jul 2019 11:32:56 +0200 Subject: [PATCH] open backup files on view action --- src/conversations/AndroidManifest.xml | 15 +++++- .../ui/ImportBackupActivity.java | 51 ++++++++++++------- src/main/AndroidManifest.xml | 1 - 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/conversations/AndroidManifest.xml b/src/conversations/AndroidManifest.xml index 0a01c6c0f..a91f4c129 100644 --- a/src/conversations/AndroidManifest.xml +++ b/src/conversations/AndroidManifest.xml @@ -23,7 +23,20 @@ + android:launchMode="singleTask"> + + + + + + + + + + + + + diff --git a/src/conversations/java/eu/siacs/conversations/ui/ImportBackupActivity.java b/src/conversations/java/eu/siacs/conversations/ui/ImportBackupActivity.java index 7ceff68f7..bca907b33 100644 --- a/src/conversations/java/eu/siacs/conversations/ui/ImportBackupActivity.java +++ b/src/conversations/java/eu/siacs/conversations/ui/ImportBackupActivity.java @@ -28,7 +28,6 @@ import eu.siacs.conversations.databinding.ActivityImportBackupBinding; import eu.siacs.conversations.databinding.DialogEnterPasswordBinding; import eu.siacs.conversations.services.ImportBackupService; import eu.siacs.conversations.ui.adapter.BackupFileAdapter; -import eu.siacs.conversations.ui.util.MenuDoubleTabUtil; import eu.siacs.conversations.utils.ThemeHelper; public class ImportBackupActivity extends ActionBarActivity implements ServiceConnection, ImportBackupService.OnBackupFilesLoaded, BackupFileAdapter.OnItemClickedListener, ImportBackupService.OnBackupProcessed { @@ -49,7 +48,7 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo super.onCreate(savedInstanceState); binding = DataBindingUtil.setContentView(this, R.layout.activity_import_backup); setSupportActionBar((Toolbar) binding.toolbar); - configureActionBar(getSupportActionBar()); + setLoadingState(savedInstanceState != null && savedInstanceState.getBoolean("loading_state", false)); this.backupFileAdapter = new BackupFileAdapter(); this.binding.list.setAdapter(this.backupFileAdapter); this.backupFileAdapter.setOnItemClickedListener(this); @@ -63,6 +62,12 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo return true; } + @Override + public void onSaveInstanceState(Bundle bundle) { + bundle.putBoolean("loading_state", this.mLoadingState); + super.onSaveInstanceState(bundle); + } + @Override public void onStart() { super.onStart(); @@ -72,6 +77,13 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo } else { bindService(new Intent(this, ImportBackupService.class), this, Context.BIND_AUTO_CREATE); } + final Intent intent = getIntent(); + if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction()) && !this.mLoadingState) { + Uri uri = intent.getData(); + if (uri != null) { + openBackupFileFromUri(uri, true); + } + } } @Override @@ -104,26 +116,30 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo @Override public void onClick(final ImportBackupService.BackupFile backupFile) { - showEnterPasswordDialog(backupFile); + showEnterPasswordDialog(backupFile, false); } - private void openBackupFileFromUri(final Uri uri) { + private void openBackupFileFromUri(final Uri uri, final boolean finishOnCancel) { try { final ImportBackupService.BackupFile backupFile = ImportBackupService.BackupFile.read(this, uri); - showEnterPasswordDialog(backupFile); + showEnterPasswordDialog(backupFile, finishOnCancel); } catch (IOException e) { Snackbar.make(binding.coordinator, R.string.not_a_backup_file, Snackbar.LENGTH_LONG).show(); } } - private void showEnterPasswordDialog(final ImportBackupService.BackupFile backupFile) { + private void showEnterPasswordDialog(final ImportBackupService.BackupFile backupFile, final boolean finishOnCancel) { final DialogEnterPasswordBinding enterPasswordBinding = DataBindingUtil.inflate(LayoutInflater.from(this), R.layout.dialog_enter_password, null, false); Log.d(Config.LOGTAG, "attempting to import " + backupFile.getUri()); enterPasswordBinding.explain.setText(getString(R.string.enter_password_to_restore, backupFile.getHeader().getJid().toString())); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(enterPasswordBinding.getRoot()); builder.setTitle(R.string.enter_password); - builder.setNegativeButton(R.string.cancel, null); + builder.setNegativeButton(R.string.cancel, (dialog, which) -> { + if (finishOnCancel) { + finish(); + } + }); builder.setPositiveButton(R.string.restore, (dialog, which) -> { final String password = enterPasswordBinding.accountPassword.getEditableText().toString(); final Uri uri = backupFile.getUri(); @@ -156,7 +172,7 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (resultCode == RESULT_OK) { if (requestCode == 0xbac) { - openBackupFileFromUri(intent.getData()); + openBackupFileFromUri(intent.getData(), false); } } } @@ -197,16 +213,15 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.action_open_backup_file: - Intent intent = new Intent(Intent.ACTION_GET_CONTENT); - intent.setType("*/*"); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { - intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, false); - } - intent.addCategory(Intent.CATEGORY_OPENABLE); - startActivityForResult(Intent.createChooser(intent, getString(R.string.open_backup)), 0xbac); - return true; + if (item.getItemId() == R.id.action_open_backup_file) { + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.setType("*/*"); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, false); + } + intent.addCategory(Intent.CATEGORY_OPENABLE); + startActivityForResult(Intent.createChooser(intent, getString(R.string.open_backup)), 0xbac); + return true; } return super.onOptionsItemSelected(item); } diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 6b43106f9..31f33e5fd 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -92,7 +92,6 @@ android:theme="@style/SplashTheme"> -