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
- 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
- Pressing the back button in the navigation bar and the one in the toolbar behaved differently
### Changed

View file

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

View file

@ -60,6 +60,7 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
bindToOpenKeychain(this)
title = name
with(binding) {
@ -100,8 +101,9 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
R.id.edit_password -> 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) {

View file

@ -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

View file

@ -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() {

View file

@ -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)

View file

@ -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)

View file

@ -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() {

View file

@ -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)

View file

@ -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()