Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Oztechan/CCC#3954] Update resolveAndStartIntent with more error prone approach #3955

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() }
}
}