-
Notifications
You must be signed in to change notification settings - Fork 304
[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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -2,20 +2,18 @@ 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, | ||
| settings: Settings, | ||
| ) : ViewModel() { | ||
| val startDestination: String = if (settings.hasCompletedOnboarding()) { | ||
| val startDestination: String = if (syncManager.isLoggedIn() && !settings.getFullySignedOut()) { | ||
|
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. Interrupting the first sync now permanently skips it. This is the one case where dropping The old flag was set after So:
And nothing else heals it: Under the old gate this interruption was also wrong (Welcome shown to a logged-in user) but it self-healed — signing in again re-ran the sync. The new gate turns a recoverable state into a stuck one. Two ways out, either is fine:
|
||
| TvOnboardingRoutes.HOME | ||
| } else { | ||
| TvOnboardingRoutes.LANDING | ||
| } | ||
|
|
||
| fun completeOnboarding() { | ||
| settings.setHasDoneInitialOnboarding() | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,37 @@ | ||
| 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 syncManager = mock<SyncManager>() | ||
| private val settings = mock<Settings>() | ||
|
|
||
| @Test | ||
| fun `start destination is landing when onboarding not completed`() { | ||
| whenever(settings.hasCompletedOnboarding()).thenReturn(false) | ||
| val viewModel = TvOnboardingViewModel(settings) | ||
| assertEquals(TvOnboardingRoutes.LANDING, viewModel.startDestination) | ||
| fun `start destination is landing when signed out`() { | ||
| whenever(syncManager.isLoggedIn()).thenReturn(false) | ||
| whenever(settings.getFullySignedOut()).thenReturn(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. Nit: this stub is dead. |
||
| assertEquals(TvOnboardingRoutes.LANDING, viewModel().startDestination) | ||
| } | ||
|
|
||
| @Test | ||
| fun `start destination is home when onboarding completed`() { | ||
| whenever(settings.hasCompletedOnboarding()).thenReturn(true) | ||
| val viewModel = TvOnboardingViewModel(settings) | ||
| assertEquals(TvOnboardingRoutes.HOME, viewModel.startDestination) | ||
| fun `start destination is home when signed in and not fully signed out`() { | ||
| whenever(syncManager.isLoggedIn()).thenReturn(true) | ||
| whenever(settings.getFullySignedOut()).thenReturn(false) | ||
| assertEquals(TvOnboardingRoutes.HOME, viewModel().startDestination) | ||
| } | ||
|
|
||
| @Test | ||
| fun `complete onboarding persists to settings`() { | ||
| val viewModel = TvOnboardingViewModel(settings) | ||
| viewModel.completeOnboarding() | ||
| verify(settings).setHasDoneInitialOnboarding() | ||
| fun `start destination is landing when logged in but sign-out is pending`() { | ||
| whenever(syncManager.isLoggedIn()).thenReturn(true) | ||
| whenever(settings.getFullySignedOut()).thenReturn(true) | ||
| assertEquals(TvOnboardingRoutes.LANDING, viewModel().startDestination) | ||
| } | ||
|
|
||
| private fun viewModel() = TvOnboardingViewModel(syncManager, settings) | ||
| } | ||
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.