Skip to content

Instantly share code, notes, and snippets.

@MkhytarMkhoian
Created June 5, 2024 20:36
Show Gist options
  • Save MkhytarMkhoian/2881ce23588b9d44263726790f14d68b to your computer and use it in GitHub Desktop.
Save MkhytarMkhoian/2881ce23588b9d44263726790f14d68b to your computer and use it in GitHub Desktop.
class MainActivityViewModel(
exceptionHandler: ExceptionHandler,
private val getDeeplinkUseCase: GetDeeplinkUseCase,
) : ViewModel(), ContainerHost<MainActivityState, MainActivityEffect> {
/* ... */
fun handleIntent(intent: Intent?) = intent {
if (intent == null) return@intent
val uri = getDeepLinkFromIntent(intent)
if (uri.isNullOrEmpty()) return@intent
executeUseCase { getDeeplinkUseCase(uri) }
.onSuccess { deeplink -> postSideEffect(MainActivityEffect.NavigateDeepLink(deeplink)) }
.onFailure { postSideEffect(MainActivityEffect.ShowGenericError) }
}
private fun getDeepLinkFromIntent(intent: Intent): String? {
return intent.takeIf {
Intent.ACTION_VIEW == it.action || Intent.ACTION_MAIN == it.action
}?.dataString
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment