-
Notifications
You must be signed in to change notification settings - Fork 305
[TV] Return to the welcome screen after signing out #5744
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
Changes from 2 commits
6f2e127
54a38f4
a204675
f7ef258
1aca2da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,6 @@ fun TvOnboardingNavHost( | |
| onSignIn = { navController.navigate(TvOnboardingRoutes.SIGN_IN) }, | ||
| onCreateAccount = { navController.navigate(TvOnboardingRoutes.CREATE_ACCOUNT) }, | ||
| onContinueWithoutAccount = { | ||
| viewModel.completeOnboarding() | ||
| navController.navigate(TvOnboardingRoutes.HOME) { | ||
| popUpTo(TvOnboardingRoutes.LANDING) { inclusive = true } | ||
| } | ||
|
|
@@ -65,7 +64,6 @@ fun TvOnboardingNavHost( | |
| composable(TvOnboardingRoutes.SYNCING) { | ||
| TvSyncingScreen( | ||
| onSyncComplete = { | ||
| viewModel.completeOnboarding() | ||
| navController.navigate(TvOnboardingRoutes.HOME) { | ||
| popUpTo(TvOnboardingRoutes.SYNCING) { inclusive = true } | ||
| } | ||
|
|
@@ -76,6 +74,11 @@ fun TvOnboardingNavHost( | |
| TvScaffold( | ||
| onLogIn = { navController.navigate(TvOnboardingRoutes.SIGN_IN) }, | ||
| onCreateAccount = { navController.navigate(TvOnboardingRoutes.CREATE_ACCOUNT) }, | ||
| onSignedOut = { | ||
| navController.navigate(TvOnboardingRoutes.LANDING) { | ||
| popUpTo(navController.graph.id) { inclusive = true } | ||
| } | ||
| }, | ||
|
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. The pop-whole-graph pattern is correct here (the start destination can be val navigateClearingBackStack: (String) -> Unit = { route ->
navController.navigate(route) {
popUpTo(navController.graph.id) { inclusive = true }
}
}Nit only — no behavioural change requested. One thing to be aware of for testing step 4: |
||
| ) | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,21 +1,17 @@ | ||||||
| package au.com.shiftyjelly.pocketcasts.onboarding | ||||||
|
|
||||||
| import androidx.lifecycle.ViewModel | ||||||
| import au.com.shiftyjelly.pocketcasts.preferences.Settings | ||||||
| import au.com.shiftyjelly.pocketcasts.repositories.sync.SyncManager | ||||||
| import dagger.hilt.android.lifecycle.HiltViewModel | ||||||
| import javax.inject.Inject | ||||||
|
|
||||||
| @HiltViewModel | ||||||
| class TvOnboardingViewModel @Inject constructor( | ||||||
| private val settings: Settings, | ||||||
| syncManager: SyncManager, | ||||||
| ) : ViewModel() { | ||||||
| val startDestination: String = if (settings.hasCompletedOnboarding()) { | ||||||
| val startDestination: String = if (syncManager.isLoggedIn()) { | ||||||
|
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. A failed/partial sign-out now strands the user in an empty Home instead of self-healing to Welcome. The account removal is asynchronous and can fail independently of the data wipe:
Under the old gate this was self-correcting:
Suggested change
(requires keeping the |
||||||
| TvOnboardingRoutes.HOME | ||||||
| } else { | ||||||
| TvOnboardingRoutes.LANDING | ||||||
| } | ||||||
|
|
||||||
| fun completeOnboarding() { | ||||||
| settings.setHasDoneInitialOnboarding() | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,26 @@ | ||
| package au.com.shiftyjelly.pocketcasts.onboarding | ||
|
|
||
| import au.com.shiftyjelly.pocketcasts.preferences.Settings | ||
| import au.com.shiftyjelly.pocketcasts.repositories.sync.SyncManager | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Test | ||
| import org.mockito.kotlin.mock | ||
| import org.mockito.kotlin.verify | ||
| import org.mockito.kotlin.whenever | ||
|
|
||
| class TvOnboardingViewModelTest { | ||
|
|
||
| private val settings = mock<Settings>() | ||
| private val syncManager = mock<SyncManager>() | ||
|
|
||
| @Test | ||
| fun `start destination is landing when onboarding not completed`() { | ||
| whenever(settings.hasCompletedOnboarding()).thenReturn(false) | ||
| val viewModel = TvOnboardingViewModel(settings) | ||
| fun `start destination is landing when signed out`() { | ||
| whenever(syncManager.isLoggedIn()).thenReturn(false) | ||
| val viewModel = TvOnboardingViewModel(syncManager) | ||
| assertEquals(TvOnboardingRoutes.LANDING, viewModel.startDestination) | ||
| } | ||
|
|
||
| @Test | ||
| fun `start destination is home when onboarding completed`() { | ||
| whenever(settings.hasCompletedOnboarding()).thenReturn(true) | ||
| val viewModel = TvOnboardingViewModel(settings) | ||
| fun `start destination is home when signed in`() { | ||
| whenever(syncManager.isLoggedIn()).thenReturn(true) | ||
| val viewModel = TvOnboardingViewModel(syncManager) | ||
| assertEquals(TvOnboardingRoutes.HOME, viewModel.startDestination) | ||
| } | ||
|
|
||
| @Test | ||
| fun `complete onboarding persists to settings`() { | ||
| val viewModel = TvOnboardingViewModel(settings) | ||
| viewModel.completeOnboarding() | ||
| verify(settings).setHasDoneInitialOnboarding() | ||
| } | ||
| } |
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.
viewModel.signOut()is fire-and-forget (signOutManager.signOutAndWipeData()just launches on@ApplicationScope), andonSignedOut()fires synchronously right after. Two consequences worth thinking about:Navigation happens before the auth state actually flips.
syncManager.isLoggedIn()/isLoggedInObservableonly becomefalseat the end ofSyncManagerImpl.signOut()(SyncManagerImpl.kt:195). Harmless today becauseTvWelcomeScreendoesn't read login state, but any future screen onLANDINGthat does will see a staleSignedIn.Sign-in can now race the tail of the wipe. The wipe keeps running for up to ~10s+ after this returns and ends with
settings.clearUserPreferences()+tvPreferences.clearAll(). Welcome auto-focuses Sign In, so the user is one click from starting a fresh device-auth flow while the old wipe is still in flight — if the new login lands first, those tail steps clear the new session's preferences. The hazard pre-dates this PR (the profile modal already offered Log In after logout), but dropping the user straight onto the Welcome CTA makes it much easier to hit.If you want to close it, having
TvSignOutManagerexpose the wipeJob/aStateFlow<Boolean>and navigating on completion (with the existing spinner/blocking UI) would be the tighter version.