Skip to content

Commit dc31627

Browse files
committed
Readme and doc updates
Also clears some minor warnings
1 parent da0a3d2 commit dc31627

File tree

15 files changed

+164
-167
lines changed

15 files changed

+164
-167
lines changed

CHANGELOG.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
- BREAKING: Rename Settings implementations to be based on the underlying API used rather than the platform
66

7-
| Old name | New name |
8-
| --- | --- |
9-
| AndroidSettings | SharedPreferencesSettings |
10-
| AppleSettings | NSUserDefaultsSettings |
11-
| JvmPreferencesSettings | PreferencesSettings |
12-
| JvmPropertiesSettings | PropertiesSettings |
13-
| WindowsSettings | RegistrySettings|
14-
| MockSettings | MapSettings |
7+
| Old name | New name |
8+
|------------------------|---------------------------|
9+
| AndroidSettings | SharedPreferencesSettings |
10+
| AppleSettings | NSUserDefaultsSettings |
11+
| JvmPreferencesSettings | PreferencesSettings |
12+
| JvmPropertiesSettings | PropertiesSettings |
13+
| WindowsSettings | RegistrySettings |
14+
| MockSettings | MapSettings |
1515

1616
- BREAKING: Migrate typed listeners from extension functions to members of ObservableSettings
1717
- BREAKING: Remove default values for defaultValue parameters

README.md

Lines changed: 131 additions & 109 deletions
Large diffs are not rendered by default.

multiplatform-settings-coroutines/src/commonMain/kotlin/com/russhwolf/settings/coroutines/CoroutineExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public fun ObservableSettings.getBooleanFlow(key: String, defaultValue: Boolean)
103103
createFlow(key, defaultValue, Settings::getBoolean, ObservableSettings::addBooleanListener)
104104

105105
/**
106-
* Create a new flow, based on observing the given [key] as an nullable `Int`. This flow will immediately emit the
106+
* Create a new flow, based on observing the given [key] as a nullable `Int`. This flow will immediately emit the
107107
* current value and then emit any subsequent values when the underlying `Settings` changes. When no value is present,
108108
* `null` will be emitted instead.
109109
*/

multiplatform-settings-coroutines/src/commonTest/kotlin/com/russhwolf/settings/coroutines/BaseCoroutineExtensionsTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ import com.russhwolf.settings.Settings
2323
import kotlinx.coroutines.flow.Flow
2424
import kotlin.test.Test
2525
import kotlin.test.assertEquals
26-
import kotlin.time.ExperimentalTime
2726

28-
@OptIn(ExperimentalSettingsApi::class, ExperimentalTime::class)
27+
@OptIn(ExperimentalSettingsApi::class)
2928
abstract class BaseCoroutineExtensionsTest {
3029

3130
abstract val settings: ObservableSettings

multiplatform-settings-coroutines/src/multithreadedTest/kotlin/com/russhwolf/settings/coroutines/ConvertersTest.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
@file:OptIn(ExperimentalCoroutinesApi::class)
18-
1917
package com.russhwolf.settings.coroutines
2018

2119
import com.russhwolf.settings.BaseSettingsTest
@@ -25,7 +23,6 @@ import com.russhwolf.settings.ObservableSettings
2523
import com.russhwolf.settings.Settings
2624
import kotlinx.coroutines.CoroutineScope
2725
import kotlinx.coroutines.Dispatchers
28-
import kotlinx.coroutines.ExperimentalCoroutinesApi
2926

3027
// TODO we should have test-cases specific to SuspendSettings and FlowSettings, but until we do we test things by
3128
// passing them through toBlockingSettings()

multiplatform-settings-no-arg/src/commonTest/kotlin/com/russhwolf/settings/NoArgTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import kotlin.test.AfterTest
2020
import kotlin.test.Test
2121
import kotlin.test.assertEquals
2222

23-
@OptIn(ExperimentalSettingsImplementation::class)
2423
abstract class NoArgTest {
2524
// clear() inside the lazy block in case subclasses need to do their setup first
2625
private val settings by lazy { Settings().also { it.clear() } }

multiplatform-settings-no-arg/src/jvmMain/kotlin/com/russhwolf/settings/NoArg.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ import java.util.prefs.Preferences
2121
/**
2222
* Returns a default [Settings] instance.
2323
*
24-
* On JVM, this uses the [JvmPreferencesSettings] implementation and delegates to [Preferences.userRoot]
24+
* On JVM, this uses the [PreferencesSettings] implementation and delegates to [Preferences.userRoot]
2525
*/
2626
public actual fun Settings(): Settings = PreferencesSettings(Preferences.userRoot())

multiplatform-settings-test/src/commonMain/kotlin/com/russhwolf/settings/MapSettings.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ package com.russhwolf.settings
2222
* This class allows storage of values with the [Int], [Long], [String], [Float], [Double], or [Boolean] types, using a
2323
* [String] reference as a key.
2424
*
25-
* The `MockSettings` implementation is intended for use in unit tests. The mock persisted state is represented by a
26-
* [Map] and can be injected at construction time.
27-
*
28-
* Operator extensions are defined in order to simplify usage. In addition, property delegates are provided for cleaner
29-
* syntax and better type-safety when interacting with values stored in a `Settings` instance.
25+
* The `MapSettings` implementation is intended for use in unit tests. It differs from production implementations
26+
* because the state exists only in-memory and has no mechanism for persistence.
3027
*
3128
* This class can be instantiated by wrapping a [MutableMap] or set of [Pair] entries, or via a [Factory].
3229
*
@@ -55,7 +52,7 @@ public class MapSettings public constructor(private val delegate: MutableMap<Str
5552
) : Settings.Factory {
5653

5754
/**
58-
* Assigns the values in [delegate] to the cache that will be used to back any [MockSettings] this factory
55+
* Assigns the values in [delegate] to the cache that will be used to back any [MapSettings] this factory
5956
* creates named [name]
6057
*/
6158
public fun setCacheValues(name: String?, delegate: Map<String, Any>) {
@@ -65,7 +62,7 @@ public class MapSettings public constructor(private val delegate: MutableMap<Str
6562
}
6663

6764
/**
68-
* Assigns the values in [items] to the cache that will be used to back any [MockSettings] this factory
65+
* Assigns the values in [items] to the cache that will be used to back any [MapSettings] this factory
6966
* creates named [name]
7067
*/
7168
public fun setCacheValues(name: String?, vararg items: Pair<String, Any>) {
@@ -241,11 +238,12 @@ public class MapSettings public constructor(private val delegate: MutableMap<Str
241238
}
242239

243240
/**
244-
* A handle to a listener instance created in [addListener] so it can be passed to [removeListener]
241+
* A handle to a listener instance returned by one of the addListener methods of [ObservableSettings], so it can be
242+
* deactivated as needed.
245243
*
246-
* In the [MockSettings] implementation this simply wraps a lambda parameter which is being called whenever a
244+
* In the [MapSettings] implementation this simply wraps a lambda parameter which is being called whenever a
247245
* mutating API is called. Unlike platform implementations, this listener will NOT be called if the underlying map
248-
* is mutated by something other than the `MockSettings` instance that originally created the listener.
246+
* is mutated by something other than the `MapSettings` instance that originally created the listener.
249247
*/
250248
public class Listener internal constructor(
251249
private val listeners: MutableList<() -> Any>,

multiplatform-settings/src/androidMain/kotlin/com/russhwolf/settings/SharedPreferencesSettings.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ public class SharedPreferencesSettings @JvmOverloads public constructor(
5151
/**
5252
* A factory that can produce [Settings] instances.
5353
*
54-
* This class can only be instantiated via a platform-specific constructor. It's purpose is so that `Settings`
55-
* objects can be created in common code, so that the only platform-specific behavior necessary in order to use
56-
* multiple `Settings` objects is the one-time creation of a single `Factory`.
57-
*
58-
* On the Android platform, this class creates `Settings` objects backed by [SharedPreferences]. It can only be
54+
* This class creates `Settings` objects backed by [SharedPreferences]. It can only be
5955
* created by supplying a [Context] instance. The `Factory` will hold onto a reference to the
6056
* [applicationContext][Context.getApplicationContext] property of the supplied `context` and will use that to
6157
* create [SharedPreferences] objects.
@@ -268,7 +264,8 @@ public class SharedPreferencesSettings @JvmOverloads public constructor(
268264
}
269265

270266
/**
271-
* A handle to a listener instance created in [addListener] so it can be passed to [removeListener]
267+
* A handle to a listener instance returned by one of the addListener methods of [ObservableSettings], so it can be
268+
* deactivated as needed.
272269
*
273270
* On the Android platform, this is a wrapper around [SharedPreferences.OnSharedPreferenceChangeListener].
274271
*/

multiplatform-settings/src/androidTest/kotlin/com/russhwolf/settings/SharedPreferencesSettingsTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class SharedPreferencesSettingsTest : BaseSettingsTest(factory) {
8181
@Test
8282
fun issue_108() {
8383
// In Android 11 (SDK level 30), we will get OnSharedPreferenceChangeListener callbacks with a null updatedKey
84-
// if the user calls clear() on the SharedPreferenecs.Editor. On Multiplatform Settings versions 0.8.1 and
84+
// if the user calls clear() on the SharedPreferences.Editor. On Multiplatform Settings versions 0.8.1 and
8585
// earlier, we assumed updatedKey was nonnull so this would crash.
8686

8787
val preferences = context.getSharedPreferences("Settings", Context.MODE_PRIVATE)

multiplatform-settings/src/appleMain/kotlin/com/russhwolf/settings/KeychainSettings.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ public class KeychainSettings(vararg defaultProperties: Pair<CFStringRef?, CFTyp
101101
/**
102102
* A factory that can produce [Settings] instances.
103103
*
104-
* This class can only be instantiated via a platform-specific constructor. It's purpose is so that `Settings`
105-
* objects can be created in common code, so that the only platform-specific behavior necessary in order to use
106-
* multiple `Settings` objects is the one-time creation of a single `Factory`.
107-
*
108104
* This class creates `Settings` objects backed by the Apple keychain.
109105
*/
110106
public class Factory : Settings.Factory {

multiplatform-settings/src/appleMain/kotlin/com/russhwolf/settings/NSUserDefaultsSettings.kt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import platform.Foundation.NSNotificationCenter
2222
import platform.Foundation.NSUserDefaults
2323
import platform.Foundation.NSUserDefaultsDidChangeNotification
2424
import platform.darwin.NSObjectProtocol
25-
import kotlin.native.concurrent.AtomicReference
2625

2726
/**
2827
* A collection of storage-backed key-value data
@@ -39,11 +38,6 @@ import kotlin.native.concurrent.AtomicReference
3938
*
4039
* On the iOS and macOS platforms, this class can be created by passing a [NSUserDefaults] instance which will be used as a
4140
* delegate, or via a [Factory].
42-
*
43-
* Note that this class is frozen on construction, and is safe to use in a multi-threaded environment. If the listener
44-
* APIs will be used in such an environment, then [useFrozenListeners] should be set to true on creation. In that case,
45-
* the block passed to [addListener] will be frozen as well so that it can safely be triggered from any thread. To avoid
46-
* freezing listeners, restrict interaction with this class to a single thread and set `useFrozenListeners` to `false`.
4741
*/
4842
public class NSUserDefaultsSettings public constructor(
4943
private val delegate: NSUserDefaults
@@ -52,11 +46,7 @@ public class NSUserDefaultsSettings public constructor(
5246
/**
5347
* A factory that can produce [Settings] instances.
5448
*
55-
* This class can only be instantiated via a platform-specific constructor. It's purpose is so that `Settings`
56-
* objects can be created in common code, so that the only platform-specific behavior necessary in order to use
57-
* multiple `Settings` objects is the one-time creation of a single `Factory`.
58-
*
59-
* On the iOS and macOS platforms, this class creates `Settings` objects backed by [NSUserDefaults].
49+
* This class creates `Settings` objects backed by [NSUserDefaults].
6050
*/
6151
public class Factory : Settings.Factory {
6252

@@ -238,7 +228,8 @@ public class NSUserDefaultsSettings public constructor(
238228
}
239229

240230
/**
241-
* A handle to a listener instance created in [addListener] so it can be passed to [removeListener]
231+
* A handle to a listener instance returned by one of the addListener methods of [ObservableSettings], so it can be
232+
* deactivated as needed.
242233
*
243234
* On the iOS and macOS platforms, this is a wrapper around the object returned by [NSNotificationCenter.addObserverForName]
244235
*/

multiplatform-settings/src/appleTest/kotlin/com/russhwolf/settings/NSUserDefaultsSettingsBackgroundTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ class NSUserDefaultsSettingsBackgroundTest {
8989
assertEquals(false, incrementedOnMainThread.value)
9090
}
9191

92-
@OptIn(ExperimentalStdlibApi::class)
9392
@Test
9493
fun nonprimitive_value_across_threads(): Unit = memScoped {
9594
val mutableState = AtomicInt(0)

multiplatform-settings/src/commonMain/kotlin/com/russhwolf/settings/Settings.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public interface ObservableSettings : Settings {
305305
* Adds a listener which will call the supplied [callback] anytime the value at [key] changes. A [SettingsListener]
306306
* reference is returned which can be used to halt callbacks by calling [deactivate()][SettingsListener.deactivate].
307307
* A strong reference should be held to the `SettingsListener` returned by this method in order to avoid it being
308-
* garbaze-collected.
308+
* garbage-collected.
309309
*/
310310
@Suppress("DEPRECATION")
311311
public fun addDoubleOrNullListener(
@@ -328,11 +328,13 @@ public interface ObservableSettings : Settings {
328328
}
329329

330330
/**
331-
* A handle to a listener instance returned by [ObservableSettings.addListener] so it can be deactivated as needed
331+
* A handle to a listener instance returned by one of the addListener methods of [ObservableSettings], so it can be
332+
* deactivated as needed.
332333
*/
333334
public interface SettingsListener {
334335
/**
335-
* Unsubscribes this [SettingsListener] from receiving updates to the value at the key it monitors
336+
* Unsubscribes this [SettingsListener] from receiving updates to the value at the key it monitors. After calling
337+
* this method you should no longer hold a reference to the listener.
336338
*/
337339
public fun deactivate()
338340
}

multiplatform-settings/src/jvmMain/kotlin/com/russhwolf/settings/PreferencesSettings.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ public class PreferencesSettings public constructor(
4848
/**
4949
* A factory that can produce [Settings] instances.
5050
*
51-
* This class can only be instantiated via a platform-specific constructor. It's purpose is so that `Settings`
52-
* objects can be created in common code, so that the only platform-specific behavior necessary in order to use
53-
* multiple `Settings` objects is the one-time creation of a single `Factory`.
54-
*
5551
* On the JVM platform, this class creates `Settings` objects backed by [Preferences].
5652
*/
5753
public class Factory(private val rootPreferences: Preferences = Preferences.userRoot()) : Settings.Factory {
@@ -213,7 +209,8 @@ public class PreferencesSettings public constructor(
213209
}
214210

215211
/**
216-
* A handle to a listener instance created in [addListener] so it can be passed to [removeListener]
212+
* A handle to a listener instance returned by one of the addListener methods of [ObservableSettings], so it can be
213+
* deactivated as needed.
217214
*
218215
* On the JVM platform, this is a wrapper around [PreferenceChangeListener].
219216
*/

0 commit comments

Comments
 (0)