aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2020-09-05 20:35:24 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2020-09-05 22:49:36 +0530
commitee6fd10ea61e0f4789bc255418993ad59df44b34 (patch)
tree3793da0b7d7e2479c5df7df258011b78c7466b17
parent58f28727c168966f2b3386097b91abbbeeac31d7 (diff)
GitOperation: use runCatching to replace exception handling
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/operation/GitOperation.kt13
1 files changed, 7 insertions, 6 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/operation/GitOperation.kt b/app/src/main/java/com/zeapo/pwdstore/git/operation/GitOperation.kt
index 32a94d73..ad6a3e29 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/operation/GitOperation.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/operation/GitOperation.kt
@@ -7,9 +7,12 @@ package com.zeapo.pwdstore.git.operation
import android.content.Intent
import android.widget.Toast
import androidx.fragment.app.FragmentActivity
+import com.github.ajalt.timberkt.e
import com.github.michaelbull.result.Err
import com.github.michaelbull.result.Ok
import com.github.michaelbull.result.Result
+import com.github.michaelbull.result.onFailure
+import com.github.michaelbull.result.runCatching
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.R
import com.zeapo.pwdstore.UserPreference
@@ -86,15 +89,13 @@ abstract class GitOperation(protected val callingActivity: FragmentActivity) {
}
private fun getSshKey(make: Boolean) {
- try {
+ runCatching {
// Ask the UserPreference to provide us with the ssh-key
- // onResult has to be handled by the callingActivity
val intent = Intent(callingActivity.applicationContext, UserPreference::class.java)
intent.putExtra("operation", if (make) "make_ssh_key" else "get_ssh_key")
- callingActivity.startActivityForResult(intent, GET_SSH_KEY_FROM_CLONE)
- } catch (e: Exception) {
- println("Exception caught :(")
- e.printStackTrace()
+ callingActivity.startActivity(intent)
+ }.onFailure { e ->
+ e(e)
}
}