diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/DecryptActivity.kt b/app/src/main/java/com/zeapo/pwdstore/crypto/DecryptActivity.kt index e0e82cd7..3685cb17 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/DecryptActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/DecryptActivity.kt @@ -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()) { diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitCommandExecutor.kt b/app/src/main/java/com/zeapo/pwdstore/git/GitCommandExecutor.kt index 6ef09537..ed5411ac 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitCommandExecutor.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitCommandExecutor.kt @@ -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 -> { + } } } } diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt index b3217395..49abc92d 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt @@ -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. */ diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt index 97010c23..4bbc5965 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt @@ -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, ) } } diff --git a/app/src/main/java/com/zeapo/pwdstore/git/log/GitLogActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/log/GitLogActivity.kt index 8c1c0f09..1e616bae 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/log/GitLogActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/log/GitLogActivity.kt @@ -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) diff --git a/app/src/main/res/menu/pgp_handler.xml b/app/src/main/res/menu/pgp_handler.xml index 53cd8b9c..44935595 100644 --- a/app/src/main/res/menu/pgp_handler.xml +++ b/app/src/main/res/menu/pgp_handler.xml @@ -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" />