Skip to content

Instantly share code, notes, and snippets.

@kasem-sm
Last active May 30, 2022 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasem-sm/19fb18894e004cbb12d6ac18e61c8461 to your computer and use it in GitHub Desktop.
Save kasem-sm/19fb18894e004cbb12d6ac18e61c8461 to your computer and use it in GitHub Desktop.
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