From c62e1303b1258728fb7ac7e11053e39b3736aa96 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 5 Sep 2020 20:32:33 +0530 Subject: AutofillScenario: use runCatching to replace exception handling Signed-off-by: Harsh Shandilya --- .../java/com/zeapo/pwdstore/autofill/oreo/AutofillScenario.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillScenario.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillScenario.kt index daa2db45..f4fd5cf1 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillScenario.kt +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillScenario.kt @@ -12,6 +12,8 @@ import android.view.autofill.AutofillId import android.view.autofill.AutofillValue import androidx.annotation.RequiresApi import com.github.ajalt.timberkt.e +import com.github.michaelbull.result.getOrElse +import com.github.michaelbull.result.runCatching enum class AutofillAction { Match, Search, Generate, FillOtpFromSms @@ -36,7 +38,7 @@ sealed class AutofillScenario { const val BUNDLE_KEY_GENERIC_PASSWORD_IDS = "genericPasswordIds" fun fromBundle(clientState: Bundle): AutofillScenario? { - return try { + return runCatching { Builder().apply { username = clientState.getParcelable(BUNDLE_KEY_USERNAME_ID) fillUsername = clientState.getBoolean(BUNDLE_KEY_FILL_USERNAME) @@ -57,8 +59,8 @@ sealed class AutofillScenario { ) ?: emptyList() ) }.build() - } catch (exception: IllegalArgumentException) { - e(exception) + }.getOrElse { e -> + e(e) null } } -- cgit v1.2.3