diff --git a/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/Settings.kt b/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/Settings.kt index ef8482609ec..2645a94d255 100644 --- a/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/Settings.kt +++ b/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/Settings.kt @@ -613,4 +613,12 @@ interface Settings { fun setLastSelectedSubscriptionFrequency(frequency: SubscriptionFrequency) fun getLastSelectedSubscriptionFrequency(): SubscriptionFrequency? + + // This boolean should be update to false when a user signs in and should be set to + // true once a user signs out and that sign out has been fully handled + // by the app. This field helps make sure the app fully handles signing a user + // out even if they sign out from outside the app (i.e., from the Android OS's + // account management settings). + fun setFullySignedOut(boolean: Boolean) + fun getFullySignedOut(): Boolean } diff --git a/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/SettingsImpl.kt b/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/SettingsImpl.kt index 6b88458bea7..dfbb88c41d1 100644 --- a/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/SettingsImpl.kt +++ b/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/SettingsImpl.kt @@ -64,6 +64,7 @@ class SettingsImpl @Inject constructor( private const val CUSTOM_MEDIA_ACTIONS_VISIBLE_KEY = "CustomMediaActionsVisibleKey" private const val LAST_SELECTED_SUBSCRIPTION_TIER_KEY = "LastSelectedSubscriptionTierKey" private const val LAST_SELECTED_SUBSCRIPTION_FREQUENCY_KEY = "LastSelectedSubscriptionFrequencyKey" + private const val PROCESSED_SIGNOUT_KEY = "ProcessedSignout" } private var languageCode: String? = null @@ -1402,4 +1403,11 @@ class SettingsImpl @Inject constructor( getString(LAST_SELECTED_SUBSCRIPTION_FREQUENCY_KEY)?.let { SubscriptionFrequency.valueOf(it) } + + override fun setFullySignedOut(boolean: Boolean) { + setBoolean(PROCESSED_SIGNOUT_KEY, boolean) + } + + override fun getFullySignedOut(): Boolean = + getBoolean(PROCESSED_SIGNOUT_KEY, true) } diff --git a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/sync/SyncManagerImpl.kt b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/sync/SyncManagerImpl.kt index 346e9250344..a0eb9907375 100644 --- a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/sync/SyncManagerImpl.kt +++ b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/sync/SyncManagerImpl.kt @@ -188,6 +188,9 @@ class SyncManagerImpl @Inject constructor( val loginResult = try { val response = loginFunction() val result = handleTokenResponse(loginIdentity = loginIdentity, response = response) + + settings.setFullySignedOut(false) + LoginResult.Success(result) } catch (ex: Exception) { Timber.e(ex, "Failed to sign in with Pocket Casts") diff --git a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/user/UserManager.kt b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/user/UserManager.kt index 629aa9a122a..b44ce792d70 100644 --- a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/user/UserManager.kt +++ b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/user/UserManager.kt @@ -91,28 +91,27 @@ class UserManagerImpl @Inject constructor( @OptIn(DelicateCoroutinesApi::class) override fun signOut(playbackManager: PlaybackManager, wasInitiatedByUser: Boolean) { - val wasSignedIn = syncManager.isLoggedIn() - - LogBuffer.i(LogBuffer.TAG_BACKGROUND_TASKS, "Signing out") - subscriptionManager.clearCachedStatus() - syncManager.signOut { - settings.clearPlusPreferences() - GlobalScope.launch { - userEpisodeManager.removeCloudStatusFromFiles(playbackManager) - } + if (wasInitiatedByUser || !settings.getFullySignedOut()) { + LogBuffer.i(LogBuffer.TAG_BACKGROUND_TASKS, "Signing out") + subscriptionManager.clearCachedStatus() + syncManager.signOut { + settings.clearPlusPreferences() + GlobalScope.launch { + userEpisodeManager.removeCloudStatusFromFiles(playbackManager) + } - settings.setMarketingOptIn(false) - settings.setMarketingOptInNeedsSync(false) - settings.setEndOfYearModalHasBeenShown(false) - if (wasSignedIn) { + settings.setMarketingOptIn(false) + settings.setMarketingOptInNeedsSync(false) + settings.setEndOfYearModalHasBeenShown(false) analyticsTracker.track( AnalyticsEvent.USER_SIGNED_OUT, mapOf(KEY_USER_INITIATED to wasInitiatedByUser) ) + analyticsTracker.flush() + analyticsTracker.clearAllData() + analyticsTracker.refreshMetadata() } - analyticsTracker.flush() - analyticsTracker.clearAllData() - analyticsTracker.refreshMetadata() } + settings.setFullySignedOut(true) } }