-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add watch settings screen with metered data warning #860
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:pathData="M9.793,7.293C10.183,6.902 10.817,6.902 11.207,7.293L15.207,11.293L15.914,12L15.207,12.707L11.207,16.707C10.817,17.098 10.183,17.098 9.793,16.707C9.402,16.317 9.402,15.683 9.793,15.293L12.086,13H3C2.448,13 2,12.552 2,12C2,11.448 2.448,11 3,11H12.086L9.793,8.707C9.402,8.317 9.402,7.683 9.793,7.293Z" | ||
android:fillColor="#000000" | ||
android:fillType="evenOdd"/> | ||
<path | ||
android:pathData="M6,5C6,3.895 6.895,3 8,3H17C18.105,3 19,3.895 19,5V19C19,20.105 18.105,21 17,21H8C6.895,21 6,20.105 6,19V18C6,17.448 6.448,17 7,17C7.552,17 8,17.448 8,18V19H17V5H8V6C8,6.552 7.552,7 7,7C6.448,7 6,6.552 6,6V5Z" | ||
android:strokeAlpha="0.5" | ||
android:fillColor="#000000" | ||
android:fillType="evenOdd" | ||
android:fillAlpha="0.5"/> | ||
</vector> |
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
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 |
---|---|---|
|
@@ -4,22 +4,29 @@ import android.os.Bundle | |
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.ui.tooling.preview.Devices | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import androidx.navigation.NavType | ||
import androidx.navigation.navArgument | ||
import androidx.wear.compose.navigation.rememberSwipeDismissableNavController | ||
import au.com.shiftyjelly.pocketcasts.ui.theme.Theme | ||
import au.com.shiftyjelly.pocketcasts.wear.theme.WearAppTheme | ||
import au.com.shiftyjelly.pocketcasts.wear.ui.FilesScreen | ||
import au.com.shiftyjelly.pocketcasts.wear.ui.FiltersScreen | ||
import au.com.shiftyjelly.pocketcasts.wear.ui.SettingsScreen | ||
import au.com.shiftyjelly.pocketcasts.wear.ui.UpNextScreen | ||
import au.com.shiftyjelly.pocketcasts.wear.ui.WatchListScreen | ||
import au.com.shiftyjelly.pocketcasts.wear.ui.authenticationGraph | ||
import au.com.shiftyjelly.pocketcasts.wear.ui.authenticationSubGraph | ||
import au.com.shiftyjelly.pocketcasts.wear.ui.downloads.DownloadsScreen | ||
import au.com.shiftyjelly.pocketcasts.wear.ui.episode.EpisodeScreenFlow | ||
import au.com.shiftyjelly.pocketcasts.wear.ui.episode.EpisodeScreenFlow.episodeGraph | ||
import au.com.shiftyjelly.pocketcasts.wear.ui.player.NowPlayingScreen | ||
import au.com.shiftyjelly.pocketcasts.wear.ui.player.NowPlayingViewModel | ||
import au.com.shiftyjelly.pocketcasts.wear.ui.player.StreamingConfirmationScreen | ||
import au.com.shiftyjelly.pocketcasts.wear.ui.podcast.PodcastScreen | ||
import au.com.shiftyjelly.pocketcasts.wear.ui.podcasts.PodcastsScreen | ||
import com.google.android.horologist.compose.navscaffold.NavScaffoldViewModel | ||
|
@@ -59,12 +66,41 @@ fun WearApp(themeType: Theme.ThemeType) { | |
WatchListScreen(navController::navigate, it.scrollableState) | ||
} | ||
|
||
composable(NowPlayingScreen.route) { viewModel -> | ||
viewModel.timeTextMode = NavScaffoldViewModel.TimeTextMode.Off | ||
composable(NowPlayingScreen.route) { | ||
it.timeTextMode = NavScaffoldViewModel.TimeTextMode.Off | ||
|
||
// Listen for results from streaming confirmation screen | ||
navController.currentBackStackEntry?.savedStateHandle | ||
?.getStateFlow<StreamingConfirmationScreen.Result?>(StreamingConfirmationScreen.resultKey, null) | ||
?.collectAsStateWithLifecycle()?.value?.let { streamingConfirmationResult -> | ||
val viewModel = hiltViewModel<NowPlayingViewModel>() | ||
LaunchedEffect(streamingConfirmationResult) { | ||
viewModel.onStreamingConfirmationResult(streamingConfirmationResult) | ||
// Clear result once consumed | ||
navController.currentBackStackEntry?.savedStateHandle | ||
?.remove<StreamingConfirmationScreen.Result?>(StreamingConfirmationScreen.resultKey) | ||
} | ||
} | ||
|
||
NowPlayingScreen( | ||
navigateToEpisode = { episodeUuid -> | ||
navController.navigate(EpisodeScreenFlow.navigateRoute(episodeUuid)) | ||
}, | ||
showStreamingConfirmation = { navController.navigate(StreamingConfirmationScreen.route) }, | ||
) | ||
} | ||
|
||
composable(StreamingConfirmationScreen.route) { | ||
it.timeTextMode = NavScaffoldViewModel.TimeTextMode.Off | ||
|
||
StreamingConfirmationScreen( | ||
onFinished = { result -> | ||
navController.previousBackStackEntry?.savedStateHandle?.set( | ||
StreamingConfirmationScreen.resultKey, | ||
result | ||
) | ||
Comment on lines
+98
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is passing the result of what the user selected back to the previous screen. |
||
navController.popBackStack() | ||
}, | ||
) | ||
} | ||
|
||
|
@@ -126,6 +162,13 @@ fun WearApp(themeType: Theme.ThemeType) { | |
|
||
composable(FilesScreen.route) { FilesScreen() } | ||
|
||
scrollable(SettingsScreen.route) { | ||
SettingsScreen( | ||
scrollState = it.columnState, | ||
signInClick = { navController.navigate(authenticationSubGraph) }, | ||
) | ||
} | ||
|
||
authenticationGraph(navController) | ||
} | ||
} | ||
|
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
180 changes: 180 additions & 0 deletions
180
wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/ui/SettingsScreen.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,180 @@ | ||
package au.com.shiftyjelly.pocketcasts.wear.ui | ||
|
||
import android.content.res.Configuration | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.wear.compose.material.Icon | ||
import androidx.wear.compose.material.MaterialTheme | ||
import androidx.wear.compose.material.Text | ||
import androidx.wear.compose.material.ToggleChip | ||
import androidx.wear.compose.material.ToggleChipDefaults | ||
import au.com.shiftyjelly.pocketcasts.models.to.SignInState | ||
import au.com.shiftyjelly.pocketcasts.models.to.SubscriptionStatus | ||
import au.com.shiftyjelly.pocketcasts.ui.theme.Theme | ||
import au.com.shiftyjelly.pocketcasts.wear.theme.WearAppTheme | ||
import au.com.shiftyjelly.pocketcasts.wear.theme.theme | ||
import au.com.shiftyjelly.pocketcasts.wear.ui.component.ChipScreenHeader | ||
import au.com.shiftyjelly.pocketcasts.wear.ui.component.ChipSectionHeader | ||
import au.com.shiftyjelly.pocketcasts.wear.ui.component.WatchListChip | ||
import com.google.android.horologist.compose.layout.ScalingLazyColumn | ||
import com.google.android.horologist.compose.layout.ScalingLazyColumnState | ||
import au.com.shiftyjelly.pocketcasts.images.R as IR | ||
import au.com.shiftyjelly.pocketcasts.localization.R as LR | ||
|
||
object SettingsScreen { | ||
const val route = "settings_screen" | ||
} | ||
|
||
@Composable | ||
fun SettingsScreen( | ||
scrollState: ScalingLazyColumnState, | ||
signInClick: () -> Unit, | ||
) { | ||
|
||
val viewModel = hiltViewModel<SettingsViewModel>() | ||
val state by viewModel.state.collectAsState() | ||
|
||
Content( | ||
scrollState = scrollState, | ||
state = state, | ||
onWarnOnMeteredChanged = { viewModel.setWarnOnMeteredNetwork(it) }, | ||
signInClick = signInClick, | ||
onSignOutClicked = viewModel::signOut, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun Content( | ||
scrollState: ScalingLazyColumnState, | ||
state: SettingsViewModel.State, | ||
onWarnOnMeteredChanged: (Boolean) -> Unit, | ||
signInClick: () -> Unit, | ||
onSignOutClicked: () -> Unit, | ||
) { | ||
ScalingLazyColumn(columnState = scrollState) { | ||
|
||
item { | ||
ChipScreenHeader(LR.string.settings) | ||
} | ||
|
||
item { | ||
ToggleChip( | ||
label = stringResource(LR.string.settings_metered_data_warning), | ||
checked = state.showDataWarning, | ||
onCheckedChanged = onWarnOnMeteredChanged, | ||
) | ||
} | ||
|
||
item { | ||
ChipSectionHeader(LR.string.account) | ||
} | ||
|
||
item { | ||
val signInState = state.signInState | ||
when (signInState) { | ||
is SignInState.SignedIn -> { | ||
WatchListChip( | ||
titleRes = LR.string.log_out, | ||
secondaryLabel = signInState.email, | ||
iconRes = IR.drawable.ic_signout, | ||
onClick = onSignOutClicked, | ||
) | ||
} | ||
is SignInState.SignedOut -> { | ||
WatchListChip( | ||
titleRes = LR.string.log_in, | ||
iconRes = IR.drawable.signin, | ||
onClick = signInClick, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun ToggleChip( | ||
label: String, | ||
checked: Boolean, | ||
onCheckedChanged: (Boolean) -> Unit, | ||
) { | ||
val color = MaterialTheme.theme.colors.support05 | ||
ToggleChip( | ||
checked = checked, | ||
onCheckedChange = { onCheckedChanged(it) }, | ||
label = { | ||
Text( | ||
text = label, | ||
style = MaterialTheme.typography.button, | ||
) | ||
}, | ||
toggleControl = { | ||
Icon( | ||
imageVector = ToggleChipDefaults.switchIcon(checked), | ||
contentDescription = stringResource(if (checked) LR.string.on else LR.string.off), | ||
modifier = Modifier | ||
) | ||
}, | ||
colors = ToggleChipDefaults.toggleChipColors( | ||
checkedEndBackgroundColor = color.copy(alpha = 0.32f), | ||
checkedToggleControlColor = color, | ||
), | ||
modifier = Modifier.fillMaxWidth() | ||
) | ||
} | ||
|
||
@Preview( | ||
widthDp = 200, | ||
heightDp = 200, | ||
uiMode = Configuration.UI_MODE_TYPE_WATCH, | ||
) | ||
@Composable | ||
private fun SettingsScreenPreview_unchecked() { | ||
WearAppTheme(Theme.ThemeType.DARK) { | ||
Content( | ||
scrollState = ScalingLazyColumnState(), | ||
state = SettingsViewModel.State( | ||
signInState = SignInState.SignedIn( | ||
email = "[email protected]", | ||
subscriptionStatus = SubscriptionStatus.Free(), | ||
), | ||
showDataWarning = false, | ||
), | ||
signInClick = {}, | ||
onWarnOnMeteredChanged = {}, | ||
onSignOutClicked = {} | ||
|
||
) | ||
} | ||
} | ||
|
||
@Preview( | ||
widthDp = 200, | ||
heightDp = 200, | ||
uiMode = Configuration.UI_MODE_TYPE_WATCH, | ||
) | ||
@Composable | ||
private fun SettingsScreenPreview_checked() { | ||
WearAppTheme(Theme.ThemeType.DARK) { | ||
Content( | ||
scrollState = ScalingLazyColumnState(), | ||
state = SettingsViewModel.State( | ||
signInState = SignInState.SignedIn( | ||
email = "[email protected]", | ||
subscriptionStatus = SubscriptionStatus.Free(), | ||
), | ||
showDataWarning = true, | ||
), | ||
signInClick = {}, | ||
onWarnOnMeteredChanged = {}, | ||
onSignOutClicked = {} | ||
|
||
) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love the boilerplate this requires to get a result from the stream warning screen via the savedStateHandle. This seemed like the best solution though since I can't use a shared view model due to the fact that I need different behavior depending on whether the stream warning is showing from the now playing screen or the episode details screen (now playing plays the currently queued episode, epsidoe details queues and plays the currently viewed episode).