android / android/codelab-android-datastore

Lab refers to an undefined context.createDataStore(...) function

Aperta
#71 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Kotlin
Stelle
240
Fork
113
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

[8. SharedPreferences to Proto DataStore](https://developer.android.com/codelabs/android-proto-datastore#7) is already very chaotic in terms of modifications that ain't clear whether they apply to `UserPreferencesRepository.kt` or to `TasksActivity.kt` or maybe to both.

That's because, in previous steps, the lab mandates to temporarily create a `Context` extension property `userPreferencesStore` that it's also temporarily injected from `TasksActivity` into `UserPreferencesRepository`.

But once at step [8. SharedPreferences to Proto DataStore](https://developer.android.com/codelabs/android-proto-datastore#7), lots of these temporary things become finalized although the lab only tells what to edit but not where.

At some point, it requests to redefine `userPreferencesStore` but this time not as a `Context` extension property but as a presumably `UserPreferencesRepository` property. It doesn't clarify whose this redefinition belongs. I presume that it's `UserPreferencesRepository`.

It doesn't end there, though: the new definition invokes a non-existing `context.createDataStore(...)` function as follows:
```
private val userPreferencesStore: DataStore = context.createDataStore(
fileName = "user_prefs.pb",
serializer = UserPreferencesSerializer,
migrations = listOf(sharedPrefsMigration)
)
```

I could only finish the lab by figuring out the missing extension function as follows:

```
fun Context.createDataStore(
fileName: String,
serializer: Serializer,
corruptionHandler: ReplaceFileCorruptionHandler? = null,
migrations: List> = listOf(),
scope: CoroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
): DataStore =
DataStoreFactory.create(
produceFile = { File(this.filesDir, "datastore/$fileName") },
serializer = serializer,
corruptionHandler = corruptionHandler,
migrations = migrations,
scope = scope
)
```

If my guessing is correct, the lab should include my guessed definition for God's sake.

The provided finished branch `proto_datastore` just stuck to the temporary definition (contradicting the lab instructions that called for a redefinition.)

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia confrontando il passaggio 8 del codelab SharedPreferences to Proto DataStore con UserPreferencesRepository.kt, TasksActivity.kt e il branch proto_datastore. Verifica dove deve trovarsi userPreferencesStore e se context.createDataStore è definito o previsto; il lavoro è completo quando le istruzioni e il branch completato identificano in modo coerente la responsabilità e forniscono ogni definizione necessaria.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
android, kotlin
Ambito
documentation, mobile
Tipo di issue
Documentazione
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.