diff options
Diffstat (limited to 'app/src/main')
5 files changed, 52 insertions, 27 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt index 36ea7ae4..013a922d 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt @@ -110,7 +110,11 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) { binding.swipeRefresher.isRefreshing = false refreshPasswordList() }, - failure = ::finishAfterPromptOnErrorHandler, + failure = { err -> + promptOnErrorHandler(err) { + binding.swipeRefresher.isRefreshing = false + } + }, ) } } diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt index 4ad4fb91..2639c6b6 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt @@ -315,7 +315,7 @@ class PasswordStore : BaseGitActivity() { private fun runGitOperation(operation: Int) = lifecycleScope.launch { launchGitOperation(operation).fold( success = { refreshPasswordList() }, - failure = ::finishAfterPromptOnErrorHandler, + failure = ::promptOnErrorHandler ) } diff --git a/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt index dd8ea731..a15972c1 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt @@ -61,7 +61,7 @@ abstract class BaseGitActivity : AppCompatActivity() { finish() } - fun finishAfterPromptOnErrorHandler(err: Throwable) { + fun promptOnErrorHandler(err: Throwable, onPromptDone: () -> Unit = {}) { val error = rootCauseException(err) if (!isExplicitlyUserInitiatedError(error)) { getEncryptedPrefs("git_operation").edit { @@ -69,12 +69,17 @@ abstract class BaseGitActivity : AppCompatActivity() { } sharedPrefs.edit { remove(PreferenceKeys.SSH_OPENKEYSTORE_KEYID) } d(error) - MaterialAlertDialogBuilder(this) - .setTitle(resources.getString(R.string.jgit_error_dialog_title)) - .setMessage(ErrorMessages[error]) - .setPositiveButton(resources.getString(R.string.dialog_ok)) { _, _ -> - finish() - }.show() + MaterialAlertDialogBuilder(this).run { + setTitle(resources.getString(R.string.jgit_error_dialog_title)) + setMessage(ErrorMessages[error]) + setPositiveButton(resources.getString(R.string.dialog_ok)) { _, _ -> } + setOnDismissListener { + onPromptDone() + } + show() + } + } else { + onPromptDone() } } 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 46a54f57..b3217395 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt @@ -81,28 +81,36 @@ class GitConfigActivity : BaseGitActivity() { binding.gitAbortRebase.setOnClickListener { lifecycleScope.launch { launchGitOperation(BREAK_OUT_OF_DETACHED).fold( - success = { - MaterialAlertDialogBuilder(this@GitConfigActivity) - .setTitle(resources.getString(R.string.git_abort_and_push_title)) - .setMessage(resources.getString( - R.string.git_break_out_of_detached_success, - GitSettings.branch, - "conflicting-${GitSettings.branch}-...", - )) - .setOnCancelListener { finish() } - .setPositiveButton(resources.getString(R.string.dialog_ok)) { _, _ -> - finish() - }.show() - }, - failure = ::finishAfterPromptOnErrorHandler, + success = { + MaterialAlertDialogBuilder(this@GitConfigActivity).run { + setTitle(resources.getString(R.string.git_abort_and_push_title)) + setMessage(resources.getString( + R.string.git_break_out_of_detached_success, + GitSettings.branch, + "conflicting-${GitSettings.branch}-...", + )) + setOnDismissListener() { finish() } + setPositiveButton(resources.getString(R.string.dialog_ok)) { _, _ -> } + show() + } + }, + failure = { err -> + promptOnErrorHandler(err) { + finish() + } + }, ) } } binding.gitResetToRemote.setOnClickListener { lifecycleScope.launch { launchGitOperation(REQUEST_RESET).fold( - success = ::finishOnSuccessHandler, - failure = ::finishAfterPromptOnErrorHandler, + success = ::finishOnSuccessHandler, + failure = { err -> + promptOnErrorHandler(err) { + finish() + } + }, ) } } 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 c18c79c6..97010c23 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt @@ -130,7 +130,11 @@ class GitServerConfigActivity : BaseGitActivity() { setResult(RESULT_OK) finish() }, - failure = ::finishAfterPromptOnErrorHandler, + failure = { err -> + promptOnErrorHandler(err) { + finish() + } + } ) } }.onFailure { e -> @@ -160,7 +164,11 @@ class GitServerConfigActivity : BaseGitActivity() { setResult(RESULT_OK) finish() }, - failure = ::finishAfterPromptOnErrorHandler, + failure = { err -> + promptOnErrorHandler(err) { + finish() + } + }, ) } } |