From 26d7e70ae0f648770e2a084c6e5e29f1f7e24601 Mon Sep 17 00:00:00 2001 From: Syer10 Date: Tue, 1 Feb 2022 19:33:40 -0500 Subject: [PATCH] Start working on moving classes to a shared Jvm module --- buildSrc/src/main/kotlin/Config.kt | 1 + core/build.gradle.kts | 8 +- .../ca/gosyer/core/prefs/AndroidPreference.kt | 100 ++++++++++++++ .../core/prefs/AndroidPreferenceAdapters.kt | 128 ++++++++++++++++++ .../core/prefs/AndroidPreferenceStore.kt | 83 ++++++++++++ .../core/prefs/PreferenceStoreFactory.kt | 21 +++ .../core/prefs/PreferenceStoreFactory.kt | 3 +- .../ca/gosyer/core/io/DataUriStringSource.kt | 53 -------- .../ca/gosyer/core/io/OkioExtensions.kt | 9 +- .../kotlin/ca/gosyer/core/logging/Logging.kt | 0 .../core/prefs/PreferenceStoreFactory.kt | 2 +- .../kotlin/ca/gosyer/core/util/Codec.kt | 14 -- data/build.gradle.kts | 8 +- .../kotlin/ca/gosyer/data/DataComponent.kt | 96 +++++++++++++ .../kotlin/ca/gosyer/data/DataComponent.kt | 100 ++++++++++++++ .../kotlin/ca/gosyer/data/DataComponent.kt | 92 +------------ .../ca/gosyer/data/base/WebsocketService.kt | 0 .../gosyer/data/download/DownloadService.kt | 0 .../data/download/model/DownloadChapter.kt | 0 .../data/download/model/DownloadState.kt | 0 .../data/download/model/DownloadStatus.kt | 0 .../data/download/model/DownloaderStatus.kt | 0 .../gosyer/data/library/LibraryPreferences.kt | 0 .../data/library/LibraryUpdateService.kt | 0 .../gosyer/data/library/model/DisplayMode.kt | 0 .../ca/gosyer/data/library/model/JobStatus.kt | 0 .../gosyer/data/library/model/UpdateStatus.kt | 0 .../data/migration/MigrationPreferences.kt | 0 .../ca/gosyer/data/migration/Migrations.kt | 0 .../ca/gosyer/data/server/HttpClient.kt | 0 .../gosyer/data/server/ServerPreferences.kt | 0 .../gosyer/data/server/ServerUrlPreference.kt | 0 .../interactions/BackupInteractionHandler.kt | 0 .../interactions/BaseInteractionHandler.kt | 0 .../CategoryInteractionHandler.kt | 0 .../interactions/ChapterInteractionHandler.kt | 0 .../DownloadInteractionHandler.kt | 0 .../ExtensionInteractionHandler.kt | 0 .../interactions/LibraryInteractionHandler.kt | 0 .../interactions/MangaInteractionHandler.kt | 0 .../interactions/SourceInteractionHandler.kt | 0 .../interactions/UpdatesInteractionHandler.kt | 0 .../ca/gosyer/data/server/model/Auth.kt | 0 .../ca/gosyer/data/server/model/Proxy.kt | 0 .../ca/gosyer/data/server/requests/Backup.kt | 0 .../gosyer/data/server/requests/Category.kt | 0 .../gosyer/data/server/requests/Chapters.kt | 0 .../gosyer/data/server/requests/Downloads.kt | 0 .../gosyer/data/server/requests/Extensions.kt | 0 .../ca/gosyer/data/server/requests/Library.kt | 0 .../ca/gosyer/data/server/requests/Manga.kt | 0 .../ca/gosyer/data/server/requests/Meta.kt | 0 .../data/server/requests/RestRequests.kt | 0 .../ca/gosyer/data/server/requests/Sources.kt | 0 .../ca/gosyer/data/server/requests/Updates.kt | 0 .../ca/gosyer/data/update/UpdateChecker.kt | 0 .../gosyer/data/update/UpdatePreferences.kt | 0 .../gosyer/data/update/model/GithubRelease.kt | 0 i18n/build.gradle.kts | 8 +- presentation/build.gradle.kts | 8 +- .../kotlin/ca/gosyer/ui/util/compose/Image.kt | 8 +- ui-core/build.gradle.kts | 8 +- .../gosyer/uicore/resources/stringResource.kt | 41 ++++++ .../gosyer/uicore/resources/StringResource.kt | 23 ++++ .../gosyer/uicore/resources/StringResource.kt | 8 +- .../uicore/components/DropdownIconButton.kt | 0 .../gosyer/uicore/components/ErrorScreen.kt | 0 .../gosyer/uicore/components/LoadingScreen.kt | 0 .../ca/gosyer/uicore/components/Manga.kt | 0 .../gosyer/uicore/components/MangaListItem.kt | 0 .../ca/gosyer/uicore/components/Spinner.kt | 0 .../ca/gosyer/uicore/image/KamelImage.kt | 0 .../ca/gosyer/uicore/prefs/ColorPreference.kt | 0 .../uicore/prefs/IntStringPreference.kt | 0 .../uicore/prefs/PreferenceMutableState.kt | 0 .../ca/gosyer/uicore/theme/RandomColors.kt | 0 .../kotlin/ca/gosyer/uicore/theme/Themes.kt | 0 .../ca/gosyer/uicore/vm/ComposeViewModel.kt | 0 .../kotlin/ca/gosyer/uicore/vm/ViewModel.kt | 0 .../ca/gosyer/uicore/vm/ViewModelFactory.kt | 0 80 files changed, 647 insertions(+), 175 deletions(-) create mode 100644 core/src/androidMain/kotlin/ca/gosyer/core/prefs/AndroidPreference.kt create mode 100644 core/src/androidMain/kotlin/ca/gosyer/core/prefs/AndroidPreferenceAdapters.kt create mode 100644 core/src/androidMain/kotlin/ca/gosyer/core/prefs/AndroidPreferenceStore.kt create mode 100644 core/src/androidMain/kotlin/ca/gosyer/core/prefs/PreferenceStoreFactory.kt delete mode 100644 core/src/jvmMain/kotlin/ca/gosyer/core/io/DataUriStringSource.kt rename core/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/core/logging/Logging.kt (100%) delete mode 100644 core/src/jvmMain/kotlin/ca/gosyer/core/util/Codec.kt create mode 100644 data/src/androidMain/kotlin/ca/gosyer/data/DataComponent.kt create mode 100644 data/src/desktopMain/kotlin/ca/gosyer/data/DataComponent.kt rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/base/WebsocketService.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/download/DownloadService.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/download/model/DownloadChapter.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/download/model/DownloadState.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/download/model/DownloadStatus.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/download/model/DownloaderStatus.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/library/LibraryPreferences.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/library/LibraryUpdateService.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/library/model/DisplayMode.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/library/model/JobStatus.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/library/model/UpdateStatus.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/migration/MigrationPreferences.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/migration/Migrations.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/HttpClient.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/ServerPreferences.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/ServerUrlPreference.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/interactions/BackupInteractionHandler.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/interactions/BaseInteractionHandler.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/interactions/CategoryInteractionHandler.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/interactions/ChapterInteractionHandler.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/interactions/DownloadInteractionHandler.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/interactions/ExtensionInteractionHandler.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/interactions/LibraryInteractionHandler.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/interactions/MangaInteractionHandler.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/interactions/SourceInteractionHandler.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/interactions/UpdatesInteractionHandler.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/model/Auth.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/model/Proxy.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/requests/Backup.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/requests/Category.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/requests/Chapters.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/requests/Downloads.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/requests/Extensions.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/requests/Library.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/requests/Manga.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/requests/Meta.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/requests/RestRequests.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/requests/Sources.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/server/requests/Updates.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/update/UpdateChecker.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/update/UpdatePreferences.kt (100%) rename data/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/data/update/model/GithubRelease.kt (100%) create mode 100644 ui-core/src/androidMain/kotlin/ca/gosyer/uicore/resources/stringResource.kt create mode 100644 ui-core/src/commonMain/kotlin/ca/gosyer/uicore/resources/StringResource.kt rename ui-core/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/uicore/components/DropdownIconButton.kt (100%) rename ui-core/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/uicore/components/ErrorScreen.kt (100%) rename ui-core/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/uicore/components/LoadingScreen.kt (100%) rename ui-core/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/uicore/components/Manga.kt (100%) rename ui-core/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/uicore/components/MangaListItem.kt (100%) rename ui-core/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/uicore/components/Spinner.kt (100%) rename ui-core/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/uicore/image/KamelImage.kt (100%) rename ui-core/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/uicore/prefs/ColorPreference.kt (100%) rename ui-core/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/uicore/prefs/IntStringPreference.kt (100%) rename ui-core/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/uicore/prefs/PreferenceMutableState.kt (100%) rename ui-core/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/uicore/theme/RandomColors.kt (100%) rename ui-core/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/uicore/theme/Themes.kt (100%) rename ui-core/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/uicore/vm/ComposeViewModel.kt (100%) rename ui-core/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/uicore/vm/ViewModel.kt (100%) rename ui-core/src/{desktopMain => jvmMain}/kotlin/ca/gosyer/uicore/vm/ViewModelFactory.kt (100%) diff --git a/buildSrc/src/main/kotlin/Config.kt b/buildSrc/src/main/kotlin/Config.kt index 7ba461e6..09d532de 100644 --- a/buildSrc/src/main/kotlin/Config.kt +++ b/buildSrc/src/main/kotlin/Config.kt @@ -11,4 +11,5 @@ object Config { const val previewCommit = "b714abddae9f13e91bc53c5daac54aeae564cd2a" val desktopJvmTarget = JavaVersion.VERSION_16 + val androidJvmTarget = JavaVersion.VERSION_11 } \ No newline at end of file diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 5728aa58..6e335368 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -14,7 +14,13 @@ repositories { } kotlin { - android() + android { + compilations { + all { + kotlinOptions.jvmTarget = Config.androidJvmTarget.toString() + } + } + } jvm("desktop") { compilations { all { diff --git a/core/src/androidMain/kotlin/ca/gosyer/core/prefs/AndroidPreference.kt b/core/src/androidMain/kotlin/ca/gosyer/core/prefs/AndroidPreference.kt new file mode 100644 index 00000000..4f828264 --- /dev/null +++ b/core/src/androidMain/kotlin/ca/gosyer/core/prefs/AndroidPreference.kt @@ -0,0 +1,100 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package ca.gosyer.core.prefs + +import com.russhwolf.settings.ObservableSettings +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.channels.awaitClose +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.callbackFlow +import kotlinx.coroutines.flow.stateIn + +internal class AndroidPreference( + private val preferences: ObservableSettings, + private val key: String, + private val defaultValue: T, + private val adapter: Adapter +) : Preference { + + interface Adapter { + fun get(key: String, preferences: ObservableSettings): T + + fun set(key: String, value: T, editor: ObservableSettings) + + fun isSet(keys: Set, key: String): Boolean = key in keys + + fun keyListener(key: String) = key + } + + /** + * Returns the key of this preference. + */ + override fun key(): String { + return key + } + + /** + * Returns the current value of this preference. + */ + override fun get(): T { + return if (isSet()) { + adapter.get(key, preferences) + } else { + defaultValue + } + } + + /** + * Sets a new [value] for this preference. + */ + override fun set(value: T) { + adapter.set(key, value, preferences) + } + + /** + * Returns whether there's an existing entry for this preference. + */ + override fun isSet(): Boolean { + return adapter.isSet(preferences.keys, key) + } + + /** + * Deletes the entry of this preference. + */ + override fun delete() { + preferences.remove(key) + } + + /** + * Returns the default value of this preference + */ + override fun defaultValue(): T { + return defaultValue + } + + /** + * Returns a cold [Flow] of this preference to receive updates when its value changes. + */ + override fun changes(): Flow { + return callbackFlow { + val listener = preferences.addListener(adapter.keyListener(key)) { + trySend(get()) + } + awaitClose { listener.deactivate() } + } + } + + /** + * Returns a hot [StateFlow] of this preference bound to the given [scope], allowing to read the + * current value and receive preference updates. + */ + override fun stateIn(scope: CoroutineScope): StateFlow { + return changes().stateIn(scope, SharingStarted.Eagerly, get()) + } +} diff --git a/core/src/androidMain/kotlin/ca/gosyer/core/prefs/AndroidPreferenceAdapters.kt b/core/src/androidMain/kotlin/ca/gosyer/core/prefs/AndroidPreferenceAdapters.kt new file mode 100644 index 00000000..84979086 --- /dev/null +++ b/core/src/androidMain/kotlin/ca/gosyer/core/prefs/AndroidPreferenceAdapters.kt @@ -0,0 +1,128 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package ca.gosyer.core.prefs + +import com.russhwolf.settings.ObservableSettings +import com.russhwolf.settings.serialization.decodeValue +import com.russhwolf.settings.serialization.encodeValue +import kotlinx.serialization.KSerializer +import kotlinx.serialization.builtins.SetSerializer +import kotlinx.serialization.builtins.serializer +import kotlinx.serialization.modules.EmptySerializersModule +import kotlinx.serialization.modules.SerializersModule + +internal object StringAdapter : AndroidPreference.Adapter { + override fun get(key: String, preferences: ObservableSettings): String { + return preferences.getString(key) // Not called unless key is present. + } + + override fun set(key: String, value: String, editor: ObservableSettings) { + editor.putString(key, value) + } +} + +internal object LongAdapter : AndroidPreference.Adapter { + override fun get(key: String, preferences: ObservableSettings): Long { + return preferences.getLong(key, 0) + } + + override fun set(key: String, value: Long, editor: ObservableSettings) { + editor.putLong(key, value) + } +} + +internal object IntAdapter : AndroidPreference.Adapter { + override fun get(key: String, preferences: ObservableSettings): Int { + return preferences.getInt(key, 0) + } + + override fun set(key: String, value: Int, editor: ObservableSettings) { + editor.putInt(key, value) + } +} + +internal object FloatAdapter : AndroidPreference.Adapter { + override fun get(key: String, preferences: ObservableSettings): Float { + return preferences.getFloat(key, 0f) + } + + override fun set(key: String, value: Float, editor: ObservableSettings) { + editor.putFloat(key, value) + } +} + +internal object BooleanAdapter : AndroidPreference.Adapter { + override fun get(key: String, preferences: ObservableSettings): Boolean { + return preferences.getBoolean(key, false) + } + + override fun set(key: String, value: Boolean, editor: ObservableSettings) { + editor.putBoolean(key, value) + } +} + +internal object StringSetAdapter : AndroidPreference.Adapter> { + override fun get(key: String, preferences: ObservableSettings): Set { + return preferences.decodeValue(SetSerializer(String.serializer()), key, emptySet()) // Not called unless key is present. + } + + override fun set(key: String, value: Set, editor: ObservableSettings) { + editor.encodeValue(SetSerializer(String.serializer()), key, value) + } + + /** + * Encoding a string set makes a list of keys and a size key, such as key.size and key.0-size + */ + override fun isSet(keys: Set, key: String): Boolean { + return keys.contains("$key.size") + } + + /** + * Watching the regular key doesnt produce updates for a string set for some reason + * TODO make better, doesnt produce updates when you add something and remove something + */ + override fun keyListener(key: String): String { + return "$key.size" + } +} + +internal class ObjectAdapter( + private val serializer: (T) -> String, + private val deserializer: (String) -> T +) : AndroidPreference.Adapter { + + override fun get(key: String, preferences: ObservableSettings): T { + return deserializer(preferences.getString(key)) // Not called unless key is present. + } + + override fun set(key: String, value: T, editor: ObservableSettings) { + editor.putString(key, serializer(value)) + } +} + +internal class JsonObjectAdapter( + private val defaultValue: T, + private val serializer: KSerializer, + private val serializersModule: SerializersModule = EmptySerializersModule +) : AndroidPreference.Adapter { + + override fun get(key: String, preferences: ObservableSettings): T { + return preferences.decodeValue(serializer, key, defaultValue, serializersModule) // Not called unless key is present. + } + + override fun set(key: String, value: T, editor: ObservableSettings) { + editor.encodeValue(serializer, key, value, serializersModule) + } + + /** + * Encoding a structure makes keys start with the [key] and adds extensions for values, + * for a pair it would be like [key].first [key].second. + */ + override fun isSet(keys: Set, key: String): Boolean { + return keys.any { it.startsWith(key) } + } +} diff --git a/core/src/androidMain/kotlin/ca/gosyer/core/prefs/AndroidPreferenceStore.kt b/core/src/androidMain/kotlin/ca/gosyer/core/prefs/AndroidPreferenceStore.kt new file mode 100644 index 00000000..fa620ca2 --- /dev/null +++ b/core/src/androidMain/kotlin/ca/gosyer/core/prefs/AndroidPreferenceStore.kt @@ -0,0 +1,83 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package ca.gosyer.core.prefs + +import com.russhwolf.settings.ObservableSettings +import kotlinx.serialization.KSerializer +import kotlinx.serialization.modules.SerializersModule + +class AndroidPreferenceStore(private val preferences: ObservableSettings) : PreferenceStore { + + /** + * Returns an [String] preference for this [key]. + */ + override fun getString(key: String, defaultValue: String): Preference { + return AndroidPreference(preferences, key, defaultValue, StringAdapter) + } + + /** + * Returns a [Long] preference for this [key]. + */ + override fun getLong(key: String, defaultValue: Long): Preference { + return AndroidPreference(preferences, key, defaultValue, LongAdapter) + } + + /** + * Returns an [Int] preference for this [key]. + */ + override fun getInt(key: String, defaultValue: Int): Preference { + return AndroidPreference(preferences, key, defaultValue, IntAdapter) + } + + /** + * Returns a [Float] preference for this [key]. + */ + override fun getFloat(key: String, defaultValue: Float): Preference { + return AndroidPreference(preferences, key, defaultValue, FloatAdapter) + } + + /** + * Returns a [Boolean] preference for this [key]. + */ + override fun getBoolean(key: String, defaultValue: Boolean): Preference { + return AndroidPreference(preferences, key, defaultValue, BooleanAdapter) + } + + /** + * Returns a [Set] preference for this [key]. + */ + override fun getStringSet(key: String, defaultValue: Set): Preference> { + return AndroidPreference(preferences, key, defaultValue, StringSetAdapter) + } + + /** + * Returns preference of type [T] for this [key]. The [serializer] and [deserializer] function + * must be provided. + */ + override fun getObject( + key: String, + defaultValue: T, + serializer: (T) -> String, + deserializer: (String) -> T + ): Preference { + val adapter = ObjectAdapter(serializer, deserializer) + return AndroidPreference(preferences, key, defaultValue, adapter) + } + + /** + * Returns preference of type [T] for this [key]. The [serializer] must be provided. + */ + override fun getJsonObject( + key: String, + defaultValue: T, + serializer: KSerializer, + serializersModule: SerializersModule + ): Preference { + val adapter = JsonObjectAdapter(defaultValue, serializer, serializersModule) + return AndroidPreference(preferences, key, defaultValue, adapter) + } +} diff --git a/core/src/androidMain/kotlin/ca/gosyer/core/prefs/PreferenceStoreFactory.kt b/core/src/androidMain/kotlin/ca/gosyer/core/prefs/PreferenceStoreFactory.kt new file mode 100644 index 00000000..b849bf25 --- /dev/null +++ b/core/src/androidMain/kotlin/ca/gosyer/core/prefs/PreferenceStoreFactory.kt @@ -0,0 +1,21 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package ca.gosyer.core.prefs + +import android.content.Context +import com.russhwolf.settings.AndroidSettings +import me.tatarka.inject.annotations.Inject + +actual class PreferenceStoreFactory @Inject constructor(private val context: Context) { + actual fun create(vararg names: String): PreferenceStore { + return AndroidPreferenceStore( + AndroidSettings( + context.getSharedPreferences(names.joinToString(separator = "/"), Context.MODE_PRIVATE) + ) + ) + } +} diff --git a/core/src/desktopMain/kotlin/ca/gosyer/core/prefs/PreferenceStoreFactory.kt b/core/src/desktopMain/kotlin/ca/gosyer/core/prefs/PreferenceStoreFactory.kt index 0e8523f4..43283b14 100644 --- a/core/src/desktopMain/kotlin/ca/gosyer/core/prefs/PreferenceStoreFactory.kt +++ b/core/src/desktopMain/kotlin/ca/gosyer/core/prefs/PreferenceStoreFactory.kt @@ -7,9 +7,10 @@ package ca.gosyer.core.prefs import com.russhwolf.settings.JvmPreferencesSettings +import me.tatarka.inject.annotations.Inject import java.util.prefs.Preferences -actual class PreferenceStoreFactory { +actual class PreferenceStoreFactory @Inject constructor() { private val rootNode: Preferences = Preferences.userRoot() .node("ca/gosyer/tachideskjui") diff --git a/core/src/jvmMain/kotlin/ca/gosyer/core/io/DataUriStringSource.kt b/core/src/jvmMain/kotlin/ca/gosyer/core/io/DataUriStringSource.kt deleted file mode 100644 index 6750968e..00000000 --- a/core/src/jvmMain/kotlin/ca/gosyer/core/io/DataUriStringSource.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package ca.gosyer.core.io - -import ca.gosyer.core.util.decodeBase64 -import okio.Buffer -import okio.Source -import okio.Timeout - -class DataUriStringSource(private val data: String) : Source { - - private val timeout = Timeout() - - private val headers = data.substringBefore(",") - - private var pos = headers.length + 1 - - private val decoder: (Buffer, String) -> Long = if ("base64" in headers) { - { sink, bytes -> - val decoded = bytes.decodeBase64() - sink.write(decoded) - decoded.size.toLong() - } - } else { - { sink, bytes -> - val decoded = bytes.toByteArray() - sink.write(decoded) - decoded.size.toLong() - } - } - - override fun read(sink: Buffer, byteCount: Long): Long { - if (pos >= data.length) return -1 - - val charsToRead = minOf(data.length - pos, byteCount.toInt()) - val nextChars = data.substring(pos, pos + charsToRead) - - pos += charsToRead - - return decoder(sink, nextChars) - } - - override fun timeout(): Timeout { - return timeout - } - - override fun close() { - } -} diff --git a/core/src/jvmMain/kotlin/ca/gosyer/core/io/OkioExtensions.kt b/core/src/jvmMain/kotlin/ca/gosyer/core/io/OkioExtensions.kt index 1f8f9100..fa06a559 100644 --- a/core/src/jvmMain/kotlin/ca/gosyer/core/io/OkioExtensions.kt +++ b/core/src/jvmMain/kotlin/ca/gosyer/core/io/OkioExtensions.kt @@ -8,16 +8,19 @@ package ca.gosyer.core.io import ca.gosyer.core.lang.withIOContext import okio.BufferedSink +import okio.FileSystem +import okio.Path import okio.Source import okio.buffer -import okio.sink import okio.use -import java.nio.file.Path suspend fun Source.saveTo(path: Path) { withIOContext { use { source -> - path.sink().buffer().use { it.writeAll(source) } + FileSystem.SYSTEM + .sink(path) + .buffer() + .use { it.writeAll(source) } } } } diff --git a/core/src/desktopMain/kotlin/ca/gosyer/core/logging/Logging.kt b/core/src/jvmMain/kotlin/ca/gosyer/core/logging/Logging.kt similarity index 100% rename from core/src/desktopMain/kotlin/ca/gosyer/core/logging/Logging.kt rename to core/src/jvmMain/kotlin/ca/gosyer/core/logging/Logging.kt diff --git a/core/src/jvmMain/kotlin/ca/gosyer/core/prefs/PreferenceStoreFactory.kt b/core/src/jvmMain/kotlin/ca/gosyer/core/prefs/PreferenceStoreFactory.kt index 6a17355d..9fefaf41 100644 --- a/core/src/jvmMain/kotlin/ca/gosyer/core/prefs/PreferenceStoreFactory.kt +++ b/core/src/jvmMain/kotlin/ca/gosyer/core/prefs/PreferenceStoreFactory.kt @@ -6,6 +6,6 @@ package ca.gosyer.core.prefs -expect class PreferenceStoreFactory() { +expect class PreferenceStoreFactory { fun create(vararg names: String): PreferenceStore } diff --git a/core/src/jvmMain/kotlin/ca/gosyer/core/util/Codec.kt b/core/src/jvmMain/kotlin/ca/gosyer/core/util/Codec.kt deleted file mode 100644 index 268b190b..00000000 --- a/core/src/jvmMain/kotlin/ca/gosyer/core/util/Codec.kt +++ /dev/null @@ -1,14 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package ca.gosyer.core.util - -import okio.ByteString.Companion.decodeBase64 -import okio.ByteString.Companion.encode - -fun String.decodeBase64() = decodeBase64()!! - -fun String.md5() = encode().md5().hex() diff --git a/data/build.gradle.kts b/data/build.gradle.kts index 870db907..0e1d4dd2 100644 --- a/data/build.gradle.kts +++ b/data/build.gradle.kts @@ -8,7 +8,13 @@ plugins { } kotlin { - android() + android { + compilations { + all { + kotlinOptions.jvmTarget = Config.androidJvmTarget.toString() + } + } + } jvm("desktop") { compilations { all { diff --git a/data/src/androidMain/kotlin/ca/gosyer/data/DataComponent.kt b/data/src/androidMain/kotlin/ca/gosyer/data/DataComponent.kt new file mode 100644 index 00000000..13f378e8 --- /dev/null +++ b/data/src/androidMain/kotlin/ca/gosyer/data/DataComponent.kt @@ -0,0 +1,96 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package ca.gosyer.data + +import android.content.Context +import ca.gosyer.core.di.AppScope +import ca.gosyer.core.prefs.PreferenceStoreFactory +import ca.gosyer.data.catalog.CatalogPreferences +import ca.gosyer.data.download.DownloadService +import ca.gosyer.data.extension.ExtensionPreferences +import ca.gosyer.data.library.LibraryPreferences +import ca.gosyer.data.library.LibraryUpdateService +import ca.gosyer.data.migration.MigrationPreferences +import ca.gosyer.data.migration.Migrations +import ca.gosyer.data.reader.ReaderPreferences +import ca.gosyer.data.server.Http +import ca.gosyer.data.server.HttpProvider +import ca.gosyer.data.server.ServerPreferences +import ca.gosyer.data.ui.UiPreferences +import ca.gosyer.data.update.UpdateChecker +import ca.gosyer.data.update.UpdatePreferences +import me.tatarka.inject.annotations.Component +import me.tatarka.inject.annotations.Provides + +@AppScope +@Component +actual abstract class DataComponent( + @get:AppScope + @get:Provides + val context: Context +) { + protected abstract val preferenceFactory: PreferenceStoreFactory + + protected abstract val httpProvider: HttpProvider + + abstract val downloadService: DownloadService + + abstract val libraryUpdateService: LibraryUpdateService + + abstract val migrations: Migrations + + abstract val updateChecker: UpdateChecker + + @get:AppScope + @get:Provides + val serverPreferences: ServerPreferences + get() = ServerPreferences(preferenceFactory.create("server")) + + @get:AppScope + @get:Provides + val extensionPreferences: ExtensionPreferences + get() = ExtensionPreferences(preferenceFactory.create("extension")) + + @get:AppScope + @get:Provides + val catalogPreferences: CatalogPreferences + get() = CatalogPreferences(preferenceFactory.create("catalog")) + + @get:AppScope + @get:Provides + val libraryPreferences: LibraryPreferences + get() = LibraryPreferences(preferenceFactory.create("library")) + + @get:AppScope + @get:Provides + val readerPreferences: ReaderPreferences + get() = ReaderPreferences(preferenceFactory.create("reader")) { name -> + preferenceFactory.create("reader", name) + } + + @get:AppScope + @get:Provides + val uiPreferences: UiPreferences + get() = UiPreferences(preferenceFactory.create("ui")) + + @get:AppScope + @get:Provides + val migrationPreferences: MigrationPreferences + get() = MigrationPreferences(preferenceFactory.create("migration")) + + @get:AppScope + @get:Provides + val updatePreferences: UpdatePreferences + get() = UpdatePreferences(preferenceFactory.create("update")) + + @get:AppScope + @get:Provides + val http: Http + get() = httpProvider.get(serverPreferences) + + companion object +} diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/DataComponent.kt b/data/src/desktopMain/kotlin/ca/gosyer/data/DataComponent.kt new file mode 100644 index 00000000..3f9e4b25 --- /dev/null +++ b/data/src/desktopMain/kotlin/ca/gosyer/data/DataComponent.kt @@ -0,0 +1,100 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package ca.gosyer.data + +import ca.gosyer.core.di.AppScope +import ca.gosyer.core.prefs.PreferenceStoreFactory +import ca.gosyer.data.catalog.CatalogPreferences +import ca.gosyer.data.download.DownloadService +import ca.gosyer.data.extension.ExtensionPreferences +import ca.gosyer.data.library.LibraryPreferences +import ca.gosyer.data.library.LibraryUpdateService +import ca.gosyer.data.migration.MigrationPreferences +import ca.gosyer.data.migration.Migrations +import ca.gosyer.data.reader.ReaderPreferences +import ca.gosyer.data.server.Http +import ca.gosyer.data.server.HttpProvider +import ca.gosyer.data.server.ServerHostPreferences +import ca.gosyer.data.server.ServerPreferences +import ca.gosyer.data.server.ServerService +import ca.gosyer.data.ui.UiPreferences +import ca.gosyer.data.update.UpdateChecker +import ca.gosyer.data.update.UpdatePreferences +import me.tatarka.inject.annotations.Component +import me.tatarka.inject.annotations.Provides + +@AppScope +@Component +actual abstract class DataComponent { + protected abstract val preferenceFactory: PreferenceStoreFactory + + protected abstract val httpProvider: HttpProvider + + abstract val downloadService: DownloadService + + abstract val libraryUpdateService: LibraryUpdateService + + abstract val migrations: Migrations + + abstract val updateChecker: UpdateChecker + + abstract val serverService: ServerService + + @get:AppScope + @get:Provides + val serverHostPreferences: ServerHostPreferences + get() = ServerHostPreferences(preferenceFactory.create("host")) + + @get:AppScope + @get:Provides + val serverPreferences: ServerPreferences + get() = ServerPreferences(preferenceFactory.create("server")) + + @get:AppScope + @get:Provides + val extensionPreferences: ExtensionPreferences + get() = ExtensionPreferences(preferenceFactory.create("extension")) + + @get:AppScope + @get:Provides + val catalogPreferences: CatalogPreferences + get() = CatalogPreferences(preferenceFactory.create("catalog")) + + @get:AppScope + @get:Provides + val libraryPreferences: LibraryPreferences + get() = LibraryPreferences(preferenceFactory.create("library")) + + @get:AppScope + @get:Provides + val readerPreferences: ReaderPreferences + get() = ReaderPreferences(preferenceFactory.create("reader")) { name -> + preferenceFactory.create("reader", name) + } + + @get:AppScope + @get:Provides + val uiPreferences: UiPreferences + get() = UiPreferences(preferenceFactory.create("ui")) + + @get:AppScope + @get:Provides + val migrationPreferences: MigrationPreferences + get() = MigrationPreferences(preferenceFactory.create("migration")) + + @get:AppScope + @get:Provides + val updatePreferences: UpdatePreferences + get() = UpdatePreferences(preferenceFactory.create("update")) + + @get:AppScope + @get:Provides + val http: Http + get() = httpProvider.get(serverPreferences) + + companion object +} diff --git a/data/src/jvmMain/kotlin/ca/gosyer/data/DataComponent.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/DataComponent.kt index 2e5ca6cb..2c60eb50 100644 --- a/data/src/jvmMain/kotlin/ca/gosyer/data/DataComponent.kt +++ b/data/src/jvmMain/kotlin/ca/gosyer/data/DataComponent.kt @@ -6,94 +6,4 @@ package ca.gosyer.data -import ca.gosyer.core.di.AppScope -import ca.gosyer.core.prefs.PreferenceStoreFactory -import ca.gosyer.data.catalog.CatalogPreferences -import ca.gosyer.data.download.DownloadService -import ca.gosyer.data.extension.ExtensionPreferences -import ca.gosyer.data.library.LibraryPreferences -import ca.gosyer.data.library.LibraryUpdateService -import ca.gosyer.data.migration.MigrationPreferences -import ca.gosyer.data.migration.Migrations -import ca.gosyer.data.reader.ReaderPreferences -import ca.gosyer.data.server.Http -import ca.gosyer.data.server.HttpProvider -import ca.gosyer.data.server.ServerHostPreferences -import ca.gosyer.data.server.ServerPreferences -import ca.gosyer.data.server.ServerService -import ca.gosyer.data.ui.UiPreferences -import ca.gosyer.data.update.UpdateChecker -import ca.gosyer.data.update.UpdatePreferences -import me.tatarka.inject.annotations.Component -import me.tatarka.inject.annotations.Provides - -@AppScope -@Component -abstract class DataComponent { - private val preferenceFactory = PreferenceStoreFactory() - protected abstract val httpProvider: HttpProvider - - abstract val serverService: ServerService - - abstract val downloadService: DownloadService - - abstract val libraryUpdateService: LibraryUpdateService - - abstract val migrations: Migrations - - abstract val updateChecker: UpdateChecker - - @get:AppScope - @get:Provides - val serverPreferences: ServerPreferences - get() = ServerPreferences(preferenceFactory.create("server")) - - @get:AppScope - @get:Provides - val serverHostPreferences: ServerHostPreferences - get() = ServerHostPreferences(preferenceFactory.create("host")) - - @get:AppScope - @get:Provides - val extensionPreferences: ExtensionPreferences - get() = ExtensionPreferences(preferenceFactory.create("extension")) - - @get:AppScope - @get:Provides - val catalogPreferences: CatalogPreferences - get() = CatalogPreferences(preferenceFactory.create("catalog")) - - @get:AppScope - @get:Provides - val libraryPreferences: LibraryPreferences - get() = LibraryPreferences(preferenceFactory.create("library")) - - @get:AppScope - @get:Provides - val readerPreferences: ReaderPreferences - get() = ReaderPreferences(preferenceFactory.create("reader")) { name -> - preferenceFactory.create("reader", name) - } - - @get:AppScope - @get:Provides - val uiPreferences: UiPreferences - get() = UiPreferences(preferenceFactory.create("ui")) - - @get:AppScope - @get:Provides - val migrationPreferences: MigrationPreferences - get() = MigrationPreferences(preferenceFactory.create("migration")) - - @get:AppScope - @get:Provides - val updatePreferences: UpdatePreferences - get() = UpdatePreferences(preferenceFactory.create("update")) - - @get:AppScope - @get:Provides - val http: Http - get() = httpProvider.get(serverPreferences) - - companion object -} +expect abstract class DataComponent diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/base/WebsocketService.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/base/WebsocketService.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/base/WebsocketService.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/base/WebsocketService.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/download/DownloadService.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/download/DownloadService.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/download/DownloadService.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/download/DownloadService.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/download/model/DownloadChapter.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/download/model/DownloadChapter.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/download/model/DownloadChapter.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/download/model/DownloadChapter.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/download/model/DownloadState.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/download/model/DownloadState.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/download/model/DownloadState.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/download/model/DownloadState.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/download/model/DownloadStatus.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/download/model/DownloadStatus.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/download/model/DownloadStatus.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/download/model/DownloadStatus.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/download/model/DownloaderStatus.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/download/model/DownloaderStatus.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/download/model/DownloaderStatus.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/download/model/DownloaderStatus.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/library/LibraryPreferences.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/library/LibraryPreferences.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/library/LibraryPreferences.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/library/LibraryPreferences.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/library/LibraryUpdateService.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/library/LibraryUpdateService.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/library/LibraryUpdateService.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/library/LibraryUpdateService.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/library/model/DisplayMode.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/library/model/DisplayMode.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/library/model/DisplayMode.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/library/model/DisplayMode.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/library/model/JobStatus.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/library/model/JobStatus.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/library/model/JobStatus.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/library/model/JobStatus.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/library/model/UpdateStatus.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/library/model/UpdateStatus.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/library/model/UpdateStatus.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/library/model/UpdateStatus.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/migration/MigrationPreferences.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/migration/MigrationPreferences.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/migration/MigrationPreferences.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/migration/MigrationPreferences.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/migration/Migrations.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/migration/Migrations.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/migration/Migrations.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/migration/Migrations.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/HttpClient.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/HttpClient.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/HttpClient.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/HttpClient.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/ServerPreferences.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/ServerPreferences.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/ServerPreferences.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/ServerPreferences.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/ServerUrlPreference.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/ServerUrlPreference.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/ServerUrlPreference.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/ServerUrlPreference.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/BackupInteractionHandler.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/BackupInteractionHandler.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/BackupInteractionHandler.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/BackupInteractionHandler.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/BaseInteractionHandler.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/BaseInteractionHandler.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/BaseInteractionHandler.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/BaseInteractionHandler.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/CategoryInteractionHandler.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/CategoryInteractionHandler.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/CategoryInteractionHandler.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/CategoryInteractionHandler.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/ChapterInteractionHandler.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/ChapterInteractionHandler.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/ChapterInteractionHandler.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/ChapterInteractionHandler.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/DownloadInteractionHandler.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/DownloadInteractionHandler.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/DownloadInteractionHandler.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/DownloadInteractionHandler.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/ExtensionInteractionHandler.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/ExtensionInteractionHandler.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/ExtensionInteractionHandler.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/ExtensionInteractionHandler.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/LibraryInteractionHandler.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/LibraryInteractionHandler.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/LibraryInteractionHandler.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/LibraryInteractionHandler.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/MangaInteractionHandler.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/MangaInteractionHandler.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/MangaInteractionHandler.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/MangaInteractionHandler.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/SourceInteractionHandler.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/SourceInteractionHandler.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/SourceInteractionHandler.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/SourceInteractionHandler.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/UpdatesInteractionHandler.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/UpdatesInteractionHandler.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/interactions/UpdatesInteractionHandler.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/interactions/UpdatesInteractionHandler.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/model/Auth.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/model/Auth.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/model/Auth.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/model/Auth.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/model/Proxy.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/model/Proxy.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/model/Proxy.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/model/Proxy.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Backup.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Backup.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Backup.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Backup.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Category.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Category.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Category.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Category.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Chapters.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Chapters.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Chapters.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Chapters.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Downloads.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Downloads.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Downloads.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Downloads.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Extensions.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Extensions.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Extensions.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Extensions.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Library.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Library.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Library.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Library.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Manga.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Manga.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Manga.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Manga.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Meta.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Meta.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Meta.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Meta.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/RestRequests.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/RestRequests.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/RestRequests.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/RestRequests.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Sources.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Sources.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Sources.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Sources.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Updates.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Updates.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/server/requests/Updates.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/server/requests/Updates.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/update/UpdateChecker.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/update/UpdateChecker.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/update/UpdateChecker.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/update/UpdateChecker.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/update/UpdatePreferences.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/update/UpdatePreferences.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/update/UpdatePreferences.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/update/UpdatePreferences.kt diff --git a/data/src/desktopMain/kotlin/ca/gosyer/data/update/model/GithubRelease.kt b/data/src/jvmMain/kotlin/ca/gosyer/data/update/model/GithubRelease.kt similarity index 100% rename from data/src/desktopMain/kotlin/ca/gosyer/data/update/model/GithubRelease.kt rename to data/src/jvmMain/kotlin/ca/gosyer/data/update/model/GithubRelease.kt diff --git a/i18n/build.gradle.kts b/i18n/build.gradle.kts index b719430f..72228679 100644 --- a/i18n/build.gradle.kts +++ b/i18n/build.gradle.kts @@ -8,7 +8,13 @@ plugins { } kotlin { - android() + android { + compilations { + all { + kotlinOptions.jvmTarget = Config.androidJvmTarget.toString() + } + } + } jvm("desktop") { compilations { all { diff --git a/presentation/build.gradle.kts b/presentation/build.gradle.kts index 1cccaa50..b0d8b475 100644 --- a/presentation/build.gradle.kts +++ b/presentation/build.gradle.kts @@ -10,7 +10,13 @@ plugins { } kotlin { - android() + android { + compilations { + all { + kotlinOptions.jvmTarget = Config.androidJvmTarget.toString() + } + } + } jvm("desktop") { compilations { all { diff --git a/presentation/src/desktopMain/kotlin/ca/gosyer/ui/util/compose/Image.kt b/presentation/src/desktopMain/kotlin/ca/gosyer/ui/util/compose/Image.kt index c435d817..6234ec8e 100644 --- a/presentation/src/desktopMain/kotlin/ca/gosyer/ui/util/compose/Image.kt +++ b/presentation/src/desktopMain/kotlin/ca/gosyer/ui/util/compose/Image.kt @@ -13,13 +13,15 @@ import io.ktor.client.request.HttpRequestBuilder import io.ktor.client.request.get import io.ktor.utils.io.ByteReadChannel import io.ktor.utils.io.jvm.javaio.copyTo +import okio.FileSystem +import okio.Path +import okio.buffer import org.jetbrains.skia.Image import java.io.ByteArrayOutputStream -import java.nio.file.Path -import kotlin.io.path.readBytes fun imageFromFile(file: Path): ImageBitmap { - return Image.makeFromEncoded(file.readBytes()).toComposeImageBitmap() + return Image.makeFromEncoded(FileSystem.SYSTEM.source(file).buffer().readByteArray()) + .toComposeImageBitmap() } suspend fun imageFromUrl(client: Http, url: String, block: HttpRequestBuilder.() -> Unit): ImageBitmap { diff --git a/ui-core/build.gradle.kts b/ui-core/build.gradle.kts index 9a3ba7e7..7d0602e8 100644 --- a/ui-core/build.gradle.kts +++ b/ui-core/build.gradle.kts @@ -7,7 +7,13 @@ plugins { } kotlin { - android() + android { + compilations { + all { + kotlinOptions.jvmTarget = Config.androidJvmTarget.toString() + } + } + } jvm("desktop") { compilations { all { diff --git a/ui-core/src/androidMain/kotlin/ca/gosyer/uicore/resources/stringResource.kt b/ui-core/src/androidMain/kotlin/ca/gosyer/uicore/resources/stringResource.kt new file mode 100644 index 00000000..52806fb4 --- /dev/null +++ b/ui-core/src/androidMain/kotlin/ca/gosyer/uicore/resources/stringResource.kt @@ -0,0 +1,41 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package ca.gosyer.uicore.resources + +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalContext +import dev.icerock.moko.resources.PluralsResource +import dev.icerock.moko.resources.StringResource +import dev.icerock.moko.resources.desc.Plural +import dev.icerock.moko.resources.desc.PluralFormatted +import dev.icerock.moko.resources.desc.Resource +import dev.icerock.moko.resources.desc.ResourceFormatted +import dev.icerock.moko.resources.desc.StringDesc + +@Composable +actual fun stringResource(resource: StringResource): String { + val context = LocalContext.current + return StringDesc.Resource(resource).toString(context) +} + +@Composable +actual fun stringResource(resource: StringResource, vararg args: Any): String { + val context = LocalContext.current + return StringDesc.ResourceFormatted(resource, *args).toString(context) +} + +@Composable +actual fun stringResource(resource: PluralsResource, quantity: Int): String { + val context = LocalContext.current + return StringDesc.Plural(resource, quantity).toString(context) +} + +@Composable +actual fun stringResource(resource: PluralsResource, quantity: Int, vararg args: Any): String { + val context = LocalContext.current + return StringDesc.PluralFormatted(resource, quantity, *args).toString(context) +} diff --git a/ui-core/src/commonMain/kotlin/ca/gosyer/uicore/resources/StringResource.kt b/ui-core/src/commonMain/kotlin/ca/gosyer/uicore/resources/StringResource.kt new file mode 100644 index 00000000..7d9cc549 --- /dev/null +++ b/ui-core/src/commonMain/kotlin/ca/gosyer/uicore/resources/StringResource.kt @@ -0,0 +1,23 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package ca.gosyer.uicore.resources + +import androidx.compose.runtime.Composable +import dev.icerock.moko.resources.PluralsResource +import dev.icerock.moko.resources.StringResource + +@Composable +expect fun stringResource(resource: StringResource): String + +@Composable +expect fun stringResource(resource: StringResource, vararg args: Any): String + +@Composable +expect fun stringResource(resource: PluralsResource, quantity: Int): String + +@Composable +expect fun stringResource(resource: PluralsResource, quantity: Int, vararg args: Any): String diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/resources/StringResource.kt b/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/resources/StringResource.kt index d2b319f1..5e6a80e2 100644 --- a/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/resources/StringResource.kt +++ b/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/resources/StringResource.kt @@ -16,17 +16,17 @@ import dev.icerock.moko.resources.desc.ResourceFormatted import dev.icerock.moko.resources.desc.StringDesc @Composable -fun stringResource(resource: StringResource): String = +actual fun stringResource(resource: StringResource): String = StringDesc.Resource(resource).localized() @Composable -fun stringResource(resource: StringResource, vararg args: Any): String = +actual fun stringResource(resource: StringResource, vararg args: Any): String = StringDesc.ResourceFormatted(resource, *args).localized() @Composable -fun stringResource(resource: PluralsResource, quantity: Int): String = +actual fun stringResource(resource: PluralsResource, quantity: Int): String = StringDesc.Plural(resource, quantity).localized() @Composable -fun stringResource(resource: PluralsResource, quantity: Int, vararg args: Any): String = +actual fun stringResource(resource: PluralsResource, quantity: Int, vararg args: Any): String = StringDesc.PluralFormatted(resource, quantity, *args).localized() diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/components/DropdownIconButton.kt b/ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/components/DropdownIconButton.kt similarity index 100% rename from ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/components/DropdownIconButton.kt rename to ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/components/DropdownIconButton.kt diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/components/ErrorScreen.kt b/ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/components/ErrorScreen.kt similarity index 100% rename from ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/components/ErrorScreen.kt rename to ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/components/ErrorScreen.kt diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/components/LoadingScreen.kt b/ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/components/LoadingScreen.kt similarity index 100% rename from ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/components/LoadingScreen.kt rename to ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/components/LoadingScreen.kt diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/components/Manga.kt b/ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/components/Manga.kt similarity index 100% rename from ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/components/Manga.kt rename to ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/components/Manga.kt diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/components/MangaListItem.kt b/ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/components/MangaListItem.kt similarity index 100% rename from ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/components/MangaListItem.kt rename to ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/components/MangaListItem.kt diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/components/Spinner.kt b/ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/components/Spinner.kt similarity index 100% rename from ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/components/Spinner.kt rename to ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/components/Spinner.kt diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/image/KamelImage.kt b/ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/image/KamelImage.kt similarity index 100% rename from ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/image/KamelImage.kt rename to ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/image/KamelImage.kt diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/prefs/ColorPreference.kt b/ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/prefs/ColorPreference.kt similarity index 100% rename from ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/prefs/ColorPreference.kt rename to ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/prefs/ColorPreference.kt diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/prefs/IntStringPreference.kt b/ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/prefs/IntStringPreference.kt similarity index 100% rename from ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/prefs/IntStringPreference.kt rename to ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/prefs/IntStringPreference.kt diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/prefs/PreferenceMutableState.kt b/ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/prefs/PreferenceMutableState.kt similarity index 100% rename from ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/prefs/PreferenceMutableState.kt rename to ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/prefs/PreferenceMutableState.kt diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/theme/RandomColors.kt b/ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/theme/RandomColors.kt similarity index 100% rename from ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/theme/RandomColors.kt rename to ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/theme/RandomColors.kt diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/theme/Themes.kt b/ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/theme/Themes.kt similarity index 100% rename from ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/theme/Themes.kt rename to ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/theme/Themes.kt diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/vm/ComposeViewModel.kt b/ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/vm/ComposeViewModel.kt similarity index 100% rename from ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/vm/ComposeViewModel.kt rename to ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/vm/ComposeViewModel.kt diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/vm/ViewModel.kt b/ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/vm/ViewModel.kt similarity index 100% rename from ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/vm/ViewModel.kt rename to ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/vm/ViewModel.kt diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/vm/ViewModelFactory.kt b/ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/vm/ViewModelFactory.kt similarity index 100% rename from ui-core/src/desktopMain/kotlin/ca/gosyer/uicore/vm/ViewModelFactory.kt rename to ui-core/src/jvmMain/kotlin/ca/gosyer/uicore/vm/ViewModelFactory.kt