-
-
Save kasem-sm/19fb18894e004cbb12d6ac18e61c8461 to your computer and use it in GitHub Desktop.
When Jetpack's Glance met his fellow worker, Work Manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object CustomGlanceStateDefinition : GlanceStateDefinition<Preferences> { | |
override suspend fun getDataStore(context: Context, fileKey: String): DataStore<Preferences> { | |
return context.dataStore | |
} | |
override fun getLocation(context: Context, fileKey: String): File { | |
// Note: The Datastore Preference file resides is in the context.applicationContext.filesDir + "datastore/" | |
return File(context.applicationContext.filesDir, "datastore/$fileName") | |
} | |
private const val fileName = "widget_store" | |
private val Context.dataStore: DataStore<Preferences> | |
by preferencesDataStore(name = fileName) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment