Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit c65f3c7

Browse files
authored
UX fixups and improvements (#1086)
* git: re-add back button handling Signed-off-by: Harsh Shandilya <[email protected]> * Hide unsupported authentication methods Signed-off-by: Harsh Shandilya <[email protected]> * GitCommandExecutor: cleanup and address build warning Signed-off-by: Harsh Shandilya <[email protected]> * Address review comments Signed-off-by: Harsh Shandilya <[email protected]> * DecryptActivity: hide menu items until decrypt finishes Signed-off-by: Harsh Shandilya <[email protected]> * GitServerConfigActivity: don't finish on failure Signed-off-by: Harsh Shandilya <[email protected]>
1 parent 2687763 commit c65f3c7

File tree

6 files changed

+66
-6
lines changed

6 files changed

+66
-6
lines changed

app/src/main/java/com/zeapo/pwdstore/crypto/DecryptActivity.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
8282

8383
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
8484
menuInflater.inflate(R.menu.pgp_handler, menu)
85+
passwordEntry?.let { entry ->
86+
if (menu != null) {
87+
menu.findItem(R.id.edit_password).isVisible = true
88+
if (entry.password.isNotEmpty()) {
89+
menu.findItem(R.id.share_password_as_plaintext).isVisible = true
90+
menu.findItem(R.id.copy_password).isVisible = true
91+
}
92+
}
93+
}
8594
return true
8695
}
8796

@@ -153,6 +162,7 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
153162
val entry = PasswordEntry(outputStream)
154163

155164
passwordEntry = entry
165+
invalidateOptionsMenu()
156166

157167
with(binding) {
158168
if (entry.password.isEmpty()) {

app/src/main/java/com/zeapo/pwdstore/git/GitCommandExecutor.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package com.zeapo.pwdstore.git
88
import android.widget.Toast
99
import androidx.fragment.app.FragmentActivity
1010
import com.github.michaelbull.result.Result
11+
import com.github.michaelbull.result.runCatching
1112
import com.google.android.material.snackbar.Snackbar
1213
import com.zeapo.pwdstore.R
1314
import com.zeapo.pwdstore.git.GitException.PullException
@@ -37,7 +38,7 @@ class GitCommandExecutor(
3738
)
3839
// Count the number of uncommitted files
3940
var nbChanges = 0
40-
return com.github.michaelbull.result.runCatching {
41+
return runCatching {
4142
for (command in operation.commands) {
4243
when (command) {
4344
is StatusCommand -> {
@@ -95,6 +96,8 @@ class GitCommandExecutor(
9596
).show()
9697
}
9798
}
99+
else -> {
100+
}
98101
}
99102
}
100103
}

app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.content.Intent
88
import android.os.Bundle
99
import android.os.Handler
1010
import android.util.Patterns
11+
import android.view.MenuItem
1112
import androidx.core.os.postDelayed
1213
import androidx.lifecycle.lifecycleScope
1314
import com.github.ajalt.timberkt.e
@@ -59,6 +60,16 @@ class GitConfigActivity : BaseGitActivity() {
5960
}
6061
}
6162

63+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
64+
return when (item.itemId) {
65+
android.R.id.home -> {
66+
finish()
67+
true
68+
}
69+
else -> super.onOptionsItemSelected(item)
70+
}
71+
}
72+
6273
/**
6374
* Sets up the UI components of the tools section.
6475
*/

app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ package com.zeapo.pwdstore.git
66

77
import android.os.Bundle
88
import android.os.Handler
9+
import android.view.MenuItem
910
import android.view.View
1011
import androidx.core.os.postDelayed
12+
import androidx.core.view.isVisible
13+
import androidx.core.widget.doOnTextChanged
1114
import androidx.lifecycle.lifecycleScope
1215
import com.github.ajalt.timberkt.e
1316
import com.github.michaelbull.result.fold
@@ -68,6 +71,19 @@ class GitServerConfigActivity : BaseGitActivity() {
6871
binding.serverUrl.setText(GitSettings.url)
6972
binding.serverBranch.setText(GitSettings.branch)
7073

74+
binding.serverUrl.doOnTextChanged { text, _, _, _ ->
75+
if (text.isNullOrEmpty()) return@doOnTextChanged
76+
if (text.startsWith("http://") || text.startsWith("https://")) {
77+
binding.authModeSshKey.isVisible = false
78+
binding.authModeOpenKeychain.isVisible = false
79+
binding.authModePassword.isVisible = true
80+
} else {
81+
binding.authModeSshKey.isVisible = true
82+
binding.authModeOpenKeychain.isVisible = true
83+
binding.authModePassword.isVisible = true
84+
}
85+
}
86+
7187
binding.saveButton.setOnClickListener {
7288
when (val updateResult = GitSettings.updateConnectionSettingsIfValid(
7389
newAuthMode = newAuthMode,
@@ -104,6 +120,16 @@ class GitServerConfigActivity : BaseGitActivity() {
104120
}
105121
}
106122

123+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
124+
return when (item.itemId) {
125+
android.R.id.home -> {
126+
finish()
127+
true
128+
}
129+
else -> super.onOptionsItemSelected(item)
130+
}
131+
}
132+
107133
/**
108134
* Clones the repository, the directory exists, deletes it
109135
*/
@@ -164,11 +190,7 @@ class GitServerConfigActivity : BaseGitActivity() {
164190
setResult(RESULT_OK)
165191
finish()
166192
},
167-
failure = { err ->
168-
promptOnErrorHandler(err) {
169-
finish()
170-
}
171-
},
193+
failure = ::promptOnErrorHandler,
172194
)
173195
}
174196
}

app/src/main/java/com/zeapo/pwdstore/git/log/GitLogActivity.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package com.zeapo.pwdstore.git.log
77

88
import android.os.Bundle
9+
import android.view.MenuItem
910
import androidx.recyclerview.widget.DividerItemDecoration
1011
import androidx.recyclerview.widget.LinearLayoutManager
1112
import com.zeapo.pwdstore.databinding.ActivityGitLogBinding
@@ -28,6 +29,16 @@ class GitLogActivity : BaseGitActivity() {
2829
createRecyclerView()
2930
}
3031

32+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
33+
return when (item.itemId) {
34+
android.R.id.home -> {
35+
finish()
36+
true
37+
}
38+
else -> super.onOptionsItemSelected(item)
39+
}
40+
}
41+
3142
private fun createRecyclerView() {
3243
binding.gitLogRecyclerView.apply {
3344
setHasFixedSize(true)

app/src/main/res/menu/pgp_handler.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@
1111
android:id="@+id/share_password_as_plaintext"
1212
android:icon="@drawable/ic_share_24dp"
1313
android:title="@string/share_as_plaintext"
14+
android:visible="false"
1415
pwstore:showAsAction="ifRoom" />
1516
<item
1617
android:id="@+id/copy_password"
1718
android:icon="@drawable/ic_content_copy"
1819
android:title="@string/copy_password"
20+
android:visible="false"
1921
pwstore:showAsAction="ifRoom" />
2022
<item
2123
android:id="@+id/edit_password"
2224
android:icon="@drawable/ic_edit_24dp"
2325
android:title="@string/edit_password"
26+
android:visible="false"
2427
pwstore:showAsAction="ifRoom" />
2528
</menu>

0 commit comments

Comments
 (0)