Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Multiplatform Settings 1.x #55 #56

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[versions]
componentsResources = "1.5.1"
componentsResources = "1.5.3"
koalaplotCore = "0.4.0-dev1"
korau = "4.0.6"
kotlin = "1.9.10"
gradle = "8.1.2"
kotlinxCoroutinesSwing = "1.7.3"
detekt = "1.19.0"
gradleVersionUpdate = "0.46.0"
koinCore = "3.4.3"
koinAndroid = "3.4.3"
koinCore = "3.5.0"
koinAndroid = "3.5.0"
kotlinxSerializationJson = "1.6.0"
kotlinxDateTime = "0.4.1"
material3WindowSizeClassMultiplatform = "0.3.1"
napier = "2.6.1"
sqlDelight = "2.0.0"
multiplatformSettings = "0.8.1"
multiplatformSettings = "1.1.0"
compose = "1.5.10-beta01"
core-library-desugaring = "2.0.3"
voyager = "1.0.0-rc07"
compose-activity = "1.7.2"
koin-compose = "1.0.4"
compose-activity = "1.8.0"
koin-compose = "1.1.0"
spotless = "5.17.1"
ktlint = "11.6.1"
accompanist-systemUIController = "0.30.1"
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
package com.joelkanyi.focusbloom.platform

import android.content.Context
import com.russhwolf.settings.AndroidSettings
import com.russhwolf.settings.ExperimentalSettingsApi
import com.russhwolf.settings.ObservableSettings
import com.russhwolf.settings.Settings
import com.russhwolf.settings.SharedPreferencesSettings

actual class MultiplatformSettingsWrapper(private val context: Context) {
@OptIn(ExperimentalSettingsApi::class)
actual fun createSettings(): ObservableSettings {
val sharedPreferences =
context.getSharedPreferences("bloom_preferences", Context.MODE_PRIVATE)
return AndroidSettings(delegate = sharedPreferences)

actual fun createSettings(): Settings {
val delegate = context.getSharedPreferences("bloom_preferences", Context.MODE_PRIVATE)
return SharedPreferencesSettings(delegate)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.joelkanyi.focusbloom.core.data.local.setting

import com.russhwolf.settings.ExperimentalSettingsApi
import com.russhwolf.settings.ObservableSettings
import com.russhwolf.settings.Settings
import com.russhwolf.settings.coroutines.getBooleanFlow
import com.russhwolf.settings.coroutines.getIntFlow
import com.russhwolf.settings.coroutines.getIntOrNullFlow
Expand All @@ -26,7 +27,8 @@ import com.russhwolf.settings.set
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow

class PreferenceManager constructor(private val observableSettings: ObservableSettings) {
class PreferenceManager constructor(private val settings: Settings) {
private val observableSettings: ObservableSettings by lazy { settings as ObservableSettings }

@OptIn(ExperimentalSettingsApi::class)
fun setString(key: String, value: String) {
Expand All @@ -51,7 +53,7 @@ class PreferenceManager constructor(private val observableSettings: ObservableSe
fun getInt(key: String) = observableSettings.getIntOrNullFlow(key = key)

@OptIn(ExperimentalSettingsApi::class, ExperimentalCoroutinesApi::class)
fun getIntFlow(key: String) = observableSettings.getIntFlow(key = key)
fun getIntFlow(key: String) = observableSettings.getIntFlow(key = key, defaultValue = 0)

companion object {
const val USERNAME = "username_key"
Expand Down Expand Up @@ -86,7 +88,8 @@ class PreferenceManager constructor(private val observableSettings: ObservableSe
@OptIn(ExperimentalCoroutinesApi::class, ExperimentalSettingsApi::class)
fun getLong(key: Any): Flow<Long?> {
return observableSettings.getLongFlow(
key = key.toString()
key = key.toString(),
defaultValue = 0
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fun commonModule() = module {
* Multiplatform-Settings
*/
single<PreferenceManager> {
PreferenceManager(observableSettings = get())
PreferenceManager(settings = get())
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
*/
package com.joelkanyi.focusbloom.platform

import com.russhwolf.settings.ExperimentalSettingsApi
import com.russhwolf.settings.ObservableSettings
import com.russhwolf.settings.Settings

expect class MultiplatformSettingsWrapper {
@OptIn(ExperimentalSettingsApi::class)
fun createSettings(): ObservableSettings
fun createSettings(): Settings
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
*/
package com.joelkanyi.focusbloom.platform

import com.russhwolf.settings.AppleSettings
import com.russhwolf.settings.ExperimentalSettingsApi
import com.russhwolf.settings.ObservableSettings
import com.russhwolf.settings.NSUserDefaultsSettings
import com.russhwolf.settings.Settings
import platform.Foundation.NSUserDefaults

actual class MultiplatformSettingsWrapper {
@OptIn(ExperimentalSettingsApi::class)
actual fun createSettings(): ObservableSettings {
val nsUserDefault = NSUserDefaults.standardUserDefaults
return AppleSettings(delegate = nsUserDefault)
actual fun createSettings(): Settings {
val delegate = NSUserDefaults.standardUserDefaults
return NSUserDefaultsSettings(delegate)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@
*/
package com.joelkanyi.focusbloom.platform

import com.russhwolf.settings.ExperimentalSettingsApi
import com.russhwolf.settings.ExperimentalSettingsImplementation
import com.russhwolf.settings.JvmPreferencesSettings
import com.russhwolf.settings.ObservableSettings
import com.russhwolf.settings.PreferencesSettings
import com.russhwolf.settings.Settings
import java.util.prefs.Preferences

actual class MultiplatformSettingsWrapper {
@OptIn(ExperimentalSettingsImplementation::class, ExperimentalSettingsApi::class)
actual fun createSettings(): ObservableSettings {
val preferences: Preferences = Preferences.userRoot()
return JvmPreferencesSettings(delegate = preferences)
actual fun createSettings(): Settings {
val delegate: Preferences = Preferences.userRoot()
return PreferencesSettings(delegate)
}
}
Loading