Fix behavior on failing Git operations (#1084)
This commit is contained in:
parent
2c0ecdfb67
commit
2687763bda
5 changed files with 52 additions and 27 deletions
|
@ -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
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -315,7 +315,7 @@ class PasswordStore : BaseGitActivity() {
|
|||
private fun runGitOperation(operation: Int) = lifecycleScope.launch {
|
||||
launchGitOperation(operation).fold(
|
||||
success = { refreshPasswordList() },
|
||||
failure = ::finishAfterPromptOnErrorHandler,
|
||||
failure = ::promptOnErrorHandler
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue