Fix and add some example code in docs.
Relnote: N/A
Bug: 180493647
Test: N/A
Change-Id: Idee90a324703a86f1f086cb6492c5b9cbd0f525a
diff --git a/datastore/datastore-preferences-core/src/main/java/androidx/datastore/preferences/core/PreferencesFactory.kt b/datastore/datastore-preferences-core/src/main/java/androidx/datastore/preferences/core/PreferencesFactory.kt
index ca97f77..2605861 100644
--- a/datastore/datastore-preferences-core/src/main/java/androidx/datastore/preferences/core/PreferencesFactory.kt
+++ b/datastore/datastore-preferences-core/src/main/java/androidx/datastore/preferences/core/PreferencesFactory.kt
@@ -30,9 +30,10 @@
* Construct a Preferences object with a list of Preferences.Pair<T>. Comparable to mapOf().
*
* Example usage:
- *
+ * ```
* val counterKey = intPreferencesKey("counter")
* val preferences = preferencesOf(counterKey to 100)
+ * ```
*
* @param pairs the key value pairs with which to construct the preferences
*/
@@ -44,10 +45,10 @@
* Construct a MutablePreferences object with a list of Preferences.Pair<T>. Comparable to mapOf().
*
* Example usage:
- *
+ * ```
* val counterKey = intPreferencesKey("counter")
- * val preferences = preferencesOf(counterKey to 100)
- *
+ * val preferences = mutablePreferencesOf(counterKey to 100)
+ * ```
* @param pairs the key value pairs with which to construct the preferences
*/
@JvmName("createMutable")
diff --git a/datastore/datastore-preferences/src/main/java/androidx/datastore/preferences/PreferenceDataStoreDelegate.kt b/datastore/datastore-preferences/src/main/java/androidx/datastore/preferences/PreferenceDataStoreDelegate.kt
index 0226299..fc7b3ad 100644
--- a/datastore/datastore-preferences/src/main/java/androidx/datastore/preferences/PreferenceDataStoreDelegate.kt
+++ b/datastore/datastore-preferences/src/main/java/androidx/datastore/preferences/PreferenceDataStoreDelegate.kt
@@ -37,13 +37,21 @@
* in a file (at the top level), and all usages of the DataStore should use a reference the same
* Instance. The receiver type for the property delegate must be an instance of [Context].
*
+ * Example usage:
+ * ```
+ * val Context.myDataStore by preferencesDataStore("filename")
+ *
+ * class SomeClass(val context: Context) {
+ * suspend fun update() = context.myDataStore.edit {...}
+ * }
+ * ```
+ *
+ *
* @param name The name of the preferences. The preferences will be stored in a file obtained
* by calling: File(context.filesDir, "datastore/" + name + ".preferences_pb")
* @param corruptionHandler The corruptionHandler is invoked if DataStore encounters a
* [androidx.datastore.core.CorruptionException] when attempting to read data. CorruptionExceptions
- * are
- * thrown by
- * serializers when data can not be de-serialized.
+ * are thrown by serializers when data can not be de-serialized.
* @param migrations are run before any access to data can occur. Each producer and migration
* may be run more than once whether or not it already succeeded (potentially because another
* migration failed or a write to disk failed.)
diff --git a/datastore/datastore/src/main/java/androidx/datastore/DataStoreDelegate.kt b/datastore/datastore/src/main/java/androidx/datastore/DataStoreDelegate.kt
index e710679..3dea771 100644
--- a/datastore/datastore/src/main/java/androidx/datastore/DataStoreDelegate.kt
+++ b/datastore/datastore/src/main/java/androidx/datastore/DataStoreDelegate.kt
@@ -35,14 +35,21 @@
* in a file (at the top level), and all usages of the DataStore should use a reference the same
* Instance. The receiver type for the property delegate must be an instance of [Context].
*
+ * Example usage:
+ * ```
+ * val Context.myDataStore by dataStore("filename", serializer)
+ *
+ * class SomeClass(val context: Context) {
+ * suspend fun update() = context.myDataStore.updateData {...}
+ * }
+ * ```
+ *
* @param fileName the filename relative to Context.filesDir that DataStore acts on. The File is
* obtained by calling File(context.filesDir, "datastore/$fileName")). No two instances of DataStore
* should act on the same file at the same time.
* @param corruptionHandler The corruptionHandler is invoked if DataStore encounters a
* [androidx.datastore.core.CorruptionException] when attempting to read data. CorruptionExceptions
- * are
- * thrown by
- * serializers when data can not be de-serialized.
+ * are thrown by serializers when data can not be de-serialized.
* @param migrations are run before any access to data can occur. Each producer and migration
* may be run more than once whether or not it already succeeded (potentially because another
* migration failed or a write to disk failed.)
diff --git a/datastore/datastore/src/main/java/androidx/datastore/migrations/SharedPreferencesMigration.kt b/datastore/datastore/src/main/java/androidx/datastore/migrations/SharedPreferencesMigration.kt
index 2252461..8fd178c 100644
--- a/datastore/datastore/src/main/java/androidx/datastore/migrations/SharedPreferencesMigration.kt
+++ b/datastore/datastore/src/main/java/androidx/datastore/migrations/SharedPreferencesMigration.kt
@@ -44,7 +44,6 @@
* long, string and string set. If the result of getAll contains other types, they will be
* ignored.
*
- *
* Example usage:
* ```
* val sharedPrefsMigration = SharedPreferencesMigration(
@@ -53,6 +52,7 @@
* myData.toBuilder().setCounter(prefs.getCounter(COUNTER_KEY, default = 0)).build()
* }
* ```
+ *
* @param produceSharedPreferences Should return the instance of SharedPreferences to migrate
* from.
* @param keysToMigrate The list of keys to migrate. The keys will be mapped to datastore