Skip to content

Instantly share code, notes, and snippets.

View igorescodro's full-sized avatar
♥️
Coding with love

Igor Escodro igorescodro

♥️
Coding with love
View GitHub Profile
NavDeepLinkBuilder(context)
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.taskDetailFragment)
.setArguments(arguments)
.createPendingIntent()
@Composable
fun NavGraph(startDestination: String = "home") {
val navController = rememberNavController()
NavHost(navController = navController, startDestination = startDestination) {
composable(route = "home") {
Home()
}
composable(
@Composable
fun NavGraph(startDestination: String = "home") {
val navController = rememberNavController()
val uri = "https://example.com"
NavHost(navController = navController, startDestination = startDestination) {
composable(
route = "task_detail/{task_id}",
arguments = listOf(navArgument("task_id") { type = NavType.LongType }),
deepLinks = listOf(navDeepLink { uriPattern = "$uri/task_id={task_id}" })
val taskDetailIntent = Intent(
Intent.ACTION_VIEW,
"https://example.com/task_id=${task.id}".toUri(),
context,
MainActivity::class.java
)
val pending: PendingIntent = TaskStackBuilder.create(context).run {
addNextIntentWithParentStack(taskDetailIntent)
getPendingIntent(REQUEST_CODE, PendingIntent.FLAG_UPDATE_CURRENT)
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="example.com"
android:scheme="https" />
</intent-filter>
val taskDetailIntent = Intent(
Intent.ACTION_VIEW,
"https://example.com/task_id=${task.id}".toUri()
)
val pending: PendingIntent = TaskStackBuilder.create(context).run {
addNextIntentWithParentStack(taskDetailIntent)
getPendingIntent(REQUEST_CODE, PendingIntent.FLAG_UPDATE_CURRENT)
}
@Composable
fun SnackbarSample() {
val snackbarHostState = remember { SnackbarHostState() }
val coroutineScope = rememberCoroutineScope()
val modifier = Modifier
Box(modifier.fillMaxSize()) {
Button(onClick = {
coroutineScope.launch {
snackbarHostState.showSnackbar(message = "This is a Snackbar")
@Composable
fun HomeList(taskViewModel: ListViewModel = viewModel()) {
Scaffold {
val list by remember(taskViewModel) {
taskViewModel.taskList
}.collectAsState()
LazyColumn {
items(
items = list,
@Composable
fun HomeList(taskViewModel: ListViewModel = viewModel()) {
val coroutineScope = rememberCoroutineScope()
val scaffoldState = rememberScaffoldState()
val onShowSnackbar: (Task) -> Unit = { task ->
coroutineScope.launch {
val snackbarResult = scaffoldState.snackbarHostState.showSnackbar(
message = "${task.title} completed",
actionLabel = "Undo"
Scaffold(scaffoldState = scaffoldState) {
...
ListItem(
task = task,
onCheckedChange = { task ->
taskViewModel.onCheckedChange(task)
onShowSnackbar(task)
}
)
}