Skip to content

Instantly share code, notes, and snippets.

View peterpazmandi's full-sized avatar
🤖
Working on android stuff

Peter Pazmandi peterpazmandi

🤖
Working on android stuff
  • Zalaegerszeg, Hungary
  • 00:12 (UTC +02:00)
View GitHub Profile
@stevdza-san
stevdza-san / DataStoreRepository.kt
Last active December 26, 2024 21:41
Preferences DataStore - YouTube Tutorial | https://youtu.be/hEHVn9ATVjY
const val PREFERENCE_NAME = "my_preference"
class DataStoreRepository(context: Context) {
private object PreferenceKeys {
val name = preferencesKey<String>("my_name")
}
private val dataStore: DataStore<Preferences> = context.createDataStore(
name = PREFERENCE_NAME
//1 .- We use callbackFlow , this is like channelFlow and will propagate our data to our viewmodel
override suspend fun getVersionCodeRepo(): Flow<Resource<Int>> = callbackFlow {
// 2.- We create a reference to our data inside Firestore
val eventDocument = FirebaseFirestore
.getInstance()
.collection("params")
.document("app")
// 3.- We generate a subscription that is going to let us listen for changes with