From 91e00d897f190ec6ab5330f7b3f43d6d7f3e57fb Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Fri, 8 Jan 2021 19:43:52 +0530 Subject: app: cleanup how we handle menu item presses (#1275) Fixes #1274 Signed-off-by: Harsh Shandilya --- app/src/main/AndroidManifest.xml | 6 +---- .../dev/msfjarvis/aps/ui/crypto/DecryptActivity.kt | 4 ++- .../aps/ui/crypto/PasswordCreationActivity.kt | 3 ++- .../aps/ui/folderselect/SelectFolderActivity.kt | 6 ++--- .../aps/ui/git/config/GitConfigActivity.kt | 2 +- .../aps/ui/git/config/GitServerConfigActivity.kt | 2 +- .../msfjarvis/aps/ui/passwords/PasswordStore.kt | 29 +++++++--------------- .../msfjarvis/aps/ui/settings/UserPreference.kt | 5 +--- .../aps/ui/sshkeygen/SshKeyGenActivity.kt | 1 - 9 files changed, 21 insertions(+), 37 deletions(-) (limited to 'app') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 609b4c86..3e1d743e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -71,23 +71,19 @@ + android:label="@string/action_settings" /> editPassword() R.id.share_password_as_plaintext -> shareAsPlaintext() R.id.copy_password -> copyPasswordToClipboard(passwordEntry?.password) + else -> return super.onOptionsItemSelected(item) } - return super.onOptionsItemSelected(item) + return true } override fun onBound(service: IOpenPgpService2) { diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/crypto/PasswordCreationActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/crypto/PasswordCreationActivity.kt index 2ddcc8b8..a6385e7a 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/crypto/PasswordCreationActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/crypto/PasswordCreationActivity.kt @@ -135,6 +135,7 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + supportActionBar?.setDisplayHomeAsUpEnabled(true) bindToOpenKeychain(this) title = if (editing) getString(R.string.edit_password) @@ -232,7 +233,7 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB when (item.itemId) { android.R.id.home -> { setResult(RESULT_CANCELED) - finish() + onBackPressed() } R.id.save_password -> { copy = false diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/folderselect/SelectFolderActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/folderselect/SelectFolderActivity.kt index f2d655bb..d80e3572 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/folderselect/SelectFolderActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/folderselect/SelectFolderActivity.kt @@ -47,12 +47,12 @@ class SelectFolderActivity : AppCompatActivity(R.layout.select_folder_layout) { when (item.itemId) { android.R.id.home -> { setResult(RESULT_CANCELED) - finish() - return true + onBackPressed() } R.id.crypto_select -> selectFolder() + else -> return super.onOptionsItemSelected(item) } - return super.onOptionsItemSelected(item) + return true } private fun selectFolder() { diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/git/config/GitConfigActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/git/config/GitConfigActivity.kt index 4067fda9..d354ce4e 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/git/config/GitConfigActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/git/config/GitConfigActivity.kt @@ -65,7 +65,7 @@ class GitConfigActivity : BaseGitActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { return when (item.itemId) { android.R.id.home -> { - finish() + onBackPressed() true } else -> super.onOptionsItemSelected(item) diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/git/config/GitServerConfigActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/git/config/GitServerConfigActivity.kt index 9826593c..db12e353 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/git/config/GitServerConfigActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/git/config/GitServerConfigActivity.kt @@ -172,7 +172,7 @@ class GitServerConfigActivity : BaseGitActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { return when (item.itemId) { android.R.id.home -> { - finish() + onBackPressed() true } else -> super.onOptionsItemSelected(item) diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt b/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt index c7ed5ee9..49620ac8 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt @@ -292,9 +292,6 @@ class PasswordStore : BaseGitActivity() { return super.onPrepareOptionsMenu(menu) } - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. override fun onOptionsItemSelected(item: MenuItem): Boolean { val id = item.itemId val initBefore = MaterialAlertDialogBuilder(this) @@ -307,41 +304,33 @@ class PasswordStore : BaseGitActivity() { }.onFailure { e -> e.printStackTrace() } - return true } R.id.git_push -> { if (!PasswordRepository.isInitialized) { initBefore.show() - return false + } else { + runGitOperation(GitOp.PUSH) } - runGitOperation(GitOp.PUSH) - return true } R.id.git_pull -> { if (!PasswordRepository.isInitialized) { initBefore.show() - return false + } else { + runGitOperation(GitOp.PULL) } - runGitOperation(GitOp.PULL) - return true } R.id.git_sync -> { if (!PasswordRepository.isInitialized) { initBefore.show() - return false + } else { + runGitOperation(GitOp.SYNC) } - runGitOperation(GitOp.SYNC) - return true - } - R.id.refresh -> { - refreshPasswordList() - return true } + R.id.refresh -> refreshPasswordList() android.R.id.home -> onBackPressed() - else -> { - } + else -> return super.onOptionsItemSelected(item) } - return super.onOptionsItemSelected(item) + return true } override fun onBackPressed() { diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/settings/UserPreference.kt b/app/src/main/java/dev/msfjarvis/aps/ui/settings/UserPreference.kt index 7caf5fb2..315ebbda 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/settings/UserPreference.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/settings/UserPreference.kt @@ -581,13 +581,10 @@ class UserPreference : AppCompatActivity() { } override fun onOptionsItemSelected(item: MenuItem): Boolean { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. return when (item.itemId) { android.R.id.home -> { setResult(RESULT_OK) - finish() + onBackPressed() true } else -> super.onOptionsItemSelected(item) diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/sshkeygen/SshKeyGenActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/sshkeygen/SshKeyGenActivity.kt index 39819988..b260b77e 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/sshkeygen/SshKeyGenActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/sshkeygen/SshKeyGenActivity.kt @@ -95,7 +95,6 @@ class SshKeyGenActivity : AppCompatActivity() { } override fun onOptionsItemSelected(item: MenuItem): Boolean { - // The back arrow in the action bar should act the same as the back button. return when (item.itemId) { android.R.id.home -> { onBackPressed() -- cgit v1.2.3