Skip to content

Commit

Permalink
[#3954] Update resolveAndStartIntent with more error prone approach
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaozhan committed Sep 16, 2024
1 parent b90e9ad commit 32d2801
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package com.oztechan.ccc.android.ui.mobile.util

import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import co.touchlab.kermit.Logger

@Suppress("TooGenericExceptionCaught")
fun Context.resolveAndStartIntent(intent: Intent) {
intent.resolveActivity(packageManager)?.let {
startActivity(intent)
} ?: Exception("No activity found to handle the intent: $intent").let {
try {
intent.resolveActivity(packageManager)?.let {
startActivity(intent)
null
} ?: Exception("No activity found to handle the intent: $intent")

Check warning on line 14 in android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/util/IntentUtil.kt

View check run for this annotation

Codecov / codecov/patch

android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/util/IntentUtil.kt#L12-L14

Added lines #L12 - L14 were not covered by tests
} catch (e: ActivityNotFoundException) {
Exception("Unable to open link", e)

Check warning on line 16 in android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/util/IntentUtil.kt

View check run for this annotation

Codecov / codecov/patch

android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/util/IntentUtil.kt#L16

Added line #L16 was not covered by tests
} catch (e: Exception) {
Exception("An error occurred", e)
}.let {

Check warning on line 19 in android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/util/IntentUtil.kt

View check run for this annotation

Codecov / codecov/patch

android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/util/IntentUtil.kt#L18-L19

Added lines #L18 - L19 were not covered by tests
Logger.e(it) { it.message.orEmpty() }
}
}

0 comments on commit 32d2801

Please sign in to comment.