Checking for New Photos

Now that your worker is executing, you can add the logic to check for new photos. There are a couple pieces needed for this functionality. You will first need a way to save the ID of the most recent photo the user has seen, then you will need to update your worker class to pull the new photos and compare the stored ID with the newest one from the server.

The first change you will make is to update PreferencesRepository to store and retrieve the latest photo ID from shared preferences.

Listing 22.5  Saving the latest photo ID (PreferencesRepository.kt)

class PreferencesRepository private constructor( private val dataStore: DataStore<Preferences> ) { ... suspend fun setStoredQuery(query: String) { dataStore.edit ...

Get Android Programming: The Big Nerd Ranch Guide, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.