Skip to content
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

On Automotive add the option to clear your data before logging in #978

Merged
merged 5 commits into from
May 19, 2023

Conversation

geekygecko
Copy link
Member

Description

For the Automotive app, we have been asked if we can add the option to clear your data before you can log in or create an account. If you have an Up Next, any podcasts or episodes then it will ask you, otherwise the dialog won't be shown to you.

Testing Instructions

  1. Deploy the Automotive version
  2. Tap on the Discover tab
  3. Tap a podcast
  4. Tap on an episode to play it
  5. Close the full screen player with the arrow at the top left
  6. Tap the settings cog
  7. Tap 'Set up account'
  8. ✅ Verify a dialog is shown asking if you want to clear your data
  9. Tap 'Clear data'
  10. Tap close and back to get back to the app
  11. ✅ Verify the mini player has closed
  12. Tap the settings cog
  13. Tap 'Set up account'
  14. ✅ Verify it goes straight to the "Sign in or create account" page and doesn't show the dialog

Screenshots

Screenshot_20230518_170246

*/
private fun isAutoDownloadingAllPodcasts(): Boolean {
return if (countPodcasts() == 0) false else podcastDao.countDownloadStatus(Podcast.AUTO_DOWNLOAD_NEW_EPISODES) == podcastDao.countSubscribed()
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods weren't been used

// if the episode is deleted from the database while playing catch the error and just return an empty state
.onErrorReturn { Optional.empty() }
.toObservable()
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As part of clearing the data when the episode was deleted, it caused the Up Next and playback event monitoring to crash. This meant that after clearing the data it wasn't possible to play another episode. This change fixes that.

@geekygecko geekygecko marked this pull request as ready for review May 18, 2023 07:42
@geekygecko geekygecko requested a review from a team as a code owner May 18, 2023 07:42
Copy link
Contributor

@mchowning mchowning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good. 👍

wasInitiatedByUser: Boolean,
) {
// Sign out first to make sure no data changes get synced
signOut(playbackManager, wasInitiatedByUser = true)
Copy link
Contributor

@mchowning mchowning May 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
signOut(playbackManager, wasInitiatedByUser = true)
signOut(playbackManager, wasInitiatedByUser = wasInitiatedByUser)

Alternatively, if we want this to always be true, we could remove the wasInitiatedByUser parameter from being passed in signOutAndClearData.

folderManager = folderManager,
searchHistoryManager = searchHistoryManager,
episodeManager = episodeManager,
wasInitiatedByUser = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if wasInitiatedByUser should be false here. The user is initiating the action here, but they're not trying to sign out. One of the things this wasInitiatedByUser variable is used for is to identify in our analytics whether the user was attempting to sign out.

Admittedly this is a bit of a moot point at this time since we're not sending any analytics to Tracks from Android Automotive yet.

Also, if you change wasInitiatedByUser to be false, you may need to do something like add a call to settings.setFullySignedOut(false) to get past this if-check in the signOut method.

The settings.getFullySIgnedOut value is a relatively recent addition I did largely to avoid extra signout calls to analytics (we were making a call to signout every time a user who was not signed in started the app). Maybe you have some ideas for how to better accomplish that because it does seem to be creating some undesirable complexity here. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be easier to understand if we named the parameter something like userAttemptingToSignOut. 🤔

I was trying to reuse the same logic but I think I have made it more complicated. Thanks for picking this up, I have committed a fix to set wasInitiatedByUser to false.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be easier to understand if we named the parameter something like userAttemptingToSignOut. 🤔

If that seems like a better name to you I'm certainly not opposed to switching to that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to note explicitly that with this change none of this code is getting run when the user clears data on sign-in:

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)

        analyticsTracker.track(
            AnalyticsEvent.USER_SIGNED_OUT,
            mapOf(KEY_USER_INITIATED to wasInitiatedByUser)
        )
        analyticsTracker.flush()
        analyticsTracker.clearAllData()
        analyticsTracker.refreshMetadata()
    }
}

I think that's probably fine because all those things seem to relate to accounts and obviously the user isn't signed-in in this scenario, but it's worth keeping in mind if we see any issues.

geekygecko and others added 2 commits May 19, 2023 08:08
…/pocketcasts/repositories/user/UserManager.kt

Co-authored-by: Matt Chowning <mchowning@gmail.com>
@geekygecko geekygecko merged commit 76999b4 into main May 19, 2023
8 checks passed
@geekygecko geekygecko deleted the update/automotive-clear-data-login branch May 19, 2023 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants