UX fixups and improvements (#1086)

* git: re-add back button handling

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>

* Hide unsupported authentication methods

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>

* GitCommandExecutor: cleanup and address build warning

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>

* Address review comments

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>

* DecryptActivity: hide menu items until decrypt finishes

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>

* GitServerConfigActivity: don't finish on failure

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-09-07 20:13:04 +05:30 committed by GitHub
parent 2687763bda
commit c65f3c7099
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 6 deletions

View file

@ -82,6 +82,15 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.pgp_handler, menu)
passwordEntry?.let { entry ->
if (menu != null) {
menu.findItem(R.id.edit_password).isVisible = true
if (entry.password.isNotEmpty()) {
menu.findItem(R.id.share_password_as_plaintext).isVisible = true
menu.findItem(R.id.copy_password).isVisible = true
}
}
}
return true
}
@ -153,6 +162,7 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
val entry = PasswordEntry(outputStream)
passwordEntry = entry
invalidateOptionsMenu()
with(binding) {
if (entry.password.isEmpty()) {

View file

@ -8,6 +8,7 @@ package com.zeapo.pwdstore.git
import android.widget.Toast
import androidx.fragment.app.FragmentActivity
import com.github.michaelbull.result.Result
import com.github.michaelbull.result.runCatching
import com.google.android.material.snackbar.Snackbar
import com.zeapo.pwdstore.R
import com.zeapo.pwdstore.git.GitException.PullException
@ -37,7 +38,7 @@ class GitCommandExecutor(
)
// Count the number of uncommitted files
var nbChanges = 0
return com.github.michaelbull.result.runCatching {
return runCatching {
for (command in operation.commands) {
when (command) {
is StatusCommand -> {
@ -95,6 +96,8 @@ class GitCommandExecutor(
).show()
}
}
else -> {
}
}
}
}

View file

@ -8,6 +8,7 @@ import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.util.Patterns
import android.view.MenuItem
import androidx.core.os.postDelayed
import androidx.lifecycle.lifecycleScope
import com.github.ajalt.timberkt.e
@ -59,6 +60,16 @@ class GitConfigActivity : BaseGitActivity() {
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
finish()
true
}
else -> super.onOptionsItemSelected(item)
}
}
/**
* Sets up the UI components of the tools section.
*/

View file

@ -6,8 +6,11 @@ package com.zeapo.pwdstore.git
import android.os.Bundle
import android.os.Handler
import android.view.MenuItem
import android.view.View
import androidx.core.os.postDelayed
import androidx.core.view.isVisible
import androidx.core.widget.doOnTextChanged
import androidx.lifecycle.lifecycleScope
import com.github.ajalt.timberkt.e
import com.github.michaelbull.result.fold
@ -68,6 +71,19 @@ class GitServerConfigActivity : BaseGitActivity() {
binding.serverUrl.setText(GitSettings.url)
binding.serverBranch.setText(GitSettings.branch)
binding.serverUrl.doOnTextChanged { text, _, _, _ ->
if (text.isNullOrEmpty()) return@doOnTextChanged
if (text.startsWith("http://") || text.startsWith("https://")) {
binding.authModeSshKey.isVisible = false
binding.authModeOpenKeychain.isVisible = false
binding.authModePassword.isVisible = true
} else {
binding.authModeSshKey.isVisible = true
binding.authModeOpenKeychain.isVisible = true
binding.authModePassword.isVisible = true
}
}
binding.saveButton.setOnClickListener {
when (val updateResult = GitSettings.updateConnectionSettingsIfValid(
newAuthMode = newAuthMode,
@ -104,6 +120,16 @@ class GitServerConfigActivity : BaseGitActivity() {
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
finish()
true
}
else -> super.onOptionsItemSelected(item)
}
}
/**
* Clones the repository, the directory exists, deletes it
*/
@ -164,11 +190,7 @@ class GitServerConfigActivity : BaseGitActivity() {
setResult(RESULT_OK)
finish()
},
failure = { err ->
promptOnErrorHandler(err) {
finish()
}
},
failure = ::promptOnErrorHandler,
)
}
}

View file

@ -6,6 +6,7 @@
package com.zeapo.pwdstore.git.log
import android.os.Bundle
import android.view.MenuItem
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.zeapo.pwdstore.databinding.ActivityGitLogBinding
@ -28,6 +29,16 @@ class GitLogActivity : BaseGitActivity() {
createRecyclerView()
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
finish()
true
}
else -> super.onOptionsItemSelected(item)
}
}
private fun createRecyclerView() {
binding.gitLogRecyclerView.apply {
setHasFixedSize(true)

View file

@ -11,15 +11,18 @@
android:id="@+id/share_password_as_plaintext"
android:icon="@drawable/ic_share_24dp"
android:title="@string/share_as_plaintext"
android:visible="false"
pwstore:showAsAction="ifRoom" />
<item
android:id="@+id/copy_password"
android:icon="@drawable/ic_content_copy"
android:title="@string/copy_password"
android:visible="false"
pwstore:showAsAction="ifRoom" />
<item
android:id="@+id/edit_password"
android:icon="@drawable/ic_edit_24dp"
android:title="@string/edit_password"
android:visible="false"
pwstore:showAsAction="ifRoom" />
</menu>