Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
When Jetpack's Glance met his fellow worker, Work Manager
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