From ee6fd10ea61e0f4789bc255418993ad59df44b34 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 5 Sep 2020 20:35:24 +0530 Subject: [PATCH] GitOperation: use runCatching to replace exception handling Signed-off-by: Harsh Shandilya --- .../zeapo/pwdstore/git/operation/GitOperation.kt | 13 +++++++------ 1 file 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) } }