-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from avidraghav/improved_error_handling
Improve error handling in the set Reminder flow
- Loading branch information
Showing
7 changed files
with
168 additions
and
129 deletions.
There are no files selected for viewing
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
114 changes: 114 additions & 0 deletions
114
app/src/main/java/com/raghav/spacedawnv2/navigation/SpaceDawnNavHost.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package com.raghav.spacedawnv2.navigation | ||
|
||
import android.app.Activity | ||
import androidx.compose.animation.AnimatedContentTransitionScope | ||
import androidx.compose.material3.SnackbarDuration | ||
import androidx.compose.material3.SnackbarHostState | ||
import androidx.compose.material3.SnackbarResult | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.rememberUpdatedState | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.compose.NavHost | ||
import androidx.navigation.compose.composable | ||
import com.raghav.spacedawnv2.R | ||
import com.raghav.spacedawnv2.launchesscreen.LaunchesScreen | ||
import com.raghav.spacedawnv2.remindersscreen.RemindersScreen | ||
import com.raghav.spacedawnv2.util.Helpers.Companion.navigateSingleTopTo | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
|
||
@Composable | ||
fun SpaceDawnNavHost( | ||
navController: NavHostController, | ||
modifier: Modifier = Modifier, | ||
snackbarHostState: SnackbarHostState, | ||
coroutineScope: CoroutineScope | ||
) { | ||
NavHost( | ||
navController = navController, | ||
startDestination = LaunchesScreen.route, | ||
modifier = modifier | ||
) { | ||
// Launches Screen | ||
composable( | ||
LaunchesScreen.route, | ||
enterTransition = { | ||
slideIntoContainer(AnimatedContentTransitionScope.SlideDirection.Right) | ||
}, | ||
exitTransition = { | ||
slideOutOfContainer(AnimatedContentTransitionScope.SlideDirection.Left) | ||
} | ||
) { | ||
val activity = (LocalContext.current as? Activity) | ||
val actionLabel by rememberUpdatedState( | ||
newValue = stringResource(id = R.string.reminders) | ||
) | ||
LaunchesScreen( | ||
systemBackButtonClicked = { activity?.finish() }, | ||
reminderSetSuccessfully = { | ||
coroutineScope.launch { | ||
val actionTaken = snackbarHostState.showSnackbar( | ||
it, | ||
actionLabel = actionLabel, | ||
withDismissAction = true, | ||
duration = SnackbarDuration.Short | ||
) | ||
when (actionTaken) { | ||
SnackbarResult.ActionPerformed -> { | ||
navController.navigateSingleTopTo(RemindersScreen.route) | ||
} | ||
|
||
else -> {} | ||
} | ||
} | ||
}, | ||
reminderNotSet = { | ||
coroutineScope.launch { | ||
snackbarHostState.showSnackbar( | ||
it, | ||
withDismissAction = true | ||
) | ||
} | ||
} | ||
) | ||
} | ||
// Reminders Screen | ||
composable( | ||
RemindersScreen.route, | ||
enterTransition = { | ||
slideIntoContainer(AnimatedContentTransitionScope.SlideDirection.Left) | ||
}, | ||
exitTransition = { | ||
slideOutOfContainer(AnimatedContentTransitionScope.SlideDirection.Right) | ||
} | ||
) { | ||
val snackBarMessage by rememberUpdatedState( | ||
newValue = stringResource(R.string.reminder_cancelled_successfully) | ||
) | ||
RemindersScreen( | ||
onBackPressed = { navController.navigateSingleTopTo(LaunchesScreen.route) }, | ||
reminderNotCancelled = { message -> | ||
coroutineScope.launch { | ||
snackbarHostState.showSnackbar( | ||
message.toString(), | ||
withDismissAction = true | ||
) | ||
} | ||
}, | ||
reminderCancelled = { | ||
coroutineScope.launch { | ||
snackbarHostState.showSnackbar( | ||
// need to extract to string res | ||
snackBarMessage, | ||
withDismissAction = true | ||
) | ||
} | ||
} | ||
) | ||
} | ||
} | ||
} |
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
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
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
5 changes: 5 additions & 0 deletions
5
domain/src/main/java/com/raghav/spacedawnv2/domain/util/ReminderExceptions.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.raghav.spacedawnv2.domain.util | ||
|
||
class ReminderPermissionException : Exception() | ||
class NotificationPermissionException : Exception() | ||
class ReminderAndNotificationPermissionException : Exception() |
Oops, something went wrong.