aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorFabian Henneke <FabianHenneke@users.noreply.github.com>2020-09-07 10:10:59 +0200
committerGitHub <noreply@github.com>2020-09-07 13:40:59 +0530
commit2687763bdaa36709667d38919b7cba1a7e26206f (patch)
treedd91c387b59c107e1521b426f3e7852b26772866 /app/src
parent2c0ecdfb67aeb8d47702159e1c61659679bc9408 (diff)
Fix behavior on failing Git operations (#1084)
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt6
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt2
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt19
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt40
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt12
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()
+ }
+ },
)
}
}