app: cleanup how we handle menu item presses (#1275)

Fixes #1274

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2021-01-08 19:43:52 +05:30 committed by GitHub
parent 534269c8fc
commit 91e00d897f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 22 additions and 37 deletions

View file

@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file.
- Git commits in the store would wrongly use the 'default' committer as opposed to the user's configured one - Git commits in the store would wrongly use the 'default' committer as opposed to the user's configured one
- Connection attempts now use a reasonable 10 second timeout as opposed to the default of 30 seconds - Connection attempts now use a reasonable 10 second timeout as opposed to the default of 30 seconds
- A change to the remote host key for a server would prevent the user from being able to connect to it - A change to the remote host key for a server would prevent the user from being able to connect to it
- Pressing the back button in the navigation bar and the one in the toolbar behaved differently
### Changed ### Changed

View file

@ -71,23 +71,19 @@
<activity <activity
android:name=".ui.settings.UserPreference" android:name=".ui.settings.UserPreference"
android:label="@string/action_settings" android:label="@string/action_settings" />
android:parentActivityName=".ui.passwords.PasswordStore" />
<activity <activity
android:name=".ui.crypto.PasswordCreationActivity" android:name=".ui.crypto.PasswordCreationActivity"
android:label="@string/new_password_title" android:label="@string/new_password_title"
android:parentActivityName=".ui.passwords.PasswordStore"
android:windowSoftInputMode="adjustResize" /> android:windowSoftInputMode="adjustResize" />
<activity <activity
android:name=".ui.crypto.DecryptActivity" android:name=".ui.crypto.DecryptActivity"
android:parentActivityName=".ui.passwords.PasswordStore"
android:windowSoftInputMode="adjustResize" /> android:windowSoftInputMode="adjustResize" />
<activity <activity
android:name=".ui.crypto.GetKeyIdsActivity" android:name=".ui.crypto.GetKeyIdsActivity"
android:parentActivityName=".ui.passwords.PasswordStore"
android:theme="@style/NoBackgroundTheme" /> android:theme="@style/NoBackgroundTheme" />
<service <service

View file

@ -60,6 +60,7 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
bindToOpenKeychain(this) bindToOpenKeychain(this)
title = name title = name
with(binding) { with(binding) {
@ -100,8 +101,9 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
R.id.edit_password -> editPassword() R.id.edit_password -> editPassword()
R.id.share_password_as_plaintext -> shareAsPlaintext() R.id.share_password_as_plaintext -> shareAsPlaintext()
R.id.copy_password -> copyPasswordToClipboard(passwordEntry?.password) R.id.copy_password -> copyPasswordToClipboard(passwordEntry?.password)
else -> return super.onOptionsItemSelected(item)
} }
return super.onOptionsItemSelected(item) return true
} }
override fun onBound(service: IOpenPgpService2) { override fun onBound(service: IOpenPgpService2) {

View file

@ -135,6 +135,7 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
bindToOpenKeychain(this) bindToOpenKeychain(this)
title = if (editing) title = if (editing)
getString(R.string.edit_password) getString(R.string.edit_password)
@ -232,7 +233,7 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB
when (item.itemId) { when (item.itemId) {
android.R.id.home -> { android.R.id.home -> {
setResult(RESULT_CANCELED) setResult(RESULT_CANCELED)
finish() onBackPressed()
} }
R.id.save_password -> { R.id.save_password -> {
copy = false copy = false

View file

@ -47,12 +47,12 @@ class SelectFolderActivity : AppCompatActivity(R.layout.select_folder_layout) {
when (item.itemId) { when (item.itemId) {
android.R.id.home -> { android.R.id.home -> {
setResult(RESULT_CANCELED) setResult(RESULT_CANCELED)
finish() onBackPressed()
return true
} }
R.id.crypto_select -> selectFolder() R.id.crypto_select -> selectFolder()
else -> return super.onOptionsItemSelected(item)
} }
return super.onOptionsItemSelected(item) return true
} }
private fun selectFolder() { private fun selectFolder() {

View file

@ -65,7 +65,7 @@ class GitConfigActivity : BaseGitActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) { return when (item.itemId) {
android.R.id.home -> { android.R.id.home -> {
finish() onBackPressed()
true true
} }
else -> super.onOptionsItemSelected(item) else -> super.onOptionsItemSelected(item)

View file

@ -172,7 +172,7 @@ class GitServerConfigActivity : BaseGitActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) { return when (item.itemId) {
android.R.id.home -> { android.R.id.home -> {
finish() onBackPressed()
true true
} }
else -> super.onOptionsItemSelected(item) else -> super.onOptionsItemSelected(item)

View file

@ -292,9 +292,6 @@ class PasswordStore : BaseGitActivity() {
return super.onPrepareOptionsMenu(menu) 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 { override fun onOptionsItemSelected(item: MenuItem): Boolean {
val id = item.itemId val id = item.itemId
val initBefore = MaterialAlertDialogBuilder(this) val initBefore = MaterialAlertDialogBuilder(this)
@ -307,41 +304,33 @@ class PasswordStore : BaseGitActivity() {
}.onFailure { e -> }.onFailure { e ->
e.printStackTrace() e.printStackTrace()
} }
return true
} }
R.id.git_push -> { R.id.git_push -> {
if (!PasswordRepository.isInitialized) { if (!PasswordRepository.isInitialized) {
initBefore.show() initBefore.show()
return false } else {
}
runGitOperation(GitOp.PUSH) runGitOperation(GitOp.PUSH)
return true }
} }
R.id.git_pull -> { R.id.git_pull -> {
if (!PasswordRepository.isInitialized) { if (!PasswordRepository.isInitialized) {
initBefore.show() initBefore.show()
return false } else {
}
runGitOperation(GitOp.PULL) runGitOperation(GitOp.PULL)
return true }
} }
R.id.git_sync -> { R.id.git_sync -> {
if (!PasswordRepository.isInitialized) { if (!PasswordRepository.isInitialized) {
initBefore.show() 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() android.R.id.home -> onBackPressed()
else -> { else -> return super.onOptionsItemSelected(item)
} }
} return true
return super.onOptionsItemSelected(item)
} }
override fun onBackPressed() { override fun onBackPressed() {

View file

@ -581,13 +581,10 @@ class UserPreference : AppCompatActivity() {
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { 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) { return when (item.itemId) {
android.R.id.home -> { android.R.id.home -> {
setResult(RESULT_OK) setResult(RESULT_OK)
finish() onBackPressed()
true true
} }
else -> super.onOptionsItemSelected(item) else -> super.onOptionsItemSelected(item)

View file

@ -95,7 +95,6 @@ class SshKeyGenActivity : AppCompatActivity() {
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { 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) { return when (item.itemId) {
android.R.id.home -> { android.R.id.home -> {
onBackPressed() onBackPressed()