Created
February 22, 2023 22:27
-
-
Save ademirqueiroga/5c28155af7d2fecd3245b37a4ea9da9f to your computer and use it in GitHub Desktop.
Handling channel/program intent
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
fun handleIntent(intent: Intent) { | |
val intentAction = intent.action | |
if (intentAction == Intent.ACTION_VIEW) { | |
val intentData = intent.data | |
val pathSegments = intentData?.pathSegments ?: emptyList() | |
when (pathSegments.firstOrNull()) { | |
"movie" -> pathSegments.get(1)?.let { movieId -> | |
val movie = MovieList.list.firstOrNull { it.id.toString() == movieId } | |
if (movie != null) { | |
val movieIntent = Intent(context, PlaybackActivity::class.java) | |
movieIntent.putExtra(PlaybackVideoFragment.MOVIE, movie) | |
startActivity(movieIntent) | |
} | |
} | |
"category" -> pathSegments.getOrNull(1)?.let { categoryId -> | |
selectRowForCategory(categoryId) | |
} | |
"discover", null -> { | |
// Just open the app. The user can browse content on the main screen | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment