Created
June 5, 2024 20:36
-
-
Save MkhytarMkhoian/2881ce23588b9d44263726790f14d68b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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