diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2022-11-27 13:10:26 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2022-11-27 13:28:46 +0530 |
commit | d4dd147c25b8fe38d4d4ae567237eb9265e62df0 (patch) | |
tree | ae21b2bc63012c4787dc37e4e4605d41c98e3014 /app | |
parent | 56a25dcd3231d2bf6aea98f0eda0a782afe91788 (diff) |
refactor: break out overly long method
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/app/passwordstore/ui/git/config/GitConfigActivity.kt | 86 |
1 files changed, 45 insertions, 41 deletions
diff --git a/app/src/main/java/app/passwordstore/ui/git/config/GitConfigActivity.kt b/app/src/main/java/app/passwordstore/ui/git/config/GitConfigActivity.kt index 96a9d191..a783273d 100644 --- a/app/src/main/java/app/passwordstore/ui/git/config/GitConfigActivity.kt +++ b/app/src/main/java/app/passwordstore/ui/git/config/GitConfigActivity.kt @@ -94,56 +94,60 @@ class GitConfigActivity : BaseGitActivity() { runCatching { startActivity(Intent(this, GitLogActivity::class.java)) } .onFailure { ex -> logcat(ERROR) { ex.asLog("Failed to start GitLogActivity") } } } - binding.gitAbortRebase.setOnClickListener { + binding.gitAbortRebase.setOnClickListener { abortRebase() } + binding.gitResetToRemote.setOnClickListener { resetToRemote() } + binding.gitGc.setOnClickListener { lifecycleScope.launch { - launchGitOperation(GitOp.BREAK_OUT_OF_DETACHED) + launchGitOperation(GitOp.GC) .fold( - success = { - val branch = PasswordRepository.getCurrentBranch() - 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, - branch, - "conflicting-$branch-...", - ) - ) - setOnDismissListener { finish() } - setPositiveButton(resources.getString(R.string.dialog_ok)) { _, _ -> } - show() - } - }, + success = ::finishOnSuccessHandler, failure = { err -> promptOnErrorHandler(err) { finish() } }, ) } } - binding.gitResetToRemote.setOnClickListener { - val dialog = - TextInputDialog.newInstance(getString(R.string.git_utils_reset_remote_branch_title)) - dialog.show(supportFragmentManager, "BRANCH_INPUT_DIALOG") - dialog.setFragmentResultListener(TextInputDialog.REQUEST_KEY) { _, bundle -> - val result = bundle.getString(TextInputDialog.BUNDLE_KEY_TEXT) - if (!result.isNullOrEmpty()) { - remoteBranch = result - lifecycleScope.launch { - launchGitOperation(GitOp.RESET) - .fold( - success = ::finishOnSuccessHandler, - failure = { err -> promptOnErrorHandler(err) { finish() } }, - ) - } + } + + private fun resetToRemote() { + val dialog = + TextInputDialog.newInstance(getString(R.string.git_utils_reset_remote_branch_title)) + dialog.show(supportFragmentManager, "BRANCH_INPUT_DIALOG") + dialog.setFragmentResultListener(TextInputDialog.REQUEST_KEY) { _, bundle -> + val result = bundle.getString(TextInputDialog.BUNDLE_KEY_TEXT) + if (!result.isNullOrEmpty()) { + remoteBranch = result + lifecycleScope.launch { + launchGitOperation(GitOp.RESET) + .fold( + success = ::finishOnSuccessHandler, + failure = { err -> promptOnErrorHandler(err) { finish() } }, + ) } } } - binding.gitGc.setOnClickListener { - lifecycleScope.launch { - launchGitOperation(GitOp.GC) - .fold( - success = ::finishOnSuccessHandler, - failure = { err -> promptOnErrorHandler(err) { finish() } }, - ) - } + } + + private fun abortRebase() { + lifecycleScope.launch { + launchGitOperation(GitOp.BREAK_OUT_OF_DETACHED) + .fold( + success = { + val branch = PasswordRepository.getCurrentBranch() + 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, + branch, + "conflicting-$branch-...", + ) + ) + setOnDismissListener { finish() } + setPositiveButton(resources.getString(R.string.dialog_ok)) { _, _ -> } + show() + } + }, + failure = { err -> promptOnErrorHandler(err) { finish() } }, + ) } } |