diff --git a/android/src/main/kotlin/ca/gosyer/jui/android/App.kt b/android/src/main/kotlin/ca/gosyer/jui/android/App.kt index f2e0ff93..d3270756 100644 --- a/android/src/main/kotlin/ca/gosyer/jui/android/App.kt +++ b/android/src/main/kotlin/ca/gosyer/jui/android/App.kt @@ -20,7 +20,9 @@ import kotlinx.coroutines.flow.launchIn import org.lighthousegames.logging.logging import java.util.Locale -class App : Application(), DefaultLifecycleObserver { +class App : + Application(), + DefaultLifecycleObserver { override fun onCreate() { super.onCreate() diff --git a/android/src/main/kotlin/ca/gosyer/jui/android/AppComponent.kt b/android/src/main/kotlin/ca/gosyer/jui/android/AppComponent.kt index 4baea889..c5f7f059 100644 --- a/android/src/main/kotlin/ca/gosyer/jui/android/AppComponent.kt +++ b/android/src/main/kotlin/ca/gosyer/jui/android/AppComponent.kt @@ -22,7 +22,10 @@ abstract class AppComponent( @get:AppScope @get:Provides val context: Context, -) : ViewModelComponent, DataComponent, DomainComponent, UiComponent { +) : ViewModelComponent, + DataComponent, + DomainComponent, + UiComponent { abstract val appMigrations: AppMigrations @get:AppScope diff --git a/android/src/main/kotlin/ca/gosyer/jui/android/data/download/AndroidDownloadService.kt b/android/src/main/kotlin/ca/gosyer/jui/android/data/download/AndroidDownloadService.kt index fa7f1f0c..600b518a 100644 --- a/android/src/main/kotlin/ca/gosyer/jui/android/data/download/AndroidDownloadService.kt +++ b/android/src/main/kotlin/ca/gosyer/jui/android/data/download/AndroidDownloadService.kt @@ -208,7 +208,10 @@ class AndroidDownloadService : Service() { val title = downloadingChapter.manga.title.chop(15) val quotedTitle = Pattern.quote(title) - val chapter = downloadingChapter.chapter.name.replaceFirst("$quotedTitle[\\s]*[-]*[\\s]*".toRegex(RegexOption.IGNORE_CASE), "") + val chapter = downloadingChapter.chapter.name.replaceFirst( + "$quotedTitle[\\s]*[-]*[\\s]*".toRegex(RegexOption.IGNORE_CASE), + "", + ) setContentTitle("$title - $chapter".chop(30)) setContentText( diff --git a/android/src/main/kotlin/ca/gosyer/jui/android/data/update/UpdateCheckWorker.kt b/android/src/main/kotlin/ca/gosyer/jui/android/data/update/UpdateCheckWorker.kt index ae795fb7..0647a9e3 100644 --- a/android/src/main/kotlin/ca/gosyer/jui/android/data/update/UpdateCheckWorker.kt +++ b/android/src/main/kotlin/ca/gosyer/jui/android/data/update/UpdateCheckWorker.kt @@ -23,9 +23,12 @@ import ca.gosyer.jui.i18n.MR import dev.icerock.moko.resources.desc.desc import java.util.concurrent.TimeUnit -class UpdateCheckWorker(private val context: Context, workerParams: WorkerParameters) : CoroutineWorker(context, workerParams) { - override suspend fun doWork(): Result { - return try { +class UpdateCheckWorker( + private val context: Context, + workerParams: WorkerParameters, +) : CoroutineWorker(context, workerParams) { + override suspend fun doWork(): Result = + try { val update = AppComponent.getInstance(context.applicationContext) .let { if (it.updatePreferences.enabled().get()) { @@ -48,7 +51,6 @@ class UpdateCheckWorker(private val context: Context, workerParams: WorkerParame } catch (e: Exception) { Result.failure() } - } companion object { private const val TAG = "UpdateChecker" diff --git a/core/src/androidMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt b/core/src/androidMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt index 692bc556..0dab11ab 100644 --- a/core/src/androidMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt +++ b/core/src/androidMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt @@ -12,9 +12,11 @@ import me.tatarka.inject.annotations.Inject actual class PreferenceStoreFactory @Inject - constructor(private val context: Context) { - actual fun create(vararg names: String): PreferenceStore { - return StandardPreferenceStore( + constructor( + private val context: Context, + ) { + actual fun create(vararg names: String): PreferenceStore = + StandardPreferenceStore( SharedPreferencesSettings( context.getSharedPreferences( names.joinToString(separator = "_"), @@ -22,5 +24,4 @@ actual class PreferenceStoreFactory ), ), ) - } } diff --git a/core/src/commonMain/kotlin/ca/gosyer/jui/core/io/OkioExtensions.kt b/core/src/commonMain/kotlin/ca/gosyer/jui/core/io/OkioExtensions.kt index 380f0090..e9014b94 100644 --- a/core/src/commonMain/kotlin/ca/gosyer/jui/core/io/OkioExtensions.kt +++ b/core/src/commonMain/kotlin/ca/gosyer/jui/core/io/OkioExtensions.kt @@ -35,6 +35,4 @@ suspend fun Source.copyTo(sink: BufferedSink) { } } -fun ByteArray.source(): BufferedSource { - return Buffer().write(this) -} +fun ByteArray.source(): BufferedSource = Buffer().write(this) diff --git a/core/src/commonMain/kotlin/ca/gosyer/jui/core/lang/CoroutineExtensions.kt b/core/src/commonMain/kotlin/ca/gosyer/jui/core/lang/CoroutineExtensions.kt index ad6aee28..f6952b63 100644 --- a/core/src/commonMain/kotlin/ca/gosyer/jui/core/lang/CoroutineExtensions.kt +++ b/core/src/commonMain/kotlin/ca/gosyer/jui/core/lang/CoroutineExtensions.kt @@ -54,7 +54,9 @@ suspend fun withUIContext(block: suspend CoroutineScope.() -> T): T = withCo suspend fun withIOContext(block: suspend CoroutineScope.() -> T): T = withContext(Dispatchers.IO, block) -fun Throwable.throwIfCancellation() { if (this is CancellationException) throw this } +fun Throwable.throwIfCancellation() { + if (this is CancellationException) throw this +} fun Result.throwIfCancellation(): Result { if (isFailure) { diff --git a/core/src/commonMain/kotlin/ca/gosyer/jui/core/lang/PriorityChannel.kt b/core/src/commonMain/kotlin/ca/gosyer/jui/core/lang/PriorityChannel.kt index fdee2fad..94ddc721 100644 --- a/core/src/commonMain/kotlin/ca/gosyer/jui/core/lang/PriorityChannel.kt +++ b/core/src/commonMain/kotlin/ca/gosyer/jui/core/lang/PriorityChannel.kt @@ -73,7 +73,10 @@ internal open class ProcessChannel( override fun offer(element: T): Boolean = inChannel.trySend(element).isSuccess @Deprecated( - "Deprecated in the favour of 'tryReceive'. Please note that the provided replacement does not rethrow channel's close cause as 'poll' did, for the precise replacement please refer to the 'poll' documentation", + "Deprecated in the favour of 'tryReceive'. " + + "Please note that the provided replacement does not rethrow " + + "channel's close cause as 'poll' did, for the precise replacement " + + "please refer to the 'poll' documentation", replaceWith = ReplaceWith("tryReceive().getOrNull()"), level = DeprecationLevel.ERROR, ) @@ -82,6 +85,7 @@ internal open class ProcessChannel( override suspend fun receive(): T = outChannel.receive() override suspend fun send(element: T) = inChannel.send(element) + override val onReceiveCatching: SelectClause1> get() = TODO("not implemented") @@ -105,16 +109,16 @@ internal class PriorityChannelImpl( scope: CoroutineScope, comparator: Comparator, ) : ProcessChannel( - // why a rendezvous channel should be the input channel? - // because we buffer and sort the messages in the co-routine - // that is where the capacity constraint is enforced - // and the buffer we keep sorted, the input channel we can't - inChannel = Channel(Channel.RENDEZVOUS), - // output channel is rendezvous channel because we may still - // get higher priority input meanwhile and we will send that - // when output consumer is ready to take it - outChannel = Channel(Channel.RENDEZVOUS), -) { + // why a rendezvous channel should be the input channel? + // because we buffer and sort the messages in the co-routine + // that is where the capacity constraint is enforced + // and the buffer we keep sorted, the input channel we can't + inChannel = Channel(Channel.RENDEZVOUS), + // output channel is rendezvous channel because we may still + // get higher priority input meanwhile and we will send that + // when output consumer is ready to take it + outChannel = Channel(Channel.RENDEZVOUS), + ) { private val buffer = PriorityQueue(comparator) private fun PriorityQueue.isNotFull() = this.size < maxCapacity diff --git a/core/src/commonMain/kotlin/ca/gosyer/jui/core/lang/String.kt b/core/src/commonMain/kotlin/ca/gosyer/jui/core/lang/String.kt index 9e795c91..9fab44c6 100644 --- a/core/src/commonMain/kotlin/ca/gosyer/jui/core/lang/String.kt +++ b/core/src/commonMain/kotlin/ca/gosyer/jui/core/lang/String.kt @@ -13,18 +13,16 @@ package ca.gosyer.jui.core.lang fun String.chop( count: Int, replacement: String = "…", -): String { - return if (length > count) { +): String = + if (length > count) { take(count - replacement.length) + replacement } else { this } -} -fun String.addSuffix(char: Char): String { - return if (endsWith(char)) { +fun String.addSuffix(char: Char): String = + if (endsWith(char)) { this } else { this + char } -} diff --git a/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/LazyPreferenceStore.kt b/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/LazyPreferenceStore.kt index 6bba50db..82c53401 100644 --- a/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/LazyPreferenceStore.kt +++ b/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/LazyPreferenceStore.kt @@ -22,9 +22,7 @@ class LazyPreferenceStore( override fun getString( key: String, defaultValue: String, - ): Preference { - return lazyStore.value.getString(key, defaultValue) - } + ): Preference = lazyStore.value.getString(key, defaultValue) /** * Returns a [Long] preference for this [key]. @@ -32,9 +30,7 @@ class LazyPreferenceStore( override fun getLong( key: String, defaultValue: Long, - ): Preference { - return lazyStore.value.getLong(key, defaultValue) - } + ): Preference = lazyStore.value.getLong(key, defaultValue) /** * Returns an [Int] preference for this [key]. @@ -42,9 +38,7 @@ class LazyPreferenceStore( override fun getInt( key: String, defaultValue: Int, - ): Preference { - return lazyStore.value.getInt(key, defaultValue) - } + ): Preference = lazyStore.value.getInt(key, defaultValue) /** * Returns a [Float] preference for this [key]. @@ -52,9 +46,7 @@ class LazyPreferenceStore( override fun getFloat( key: String, defaultValue: Float, - ): Preference { - return lazyStore.value.getFloat(key, defaultValue) - } + ): Preference = lazyStore.value.getFloat(key, defaultValue) /** * Returns a [Boolean] preference for this [key]. @@ -62,9 +54,7 @@ class LazyPreferenceStore( override fun getBoolean( key: String, defaultValue: Boolean, - ): Preference { - return lazyStore.value.getBoolean(key, defaultValue) - } + ): Preference = lazyStore.value.getBoolean(key, defaultValue) /** * Returns a [Set] preference for this [key]. @@ -72,9 +62,7 @@ class LazyPreferenceStore( override fun getStringSet( key: String, defaultValue: Set, - ): Preference> { - return lazyStore.value.getStringSet(key, defaultValue) - } + ): Preference> = lazyStore.value.getStringSet(key, defaultValue) /** * Returns preference of type [T] for this [key]. The [serializer] and [deserializer] function @@ -85,16 +73,12 @@ class LazyPreferenceStore( defaultValue: T, serializer: (T) -> String, deserializer: (String) -> T, - ): Preference { - return lazyStore.value.getObject(key, defaultValue, serializer, deserializer) - } + ): Preference = lazyStore.value.getObject(key, defaultValue, serializer, deserializer) override fun getJsonObject( key: String, defaultValue: T, serializer: KSerializer, serializersModule: SerializersModule, - ): Preference { - return lazyStore.value.getJsonObject(key, defaultValue, serializer) - } + ): Preference = lazyStore.value.getJsonObject(key, defaultValue, serializer) } diff --git a/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStore.kt b/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStore.kt index 6841fa0b..4953df97 100644 --- a/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStore.kt +++ b/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStore.kt @@ -91,8 +91,8 @@ interface PreferenceStore { inline fun > PreferenceStore.getEnum( key: String, defaultValue: T, -): Preference { - return getObject( +): Preference = + getObject( key, defaultValue, { it.name }, @@ -104,4 +104,3 @@ inline fun > PreferenceStore.getEnum( } }, ) -} diff --git a/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/StandardPreference.kt b/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/StandardPreference.kt index a413afff..5080946d 100644 --- a/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/StandardPreference.kt +++ b/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/StandardPreference.kt @@ -24,20 +24,17 @@ internal class StandardPreference( /** * Returns the key of this preference. */ - override fun key(): String { - return key - } + override fun key(): String = key /** * Returns the current value of this preference. */ - override fun get(): T { - return if (isSet()) { + override fun get(): T = + if (isSet()) { adapter.get(key, preferences) } else { defaultValue } - } /** * Sets a new [value] for this preference. @@ -49,9 +46,7 @@ internal class StandardPreference( /** * Returns whether there's an existing entry for this preference. */ - override fun isSet(): Boolean { - return adapter.isSet(preferences.keys, key) - } + override fun isSet(): Boolean = adapter.isSet(preferences.keys, key) /** * Deletes the entry of this preference. @@ -63,27 +58,22 @@ internal class StandardPreference( /** * Returns the default value of this preference */ - override fun defaultValue(): T { - return defaultValue - } + override fun defaultValue(): T = defaultValue /** * Returns a cold [Flow] of this preference to receive updates when its value changes. */ - override fun changes(): Flow { - return callbackFlow { + override fun changes(): Flow = + callbackFlow { val listener = adapter.addListener(key, preferences) { 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()) - } + override fun stateIn(scope: CoroutineScope): StateFlow = changes().stateIn(scope, SharingStarted.Eagerly, get()) } diff --git a/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/StandardPreferenceStore.kt b/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/StandardPreferenceStore.kt index 900f3054..2394de28 100644 --- a/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/StandardPreferenceStore.kt +++ b/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/StandardPreferenceStore.kt @@ -10,7 +10,9 @@ import com.russhwolf.settings.ObservableSettings import kotlinx.serialization.KSerializer import kotlinx.serialization.modules.SerializersModule -class StandardPreferenceStore(private val preferences: ObservableSettings) : PreferenceStore { +class StandardPreferenceStore( + private val preferences: ObservableSettings, +) : PreferenceStore { /** * Returns an [String] preference for this [key]. */ diff --git a/core/src/commonMain/kotlin/ca/gosyer/jui/core/util/ImageUtil.kt b/core/src/commonMain/kotlin/ca/gosyer/jui/core/util/ImageUtil.kt index 2f9913fb..be225b44 100644 --- a/core/src/commonMain/kotlin/ca/gosyer/jui/core/util/ImageUtil.kt +++ b/core/src/commonMain/kotlin/ca/gosyer/jui/core/util/ImageUtil.kt @@ -31,11 +31,12 @@ object ImageUtil { return true } - private fun charByteArrayOf(vararg bytes: Int): ByteArray { - return ByteArray(bytes.size) { pos -> bytes[pos].toByte() } - } + private fun charByteArrayOf(vararg bytes: Int): ByteArray = ByteArray(bytes.size) { pos -> bytes[pos].toByte() } - enum class ImageType(val mime: String, val extension: String) { + enum class ImageType( + val mime: String, + val extension: String, + ) { JPG("image/jpeg", "jpg"), PNG("image/png", "png"), GIF("image/gif", "gif"), diff --git a/core/src/desktopMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt b/core/src/desktopMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt index 56acda52..e19094f8 100644 --- a/core/src/desktopMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt +++ b/core/src/desktopMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt @@ -16,11 +16,10 @@ actual class PreferenceStoreFactory private val rootNode: Preferences = Preferences.userRoot() .node("ca/gosyer/tachideskjui") - actual fun create(vararg names: String): PreferenceStore { - return StandardPreferenceStore( + actual fun create(vararg names: String): PreferenceStore = + StandardPreferenceStore( PreferencesSettings( rootNode.node(names.joinToString(separator = "/")), ), ) - } } diff --git a/core/src/iosMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt b/core/src/iosMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt index f0556db4..50f14c0c 100644 --- a/core/src/iosMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt +++ b/core/src/iosMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt @@ -13,11 +13,10 @@ import platform.Foundation.NSUserDefaults actual class PreferenceStoreFactory @Inject constructor() { - actual fun create(vararg names: String): PreferenceStore { - return StandardPreferenceStore( + actual fun create(vararg names: String): PreferenceStore = + StandardPreferenceStore( NSUserDefaultsSettings( NSUserDefaults.standardUserDefaults, ), ) - } } diff --git a/data/src/commonMain/kotlin/ca/gosyer/jui/data/FlowConverterFactory.kt b/data/src/commonMain/kotlin/ca/gosyer/jui/data/FlowConverterFactory.kt index a26cabd9..6289557e 100644 --- a/data/src/commonMain/kotlin/ca/gosyer/jui/data/FlowConverterFactory.kt +++ b/data/src/commonMain/kotlin/ca/gosyer/jui/data/FlowConverterFactory.kt @@ -49,7 +49,5 @@ class FlowConverterFactory : Converter.Factory { override fun suspendResponseConverter( typeData: TypeData, ktorfit: Ktorfit, - ): Converter.SuspendResponseConverter? { - return null - } + ): Converter.SuspendResponseConverter? = null } diff --git a/desktop/src/main/kotlin/ca/gosyer/jui/desktop/AppComponent.kt b/desktop/src/main/kotlin/ca/gosyer/jui/desktop/AppComponent.kt index 1b847679..4e058aea 100644 --- a/desktop/src/main/kotlin/ca/gosyer/jui/desktop/AppComponent.kt +++ b/desktop/src/main/kotlin/ca/gosyer/jui/desktop/AppComponent.kt @@ -20,7 +20,10 @@ import me.tatarka.inject.annotations.Provides abstract class AppComponent( @get:Provides val context: ContextWrapper, -) : ViewModelComponent, DataComponent, DomainComponent, UiComponent { +) : ViewModelComponent, + DataComponent, + DomainComponent, + UiComponent { abstract val appMigrations: AppMigrations @get:AppScope diff --git a/desktop/src/main/kotlin/ca/gosyer/jui/desktop/logging/Slf4jLogFactory.kt b/desktop/src/main/kotlin/ca/gosyer/jui/desktop/logging/Slf4jLogFactory.kt index 16b3c221..5e7d762e 100644 --- a/desktop/src/main/kotlin/ca/gosyer/jui/desktop/logging/Slf4jLogFactory.kt +++ b/desktop/src/main/kotlin/ca/gosyer/jui/desktop/logging/Slf4jLogFactory.kt @@ -15,12 +15,12 @@ class Slf4jLogFactory : LogFactory { override fun createKmLog( tag: String, className: String, - ): KmLog { - return Slf4jLog(tag) - } + ): KmLog = Slf4jLog(tag) } -class Slf4jLog(tag: String) : KmLog(tag) { +class Slf4jLog( + tag: String, +) : KmLog(tag) { private val logger: Logger = LoggerFactory.getLogger(tag) override fun verbose( diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/backup/interactor/ExportBackupFile.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/backup/interactor/ExportBackupFile.kt index 2fc446a8..f8948197 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/backup/interactor/ExportBackupFile.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/backup/interactor/ExportBackupFile.kt @@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging class ExportBackupFile @Inject - constructor(private val backupRepository: BackupRepository) { + constructor( + private val backupRepository: BackupRepository, + ) { suspend fun await( block: HttpRequestBuilder.() -> Unit = {}, onError: suspend (Throwable) -> Unit = {}, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/backup/interactor/ImportBackupFile.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/backup/interactor/ImportBackupFile.kt index 6eb45adc..96843b6f 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/backup/interactor/ImportBackupFile.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/backup/interactor/ImportBackupFile.kt @@ -16,7 +16,9 @@ import org.lighthousegames.logging.logging class ImportBackupFile @Inject - constructor(private val backupRepository: BackupRepository) { + constructor( + private val backupRepository: BackupRepository, + ) { suspend fun await( file: Path, block: HttpRequestBuilder.() -> Unit = {}, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/backup/interactor/ValidateBackupFile.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/backup/interactor/ValidateBackupFile.kt index 23da9c97..dbe0f8a0 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/backup/interactor/ValidateBackupFile.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/backup/interactor/ValidateBackupFile.kt @@ -16,7 +16,9 @@ import org.lighthousegames.logging.logging class ValidateBackupFile @Inject - constructor(private val backupRepository: BackupRepository) { + constructor( + private val backupRepository: BackupRepository, + ) { suspend fun await( file: Path, block: HttpRequestBuilder.() -> Unit = {}, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/CreateCategory.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/CreateCategory.kt index fee63299..80c36d7a 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/CreateCategory.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/CreateCategory.kt @@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging class CreateCategory @Inject - constructor(private val categoryRepository: CategoryRepository) { + constructor( + private val categoryRepository: CategoryRepository, + ) { suspend fun await( name: String, onError: suspend (Throwable) -> Unit = {}, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/DeleteCategory.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/DeleteCategory.kt index 3be997da..0704cc75 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/DeleteCategory.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/DeleteCategory.kt @@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging class DeleteCategory @Inject - constructor(private val categoryRepository: CategoryRepository) { + constructor( + private val categoryRepository: CategoryRepository, + ) { suspend fun await( categoryId: Long, onError: suspend (Throwable) -> Unit = {}, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/GetCategories.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/GetCategories.kt index f774c862..7841d13a 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/GetCategories.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/GetCategories.kt @@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging class GetCategories @Inject - constructor(private val categoryRepository: CategoryRepository) { + constructor( + private val categoryRepository: CategoryRepository, + ) { suspend fun await( dropDefault: Boolean = false, onError: suspend (Throwable) -> Unit = {}, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/GetMangaCategories.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/GetMangaCategories.kt index 25bd5e29..1ed44476 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/GetMangaCategories.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/GetMangaCategories.kt @@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging class GetMangaCategories @Inject - constructor(private val categoryRepository: CategoryRepository) { + constructor( + private val categoryRepository: CategoryRepository, + ) { suspend fun await( mangaId: Long, onError: suspend (Throwable) -> Unit = {}, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/ModifyCategory.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/ModifyCategory.kt index a7fa2b7c..7864b9c1 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/ModifyCategory.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/ModifyCategory.kt @@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging class ModifyCategory @Inject - constructor(private val categoryRepository: CategoryRepository) { + constructor( + private val categoryRepository: CategoryRepository, + ) { suspend fun await( categoryId: Long, name: String, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/ReorderCategory.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/ReorderCategory.kt index 704b95b6..9f3ceeec 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/ReorderCategory.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/ReorderCategory.kt @@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging class ReorderCategory @Inject - constructor(private val categoryRepository: CategoryRepository) { + constructor( + private val categoryRepository: CategoryRepository, + ) { suspend fun await( to: Int, from: Int, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/UpdateCategoryMeta.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/UpdateCategoryMeta.kt index ff4e09df..21f91de9 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/UpdateCategoryMeta.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/interactor/UpdateCategoryMeta.kt @@ -16,7 +16,9 @@ import org.lighthousegames.logging.logging class UpdateCategoryMeta @Inject - constructor(private val categoryRepository: CategoryRepository) { + constructor( + private val categoryRepository: CategoryRepository, + ) { suspend fun await( category: Category, example: Int = category.meta.example, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/chapter/interactor/GetChapterPage.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/chapter/interactor/GetChapterPage.kt index 183dcecf..de2958d0 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/chapter/interactor/GetChapterPage.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/chapter/interactor/GetChapterPage.kt @@ -17,7 +17,9 @@ import org.lighthousegames.logging.logging class GetChapterPage @Inject - constructor(private val chapterRepository: ChapterRepository) { + constructor( + private val chapterRepository: ChapterRepository, + ) { suspend fun await( mangaId: Long, index: Int, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/BatchChapterDownload.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/BatchChapterDownload.kt index 38d8e446..78299023 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/BatchChapterDownload.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/BatchChapterDownload.kt @@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging class BatchChapterDownload @Inject - constructor(private val downloadRepository: DownloadRepository) { + constructor( + private val downloadRepository: DownloadRepository, + ) { suspend fun await( chapterIds: List, onError: suspend (Throwable) -> Unit = {}, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/ClearDownloadQueue.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/ClearDownloadQueue.kt index f78ddb78..28352181 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/ClearDownloadQueue.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/ClearDownloadQueue.kt @@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging class ClearDownloadQueue @Inject - constructor(private val downloadRepository: DownloadRepository) { + constructor( + private val downloadRepository: DownloadRepository, + ) { suspend fun await(onError: suspend (Throwable) -> Unit = {}) = asFlow() .catch { diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/QueueChapterDownload.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/QueueChapterDownload.kt index 2e23f7d8..8eebf3a7 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/QueueChapterDownload.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/QueueChapterDownload.kt @@ -16,7 +16,9 @@ import org.lighthousegames.logging.logging class QueueChapterDownload @Inject - constructor(private val downloadRepository: DownloadRepository) { + constructor( + private val downloadRepository: DownloadRepository, + ) { suspend fun await( mangaId: Long, index: Int, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/ReorderChapterDownload.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/ReorderChapterDownload.kt index 0c75386c..bd45980c 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/ReorderChapterDownload.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/ReorderChapterDownload.kt @@ -16,7 +16,9 @@ import org.lighthousegames.logging.logging class ReorderChapterDownload @Inject - constructor(private val downloadRepository: DownloadRepository) { + constructor( + private val downloadRepository: DownloadRepository, + ) { suspend fun await( mangaId: Long, index: Int, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/StartDownloading.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/StartDownloading.kt index 28de377f..c15e3a3f 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/StartDownloading.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/StartDownloading.kt @@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging class StartDownloading @Inject - constructor(private val downloadRepository: DownloadRepository) { + constructor( + private val downloadRepository: DownloadRepository, + ) { suspend fun await(onError: suspend (Throwable) -> Unit = {}) = asFlow() .catch { diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/StopChapterDownload.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/StopChapterDownload.kt index fb1ef93c..d6525b44 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/StopChapterDownload.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/StopChapterDownload.kt @@ -16,7 +16,9 @@ import org.lighthousegames.logging.logging class StopChapterDownload @Inject - constructor(private val downloadRepository: DownloadRepository) { + constructor( + private val downloadRepository: DownloadRepository, + ) { suspend fun await( mangaId: Long, index: Int, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/StopDownloading.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/StopDownloading.kt index b8af6c35..a43e8769 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/StopDownloading.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/interactor/StopDownloading.kt @@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging class StopDownloading @Inject - constructor(private val downloadRepository: DownloadRepository) { + constructor( + private val downloadRepository: DownloadRepository, + ) { suspend fun await(onError: suspend (Throwable) -> Unit = {}) = asFlow() .catch { diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/model/DownloadState.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/model/DownloadState.kt index 8dfba077..f0e9eaf3 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/model/DownloadState.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/model/DownloadState.kt @@ -11,7 +11,9 @@ import kotlinx.serialization.Serializable @Serializable @Stable -enum class DownloadState(val state: Int) { +enum class DownloadState( + val state: Int, +) { Queued(0), Downloading(1), Finished(2), diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/service/DownloadService.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/service/DownloadService.kt index e8f440d3..1371890c 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/service/DownloadService.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/service/DownloadService.kt @@ -47,6 +47,7 @@ class DownloadService .map { it.filter { it.mangaId == mangaId } } + fun registerWatches(mangaIds: Set) = downloadQueue .map { diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/GetExtensionList.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/GetExtensionList.kt index 7d623425..c1f535eb 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/GetExtensionList.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/GetExtensionList.kt @@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging class GetExtensionList @Inject - constructor(private val extensionRepository: ExtensionRepository) { + constructor( + private val extensionRepository: ExtensionRepository, + ) { suspend fun await(onError: suspend (Throwable) -> Unit = {}) = asFlow() .catch { diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/InstallExtension.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/InstallExtension.kt index 0a3a22e2..cb157c18 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/InstallExtension.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/InstallExtension.kt @@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging class InstallExtension @Inject - constructor(private val extensionRepository: ExtensionRepository) { + constructor( + private val extensionRepository: ExtensionRepository, + ) { suspend fun await( extension: Extension, onError: suspend (Throwable) -> Unit = {}, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/InstallExtensionFile.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/InstallExtensionFile.kt index 5a937e5f..28a4f38d 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/InstallExtensionFile.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/InstallExtensionFile.kt @@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging class InstallExtensionFile @Inject - constructor(private val extensionRepository: ExtensionRepository) { + constructor( + private val extensionRepository: ExtensionRepository, + ) { suspend fun await( path: Path, onError: suspend (Throwable) -> Unit = {}, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/UninstallExtension.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/UninstallExtension.kt index 9c332b2a..1a84e122 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/UninstallExtension.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/UninstallExtension.kt @@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging class UninstallExtension @Inject - constructor(private val extensionRepository: ExtensionRepository) { + constructor( + private val extensionRepository: ExtensionRepository, + ) { suspend fun await( extension: Extension, onError: suspend (Throwable) -> Unit = {}, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/UpdateExtension.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/UpdateExtension.kt index 328b70fb..8e4a9821 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/UpdateExtension.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/interactor/UpdateExtension.kt @@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging class UpdateExtension @Inject - constructor(private val extensionRepository: ExtensionRepository) { + constructor( + private val extensionRepository: ExtensionRepository, + ) { suspend fun await( extension: Extension, onError: suspend (Throwable) -> Unit = {}, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/service/ExtensionPreferences.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/service/ExtensionPreferences.kt index 310b666c..f9137600 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/service/ExtensionPreferences.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/service/ExtensionPreferences.kt @@ -10,8 +10,12 @@ import androidx.compose.ui.text.intl.Locale import ca.gosyer.jui.core.prefs.Preference import ca.gosyer.jui.core.prefs.PreferenceStore -class ExtensionPreferences(private val preferenceStore: PreferenceStore) { - fun languages(): Preference> { - return preferenceStore.getStringSet("enabled_langs", setOfNotNull("all", "en", Locale.current.language)) - } +class ExtensionPreferences( + private val preferenceStore: PreferenceStore, +) { + fun languages(): Preference> = + preferenceStore.getStringSet( + "enabled_langs", + setOfNotNull("all", "en", Locale.current.language), + ) } diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/global/interactor/GetGlobalMeta.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/global/interactor/GetGlobalMeta.kt index b2a9de7c..1a43770a 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/global/interactor/GetGlobalMeta.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/global/interactor/GetGlobalMeta.kt @@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging class GetGlobalMeta @Inject - constructor(private val globalRepository: GlobalRepository) { + constructor( + private val globalRepository: GlobalRepository, + ) { suspend fun await(onError: suspend (Throwable) -> Unit = {}) = asFlow() .catch { diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/global/interactor/UpdateGlobalMeta.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/global/interactor/UpdateGlobalMeta.kt index 436567c7..7f67d1fa 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/global/interactor/UpdateGlobalMeta.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/global/interactor/UpdateGlobalMeta.kt @@ -16,7 +16,9 @@ import org.lighthousegames.logging.logging class UpdateGlobalMeta @Inject - constructor(private val globalRepository: GlobalRepository) { + constructor( + private val globalRepository: GlobalRepository, + ) { suspend fun await( globalMeta: GlobalMeta, example: Int = globalMeta.example, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/library/service/LibraryPreferences.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/library/service/LibraryPreferences.kt index d14d902e..1caaeba0 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/library/service/LibraryPreferences.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/library/service/LibraryPreferences.kt @@ -11,56 +11,52 @@ import ca.gosyer.jui.core.prefs.PreferenceStore import ca.gosyer.jui.domain.library.model.FilterState import ca.gosyer.jui.domain.library.model.Sort -class LibraryPreferences(private val preferenceStore: PreferenceStore) { - fun showAllCategory(): Preference { - return preferenceStore.getBoolean("show_all_category", false) - } +class LibraryPreferences( + private val preferenceStore: PreferenceStore, +) { + fun showAllCategory(): Preference = preferenceStore.getBoolean("show_all_category", false) - fun filterDownloaded(): Preference { - return preferenceStore.getJsonObject("filter_downloaded", FilterState.IGNORED, FilterState.serializer()) - } + fun filterDownloaded(): Preference = + preferenceStore.getJsonObject( + "filter_downloaded", + FilterState.IGNORED, + FilterState.serializer(), + ) - fun filterUnread(): Preference { - return preferenceStore.getJsonObject("filter_unread", FilterState.IGNORED, FilterState.serializer()) - } + fun filterUnread(): Preference = + preferenceStore.getJsonObject( + "filter_unread", + FilterState.IGNORED, + FilterState.serializer(), + ) - fun filterCompleted(): Preference { - return preferenceStore.getJsonObject("filter_completed", FilterState.IGNORED, FilterState.serializer()) - } + fun filterCompleted(): Preference = + preferenceStore.getJsonObject( + "filter_completed", + FilterState.IGNORED, + FilterState.serializer(), + ) - fun sortMode(): Preference { - return preferenceStore.getJsonObject("sort_mode", Sort.ALPHABETICAL, Sort.serializer()) - } + fun sortMode(): Preference = preferenceStore.getJsonObject("sort_mode", Sort.ALPHABETICAL, Sort.serializer()) - fun sortAscending(): Preference { - return preferenceStore.getBoolean("sort_ascending", true) - } + fun sortAscending(): Preference = preferenceStore.getBoolean("sort_ascending", true) - fun displayMode(): Preference { - return preferenceStore.getJsonObject("display_mode", ca.gosyer.jui.domain.library.model.DisplayMode.CompactGrid, ca.gosyer.jui.domain.library.model.DisplayMode.serializer()) - } + fun displayMode(): Preference = + preferenceStore.getJsonObject( + "display_mode", + ca.gosyer.jui.domain.library.model.DisplayMode.CompactGrid, + ca.gosyer.jui.domain.library.model.DisplayMode.serializer(), + ) - fun gridColumns(): Preference { - return preferenceStore.getInt("grid_columns", 0) - } + fun gridColumns(): Preference = preferenceStore.getInt("grid_columns", 0) - fun gridSize(): Preference { - return preferenceStore.getInt("grid_size", 160) - } + fun gridSize(): Preference = preferenceStore.getInt("grid_size", 160) - fun unreadBadge(): Preference { - return preferenceStore.getBoolean("unread_badge", true) - } + fun unreadBadge(): Preference = preferenceStore.getBoolean("unread_badge", true) - fun downloadBadge(): Preference { - return preferenceStore.getBoolean("download_badge", false) - } + fun downloadBadge(): Preference = preferenceStore.getBoolean("download_badge", false) - fun languageBadge(): Preference { - return preferenceStore.getBoolean("language_badge", false) - } + fun languageBadge(): Preference = preferenceStore.getBoolean("language_badge", false) - fun localBadge(): Preference { - return preferenceStore.getBoolean("local_badge", false) - } + fun localBadge(): Preference = preferenceStore.getBoolean("local_badge", false) } diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/migration/service/MigrationPreferences.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/migration/service/MigrationPreferences.kt index 3bea8e9b..a3b1ed93 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/migration/service/MigrationPreferences.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/migration/service/MigrationPreferences.kt @@ -9,11 +9,10 @@ package ca.gosyer.jui.domain.migration.service import ca.gosyer.jui.core.prefs.Preference import ca.gosyer.jui.core.prefs.PreferenceStore -class MigrationPreferences(private val preferenceStore: PreferenceStore) { - fun version(): Preference { - return preferenceStore.getInt("version", 0) - } - fun appVersion(): Preference { - return preferenceStore.getInt("app_version", 0) - } +class MigrationPreferences( + private val preferenceStore: PreferenceStore, +) { + fun version(): Preference = preferenceStore.getInt("version", 0) + + fun appVersion(): Preference = preferenceStore.getInt("app_version", 0) } diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/reader/model/TappingInvertMode.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/reader/model/TappingInvertMode.kt index bd729d63..6f97e69d 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/reader/model/TappingInvertMode.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/reader/model/TappingInvertMode.kt @@ -11,7 +11,10 @@ import kotlinx.serialization.Serializable @Serializable @Stable -enum class TappingInvertMode(val shouldInvertHorizontal: Boolean = false, val shouldInvertVertical: Boolean = false) { +enum class TappingInvertMode( + val shouldInvertHorizontal: Boolean = false, + val shouldInvertVertical: Boolean = false, +) { NONE, HORIZONTAL(shouldInvertHorizontal = true), VERTICAL(shouldInvertVertical = true), diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/reader/service/ReaderModePreferences.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/reader/service/ReaderModePreferences.kt index 7d2ce5e6..4fcdb46e 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/reader/service/ReaderModePreferences.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/reader/service/ReaderModePreferences.kt @@ -13,38 +13,39 @@ import ca.gosyer.jui.domain.reader.model.Direction import ca.gosyer.jui.domain.reader.model.ImageScale import ca.gosyer.jui.domain.reader.model.NavigationMode -class ReaderModePreferences(private val mode: String, private val preferenceStore: PreferenceStore) { +class ReaderModePreferences( + private val mode: String, + private val preferenceStore: PreferenceStore, +) { constructor(mode: String, factory: (String) -> PreferenceStore) : this(mode, factory(mode)) private val defaultMode by lazy { DefaultReaderMode.values().find { it.res == mode } } - fun default(): Preference { - return preferenceStore.getBoolean("default", defaultMode != null) - } + fun default(): Preference = preferenceStore.getBoolean("default", defaultMode != null) - fun continuous(): Preference { - return preferenceStore.getBoolean("continuous", defaultMode?.continuous ?: false) - } + fun continuous(): Preference = preferenceStore.getBoolean("continuous", defaultMode?.continuous ?: false) - fun direction(): Preference { - return preferenceStore.getJsonObject("direction", defaultMode?.direction ?: Direction.Down, Direction.serializer()) - } + fun direction(): Preference = + preferenceStore.getJsonObject( + "direction", + defaultMode?.direction ?: Direction.Down, + Direction.serializer(), + ) - fun padding(): Preference { - return preferenceStore.getInt("padding", defaultMode?.padding ?: 0) - } + fun padding(): Preference = preferenceStore.getInt("padding", defaultMode?.padding ?: 0) - fun imageScale(): Preference { - return preferenceStore.getJsonObject("image_scale", defaultMode?.imageScale ?: ImageScale.FitScreen, ImageScale.serializer()) - } + fun imageScale(): Preference = + preferenceStore.getJsonObject( + "image_scale", + defaultMode?.imageScale ?: ImageScale.FitScreen, + ImageScale.serializer(), + ) - fun fitSize(): Preference { - return preferenceStore.getBoolean("fit_size", false) - } + fun fitSize(): Preference = preferenceStore.getBoolean("fit_size", false) - fun maxSize(): Preference { - return preferenceStore.getInt( + fun maxSize(): Preference = + preferenceStore.getInt( "max_size", if (defaultMode?.continuous == true) { if (defaultMode?.direction == Direction.Left || defaultMode?.direction == Direction.Right) { @@ -56,9 +57,11 @@ class ReaderModePreferences(private val mode: String, private val preferenceStor 0 }, ) - } - fun navigationMode(): Preference { - return preferenceStore.getJsonObject("navigation", defaultMode?.navigationMode ?: NavigationMode.LNavigation, NavigationMode.serializer()) - } + fun navigationMode(): Preference = + preferenceStore.getJsonObject( + "navigation", + defaultMode?.navigationMode ?: NavigationMode.LNavigation, + NavigationMode.serializer(), + ) } diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/reader/service/ReaderPreferences.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/reader/service/ReaderPreferences.kt index 2053e61f..4dcb4492 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/reader/service/ReaderPreferences.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/reader/service/ReaderPreferences.kt @@ -12,28 +12,22 @@ import ca.gosyer.jui.domain.reader.model.DefaultReaderMode import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.builtins.serializer -class ReaderPreferences(private val preferenceStore: PreferenceStore, private val factory: (String) -> PreferenceStore) { - fun preload(): Preference { - return preferenceStore.getInt("preload", 3) - } +class ReaderPreferences( + private val preferenceStore: PreferenceStore, + private val factory: (String) -> PreferenceStore, +) { + fun preload(): Preference = preferenceStore.getInt("preload", 3) - fun threads(): Preference { - return preferenceStore.getInt("threads", 3) - } + fun threads(): Preference = preferenceStore.getInt("threads", 3) - fun modes(): Preference> { - return preferenceStore.getJsonObject( + fun modes(): Preference> = + preferenceStore.getJsonObject( "modes", DefaultReaderMode.values().map { it.res }, ListSerializer(String.serializer()), ) - } - fun mode(): Preference { - return preferenceStore.getString("mode", "RTL") - } + fun mode(): Preference = preferenceStore.getString("mode", "RTL") - fun getMode(mode: String): ReaderModePreferences { - return ReaderModePreferences(mode, factory) - } + fun getMode(mode: String): ReaderModePreferences = ReaderModePreferences(mode, factory) } diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/server/HttpClient.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/server/HttpClient.kt index 98805968..b20022c5 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/server/HttpClient.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/server/HttpClient.kt @@ -44,8 +44,8 @@ expect fun HttpClientConfig.configurePlatform() fun httpClient( serverPreferences: ServerPreferences, json: Json, -): Http { - return HttpClient(Engine) { +): Http = + HttpClient(Engine) { configurePlatform() expectSuccess = true @@ -112,10 +112,10 @@ fun httpClient( } logger = object : Logger { val log = logging("HttpClient") + override fun log(message: String) { log.info { message } } } } } -} diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/server/model/ServerUrlPreference.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/server/model/ServerUrlPreference.kt index 4c808459..367bebd2 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/server/model/ServerUrlPreference.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/server/model/ServerUrlPreference.kt @@ -25,18 +25,15 @@ class ServerUrlPreference( private val port: Preference, private val pathPrefix: Preference, ) : Preference { - override fun key(): String { - return key - } + override fun key(): String = key - override fun get(): Url { - return URLBuilder(server.get()).apply { + override fun get(): Url = + URLBuilder(server.get()).apply { port = this@ServerUrlPreference.port.get() if (pathPrefix.isSet()) { pathPrefix.get().ifBlank { null }?.let { path(it) } } }.build() - } override fun set(value: Url) { server.set(value.protocol.name + "://" + value.host) @@ -44,9 +41,7 @@ class ServerUrlPreference( pathPrefix.set(value.encodedPath) } - override fun isSet(): Boolean { - return server.isSet() || port.isSet() || pathPrefix.isSet() - } + override fun isSet(): Boolean = server.isSet() || port.isSet() || pathPrefix.isSet() override fun delete() { server.delete() @@ -54,14 +49,13 @@ class ServerUrlPreference( pathPrefix.delete() } - override fun defaultValue(): Url { - return URLBuilder(server.defaultValue()).apply { + override fun defaultValue(): Url = + URLBuilder(server.defaultValue()).apply { port = this@ServerUrlPreference.port.defaultValue() }.build() - } - override fun changes(): Flow { - return combine(server.getAsFlow(), port.getAsFlow(), pathPrefix.getAsFlow()) { server, port, pathPrefix -> + override fun changes(): Flow = + combine(server.getAsFlow(), port.getAsFlow(), pathPrefix.getAsFlow()) { server, port, pathPrefix -> URLBuilder(server).apply { this.port = port if (pathPrefix.isNotBlank()) { @@ -69,9 +63,6 @@ class ServerUrlPreference( } }.build() }.drop(1) - } - override fun stateIn(scope: CoroutineScope): StateFlow { - return changes().stateIn(scope, SharingStarted.Eagerly, get()) - } + override fun stateIn(scope: CoroutineScope): StateFlow = changes().stateIn(scope, SharingStarted.Eagerly, get()) } diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/server/service/ServerPreferences.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/server/service/ServerPreferences.kt index f1f7437e..612167b7 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/server/service/ServerPreferences.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/server/service/ServerPreferences.kt @@ -13,51 +13,30 @@ import ca.gosyer.jui.domain.server.model.Proxy import ca.gosyer.jui.domain.server.model.ServerUrlPreference import io.ktor.http.Url -class ServerPreferences(private val preferenceStore: PreferenceStore) { - fun server(): Preference { - return preferenceStore.getString("server_url", "http://localhost") - } +class ServerPreferences( + private val preferenceStore: PreferenceStore, +) { + fun server(): Preference = preferenceStore.getString("server_url", "http://localhost") - fun port(): Preference { - return preferenceStore.getInt("server_port", 4567) - } + fun port(): Preference = preferenceStore.getInt("server_port", 4567) - fun pathPrefix(): Preference { - return preferenceStore.getString("server_path_prefix", "") - } + fun pathPrefix(): Preference = preferenceStore.getString("server_path_prefix", "") - fun serverUrl(): Preference { - return ServerUrlPreference("", server(), port(), pathPrefix()) - } + fun serverUrl(): Preference = ServerUrlPreference("", server(), port(), pathPrefix()) - fun proxy(): Preference { - return preferenceStore.getJsonObject("proxy", Proxy.NO_PROXY, Proxy.serializer()) - } + fun proxy(): Preference = preferenceStore.getJsonObject("proxy", Proxy.NO_PROXY, Proxy.serializer()) - fun proxyHttpHost(): Preference { - return preferenceStore.getString("proxy_http_host") - } + fun proxyHttpHost(): Preference = preferenceStore.getString("proxy_http_host") - fun proxyHttpPort(): Preference { - return preferenceStore.getInt("proxy_http_port") - } + fun proxyHttpPort(): Preference = preferenceStore.getInt("proxy_http_port") - fun proxySocksHost(): Preference { - return preferenceStore.getString("proxy_socks_host") - } + fun proxySocksHost(): Preference = preferenceStore.getString("proxy_socks_host") - fun proxySocksPort(): Preference { - return preferenceStore.getInt("proxy_socks_port") - } + fun proxySocksPort(): Preference = preferenceStore.getInt("proxy_socks_port") - fun auth(): Preference { - return preferenceStore.getJsonObject("auth", Auth.NONE, Auth.serializer()) - } + fun auth(): Preference = preferenceStore.getJsonObject("auth", Auth.NONE, Auth.serializer()) - fun authUsername(): Preference { - return preferenceStore.getString("auth_username") - } - fun authPassword(): Preference { - return preferenceStore.getString("auth_password") - } + fun authUsername(): Preference = preferenceStore.getString("auth_username") + + fun authPassword(): Preference = preferenceStore.getString("auth_password") } diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/interactor/AboutServer.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/interactor/AboutServer.kt index 3c83807f..5e3dc412 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/interactor/AboutServer.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/interactor/AboutServer.kt @@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging class AboutServer @Inject - constructor(private val settingsRepository: SettingsRepository) { + constructor( + private val settingsRepository: SettingsRepository, + ) { suspend fun await(onError: suspend (Throwable) -> Unit = {}) = asFlow() .catch { diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/interactor/CheckUpdate.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/interactor/CheckUpdate.kt index 4de2aa77..5dad9573 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/interactor/CheckUpdate.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/interactor/CheckUpdate.kt @@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging class CheckUpdate @Inject - constructor(private val settingsRepository: SettingsRepository) { + constructor( + private val settingsRepository: SettingsRepository, + ) { suspend fun await(onError: suspend (Throwable) -> Unit = {}) = asFlow() .catch { diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetFilterList.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetFilterList.kt index 3555b216..fa9f3a34 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetFilterList.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetFilterList.kt @@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging class GetFilterList @Inject - constructor(private val sourceRepository: SourceRepository) { + constructor( + private val sourceRepository: SourceRepository, + ) { suspend fun await( source: Source, reset: Boolean, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetLatestManga.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetLatestManga.kt index be0ce6e9..a5cabf65 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetLatestManga.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetLatestManga.kt @@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging class GetLatestManga @Inject - constructor(private val sourceRepository: SourceRepository) { + constructor( + private val sourceRepository: SourceRepository, + ) { suspend fun await( source: Source, page: Int, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetPopularManga.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetPopularManga.kt index a87c5d90..2fd6b75f 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetPopularManga.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetPopularManga.kt @@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging class GetPopularManga @Inject - constructor(private val sourceRepository: SourceRepository) { + constructor( + private val sourceRepository: SourceRepository, + ) { suspend fun await( source: Source, page: Int, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetQuickSearchManga.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetQuickSearchManga.kt index b250e066..7566d881 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetQuickSearchManga.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetQuickSearchManga.kt @@ -17,7 +17,9 @@ import org.lighthousegames.logging.logging class GetQuickSearchManga @Inject - constructor(private val sourceRepository: SourceRepository) { + constructor( + private val sourceRepository: SourceRepository, + ) { suspend fun await( source: Source, searchTerm: String?, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetSearchManga.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetSearchManga.kt index d3cd447f..ab7bedaa 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetSearchManga.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetSearchManga.kt @@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging class GetSearchManga @Inject - constructor(private val sourceRepository: SourceRepository) { + constructor( + private val sourceRepository: SourceRepository, + ) { suspend fun await( source: Source, searchTerm: String?, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetSourceList.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetSourceList.kt index 31514f77..4954093c 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetSourceList.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetSourceList.kt @@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging class GetSourceList @Inject - constructor(private val sourceRepository: SourceRepository) { + constructor( + private val sourceRepository: SourceRepository, + ) { suspend fun await(onError: suspend (Throwable) -> Unit = {}) = asFlow() .catch { diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetSourceSettings.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetSourceSettings.kt index 125513d5..c77c2d81 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetSourceSettings.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/GetSourceSettings.kt @@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging class GetSourceSettings @Inject - constructor(private val sourceRepository: SourceRepository) { + constructor( + private val sourceRepository: SourceRepository, + ) { suspend fun await( source: Source, onError: suspend (Throwable) -> Unit = {}, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/SetSourceFilter.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/SetSourceFilter.kt index 81f62c0b..0109ebcb 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/SetSourceFilter.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/SetSourceFilter.kt @@ -18,7 +18,9 @@ import org.lighthousegames.logging.logging class SetSourceFilter @Inject - constructor(private val sourceRepository: SourceRepository) { + constructor( + private val sourceRepository: SourceRepository, + ) { suspend fun await( source: Source, filterIndex: Int, @@ -56,7 +58,8 @@ class SetSourceFilter .catch { onError(it) log.warn(it) { - "Failed to set filter for ${source.displayName} with index = $filterIndex and childIndex = $childFilterIndex and value = $filter" + "Failed to set filter for ${source.displayName} with index = $filterIndex " + + "and childIndex = $childFilterIndex and value = $filter" } } .collect() @@ -71,7 +74,10 @@ class SetSourceFilter ) = asFlow(sourceId, filterIndex, childFilterIndex, filter) .catch { onError(it) - log.warn(it) { "Failed to set filter for $sourceId with index = $filterIndex and childIndex = $childFilterIndex and value = $filter" } + log.warn(it) { + "Failed to set filter for $sourceId with index = $filterIndex " + + "and childIndex = $childFilterIndex and value = $filter" + } } .collect() diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/SetSourceSetting.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/SetSourceSetting.kt index 4b2f7bb5..2b753c03 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/SetSourceSetting.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/interactor/SetSourceSetting.kt @@ -16,7 +16,9 @@ import org.lighthousegames.logging.logging class SetSourceSetting @Inject - constructor(private val sourceRepository: SourceRepository) { + constructor( + private val sourceRepository: SourceRepository, + ) { suspend fun await( source: Source, settingIndex: Int, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/model/sourcefilters/SourceFilterChange.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/model/sourcefilters/SourceFilterChange.kt index ad093ec8..0ef1c5e2 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/model/sourcefilters/SourceFilterChange.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/model/sourcefilters/SourceFilterChange.kt @@ -11,7 +11,10 @@ import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json @Serializable -data class SourceFilterChange(val position: Int, val state: String) { +data class SourceFilterChange( + val position: Int, + val state: String, +) { constructor(position: Int, state: Any) : this( position, if (state is SortFilter.Selection) { diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/model/sourcepreference/ListPreference.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/model/sourcepreference/ListPreference.kt index 1a86c97b..3bca70f3 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/model/sourcepreference/ListPreference.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/model/sourcepreference/ListPreference.kt @@ -13,7 +13,9 @@ import kotlinx.serialization.Serializable @Serializable @SerialName("ListPreference") @Immutable -data class ListPreference(override val props: ListProps) : SourcePreference() { +data class ListPreference( + override val props: ListProps, +) : SourcePreference() { @Serializable @Immutable data class ListProps( diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/model/sourcepreference/MultiSelectListPreference.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/model/sourcepreference/MultiSelectListPreference.kt index 85f180b9..292d51b4 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/model/sourcepreference/MultiSelectListPreference.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/model/sourcepreference/MultiSelectListPreference.kt @@ -13,7 +13,9 @@ import kotlinx.serialization.Serializable @Serializable @SerialName("MultiSelectListPreference") @Immutable -data class MultiSelectListPreference(override val props: MultiSelectListProps) : SourcePreference() { +data class MultiSelectListPreference( + override val props: MultiSelectListProps, +) : SourcePreference() { @Serializable @Immutable data class MultiSelectListProps( diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/model/sourcepreference/SourcePreferenceChange.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/model/sourcepreference/SourcePreferenceChange.kt index 36da9304..f1840910 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/model/sourcepreference/SourcePreferenceChange.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/model/sourcepreference/SourcePreferenceChange.kt @@ -11,7 +11,10 @@ import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json @Serializable -data class SourcePreferenceChange(val position: Int, val value: String) { +data class SourcePreferenceChange( + val position: Int, + val value: String, +) { constructor(position: Int, value: Any) : this( position, if (value is List<*>) { diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/service/CatalogPreferences.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/service/CatalogPreferences.kt index 79aabd0a..a292768b 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/service/CatalogPreferences.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/service/CatalogPreferences.kt @@ -11,12 +11,15 @@ import ca.gosyer.jui.core.prefs.Preference import ca.gosyer.jui.core.prefs.PreferenceStore import ca.gosyer.jui.domain.library.model.DisplayMode -class CatalogPreferences(private val preferenceStore: PreferenceStore) { - fun languages(): Preference> { - return preferenceStore.getStringSet("enabled_langs", setOfNotNull("en", Locale.current.language)) - } +class CatalogPreferences( + private val preferenceStore: PreferenceStore, +) { + fun languages(): Preference> = preferenceStore.getStringSet("enabled_langs", setOfNotNull("en", Locale.current.language)) - fun displayMode(): Preference { - return preferenceStore.getJsonObject("display_mode", DisplayMode.CompactGrid, DisplayMode.serializer()) - } + fun displayMode(): Preference = + preferenceStore.getJsonObject( + "display_mode", + DisplayMode.CompactGrid, + DisplayMode.serializer(), + ) } diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/ui/service/UiPreferences.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/ui/service/UiPreferences.kt index f213e73b..7cc210e2 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/ui/service/UiPreferences.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/ui/service/UiPreferences.kt @@ -12,68 +12,48 @@ import ca.gosyer.jui.domain.ui.model.StartScreen import ca.gosyer.jui.domain.ui.model.ThemeMode import ca.gosyer.jui.domain.ui.model.WindowSettings -class UiPreferences(private val preferenceStore: PreferenceStore) { - fun themeMode(): Preference { - return preferenceStore.getJsonObject("theme_mode", ThemeMode.System, ThemeMode.serializer()) - } +class UiPreferences( + private val preferenceStore: PreferenceStore, +) { + fun themeMode(): Preference = preferenceStore.getJsonObject("theme_mode", ThemeMode.System, ThemeMode.serializer()) - fun lightTheme(): Preference { - return preferenceStore.getInt("theme_light", 0) - } + fun lightTheme(): Preference = preferenceStore.getInt("theme_light", 0) - fun darkTheme(): Preference { - return preferenceStore.getInt("theme_dark", 0) - } + fun darkTheme(): Preference = preferenceStore.getInt("theme_dark", 0) - fun colorPrimaryLight(): Preference { - return preferenceStore.getInt("color_primary_light", 0) - } + fun colorPrimaryLight(): Preference = preferenceStore.getInt("color_primary_light", 0) - fun colorPrimaryDark(): Preference { - return preferenceStore.getInt("color_primary_dark", 0) - } + fun colorPrimaryDark(): Preference = preferenceStore.getInt("color_primary_dark", 0) - fun colorSecondaryLight(): Preference { - return preferenceStore.getInt("color_secondary_light", 0) - } + fun colorSecondaryLight(): Preference = preferenceStore.getInt("color_secondary_light", 0) - fun colorSecondaryDark(): Preference { - return preferenceStore.getInt("color_secondary_dark", 0) - } + fun colorSecondaryDark(): Preference = preferenceStore.getInt("color_secondary_dark", 0) - fun colorTertiaryLight(): Preference { - return preferenceStore.getInt("color_tertiary_light", 0) - } + fun colorTertiaryLight(): Preference = preferenceStore.getInt("color_tertiary_light", 0) - fun colorTertiaryDark(): Preference { - return preferenceStore.getInt("color_tertiary_dark", 0) - } + fun colorTertiaryDark(): Preference = preferenceStore.getInt("color_tertiary_dark", 0) - fun startScreen(): Preference { - return preferenceStore.getJsonObject("start_screen", StartScreen.Library, StartScreen.serializer()) - } + fun startScreen(): Preference = + preferenceStore.getJsonObject( + "start_screen", + StartScreen.Library, + StartScreen.serializer(), + ) - fun confirmExit(): Preference { - return preferenceStore.getBoolean("confirm_exit", false) - } + fun confirmExit(): Preference = preferenceStore.getBoolean("confirm_exit", false) - fun language(): Preference { - return preferenceStore.getString("language", "") - } + fun language(): Preference = preferenceStore.getString("language", "") - fun dateFormat(): Preference { - return preferenceStore.getString("date_format", "") - } + fun dateFormat(): Preference = preferenceStore.getString("date_format", "") - fun window(): Preference { - return preferenceStore.getJsonObject("window", WindowSettings(), WindowSettings.serializer()) - } + fun window(): Preference = preferenceStore.getJsonObject("window", WindowSettings(), WindowSettings.serializer()) - fun readerWindow(): Preference { - return preferenceStore.getJsonObject("reader_window", WindowSettings(), WindowSettings.serializer()) - } + fun readerWindow(): Preference = + preferenceStore.getJsonObject( + "reader_window", + WindowSettings(), + WindowSettings.serializer(), + ) - fun windowDecorations(): Preference { - return preferenceStore.getBoolean("window_decorations", true) - } + fun windowDecorations(): Preference = preferenceStore.getBoolean("window_decorations", true) } diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/GetRecentUpdates.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/GetRecentUpdates.kt index f4ed0935..01e65112 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/GetRecentUpdates.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/GetRecentUpdates.kt @@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging class GetRecentUpdates @Inject - constructor(private val updatesRepository: UpdatesRepository) { + constructor( + private val updatesRepository: UpdatesRepository, + ) { suspend fun await( pageNum: Int, onError: suspend (Throwable) -> Unit = {}, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/UpdateCategory.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/UpdateCategory.kt index c810c51f..f4d26d60 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/UpdateCategory.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/UpdateCategory.kt @@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging class UpdateCategory @Inject - constructor(private val updatesRepository: UpdatesRepository) { + constructor( + private val updatesRepository: UpdatesRepository, + ) { suspend fun await( categoryId: Long, onError: suspend (Throwable) -> Unit = {}, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/UpdateChecker.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/UpdateChecker.kt index 43e53cac..48a15d22 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/UpdateChecker.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/UpdateChecker.kt @@ -52,7 +52,10 @@ class UpdateChecker }.flowOn(Dispatchers.IO) sealed class Update { - data class UpdateFound(val release: GithubRelease) : Update() + data class UpdateFound( + val release: GithubRelease, + ) : Update() + object NoUpdatesFound : Update() } diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/UpdateLibrary.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/UpdateLibrary.kt index 0f9e9112..4e1e0d33 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/UpdateLibrary.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/UpdateLibrary.kt @@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging class UpdateLibrary @Inject - constructor(private val updatesRepository: UpdatesRepository) { + constructor( + private val updatesRepository: UpdatesRepository, + ) { suspend fun await(onError: suspend (Throwable) -> Unit = {}) = asFlow() .catch { diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/UpdatesPager.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/UpdatesPager.kt index f353e846..1d6ecb68 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/UpdatesPager.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/interactor/UpdatesPager.kt @@ -157,10 +157,15 @@ class UpdatesPager @Immutable sealed class Updates { @Immutable - data class Update(val manga: Manga, val chapter: Chapter) : Updates() + data class Update( + val manga: Manga, + val chapter: Chapter, + ) : Updates() @Immutable - data class Date(val date: String) : Updates() { + data class Date( + val date: String, + ) : Updates() { constructor(date: LocalDate) : this(date.toString()) } } diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/service/UpdatePreferences.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/service/UpdatePreferences.kt index f5d1dd95..698d6c7a 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/service/UpdatePreferences.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/service/UpdatePreferences.kt @@ -9,8 +9,8 @@ package ca.gosyer.jui.domain.updates.service import ca.gosyer.jui.core.prefs.Preference import ca.gosyer.jui.core.prefs.PreferenceStore -class UpdatePreferences(private val preferenceStore: PreferenceStore) { - fun enabled(): Preference { - return preferenceStore.getBoolean("enabled", true) - } +class UpdatePreferences( + private val preferenceStore: PreferenceStore, +) { + fun enabled(): Preference = preferenceStore.getBoolean("enabled", true) } diff --git a/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/server/service/ServerHostPreferences.kt b/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/server/service/ServerHostPreferences.kt index 08674a4f..77f30ec5 100644 --- a/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/server/service/ServerHostPreferences.kt +++ b/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/server/service/ServerHostPreferences.kt @@ -10,80 +10,74 @@ import ca.gosyer.jui.core.prefs.Preference import ca.gosyer.jui.core.prefs.PreferenceStore import ca.gosyer.jui.domain.server.service.host.ServerHostPreference -class ServerHostPreferences(private val preferenceStore: PreferenceStore) { - fun host(): Preference { - return preferenceStore.getBoolean("host", true) - } +class ServerHostPreferences( + private val preferenceStore: PreferenceStore, +) { + fun host(): Preference = preferenceStore.getBoolean("host", true) private val ip = ServerHostPreference.IP(preferenceStore) - fun ip(): Preference { - return ip.preference() - } + + fun ip(): Preference = ip.preference() + private val port = ServerHostPreference.Port(preferenceStore) - fun port(): Preference { - return port.preference() - } + + fun port(): Preference = port.preference() // Proxy private val socksProxyEnabled = ServerHostPreference.SocksProxyEnabled(preferenceStore) - fun socksProxyEnabled(): Preference { - return socksProxyEnabled.preference() - } + + fun socksProxyEnabled(): Preference = socksProxyEnabled.preference() + private val socksProxyHost = ServerHostPreference.SocksProxyHost(preferenceStore) - fun socksProxyHost(): Preference { - return socksProxyHost.preference() - } + + fun socksProxyHost(): Preference = socksProxyHost.preference() + private val socksProxyPort = ServerHostPreference.SocksProxyPort(preferenceStore) - fun socksProxyPort(): Preference { - return socksProxyPort.preference() - } + + fun socksProxyPort(): Preference = socksProxyPort.preference() // Misc private val debugLogsEnabled = ServerHostPreference.DebugLogsEnabled(preferenceStore) - fun debugLogsEnabled(): Preference { - return debugLogsEnabled.preference() - } + + fun debugLogsEnabled(): Preference = debugLogsEnabled.preference() + private val systemTrayEnabled = ServerHostPreference.SystemTrayEnabled(preferenceStore) - fun systemTrayEnabled(): Preference { - return systemTrayEnabled.preference() - } + + fun systemTrayEnabled(): Preference = systemTrayEnabled.preference() // Downloader private val downloadPath = ServerHostPreference.DownloadPath(preferenceStore) - fun downloadPath(): Preference { - return downloadPath.preference() - } + + fun downloadPath(): Preference = downloadPath.preference() + private val downloadAsCbz = ServerHostPreference.DownloadAsCbz(preferenceStore) - fun downloadAsCbz(): Preference { - return downloadAsCbz.preference() - } + + fun downloadAsCbz(): Preference = downloadAsCbz.preference() // WebUI private val webUIEnabled = ServerHostPreference.WebUIEnabled(preferenceStore) - fun webUIEnabled(): Preference { - return webUIEnabled.preference() - } + + fun webUIEnabled(): Preference = webUIEnabled.preference() + private val openInBrowserEnabled = ServerHostPreference.OpenInBrowserEnabled(preferenceStore) - fun openInBrowserEnabled(): Preference { - return openInBrowserEnabled.preference() - } + + fun openInBrowserEnabled(): Preference = openInBrowserEnabled.preference() // Authentication private val basicAuthEnabled = ServerHostPreference.BasicAuthEnabled(preferenceStore) - fun basicAuthEnabled(): Preference { - return basicAuthEnabled.preference() - } - private val basicAuthUsername = ServerHostPreference.BasicAuthUsername(preferenceStore) - fun basicAuthUsername(): Preference { - return basicAuthUsername.preference() - } - private val basicAuthPassword = ServerHostPreference.BasicAuthPassword(preferenceStore) - fun basicAuthPassword(): Preference { - return basicAuthPassword.preference() - } - fun properties(): Array { - return listOf( + fun basicAuthEnabled(): Preference = basicAuthEnabled.preference() + + private val basicAuthUsername = ServerHostPreference.BasicAuthUsername(preferenceStore) + + fun basicAuthUsername(): Preference = basicAuthUsername.preference() + + private val basicAuthPassword = ServerHostPreference.BasicAuthPassword(preferenceStore) + + fun basicAuthPassword(): Preference = basicAuthPassword.preference() + + fun properties(): Array = + listOf( ip, port, socksProxyEnabled, @@ -101,5 +95,4 @@ class ServerHostPreferences(private val preferenceStore: PreferenceStore) { ).mapNotNull { it.getProperty() }.toTypedArray() - } } diff --git a/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/server/service/host/ServerHostPreference.kt b/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/server/service/host/ServerHostPreference.kt index a3cd4977..0c48e551 100644 --- a/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/server/service/host/ServerHostPreference.kt +++ b/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/server/service/host/ServerHostPreference.kt @@ -16,6 +16,7 @@ sealed class ServerHostPreference { protected abstract val defaultValue: T protected abstract val serverValue: T + private fun validate(value: T): Boolean { return value != serverValue } @@ -30,6 +31,7 @@ sealed class ServerHostPreference { } protected abstract val preferenceStore: PreferenceStore + abstract fun preference(): Preference companion object { @@ -42,114 +44,144 @@ sealed class ServerHostPreference { override val defaultValue: String, override val serverValue: String = defaultValue, ) : ServerHostPreference() { - override fun preference(): Preference { - return preferenceStore.getString(propertyName, defaultValue) - } + override fun preference(): Preference = preferenceStore.getString(propertyName, defaultValue) } + sealed class IntServerHostPreference( override val preferenceStore: PreferenceStore, override val propertyName: String, override val defaultValue: Int, override val serverValue: Int = defaultValue, ) : ServerHostPreference() { - override fun preference(): Preference { - return preferenceStore.getInt(propertyName, defaultValue) - } + override fun preference(): Preference = preferenceStore.getInt(propertyName, defaultValue) } + sealed class BooleanServerHostPreference( override val preferenceStore: PreferenceStore, override val propertyName: String, override val defaultValue: Boolean, override val serverValue: Boolean = defaultValue, ) : ServerHostPreference() { - override fun preference(): Preference { - return preferenceStore.getBoolean(propertyName, defaultValue) - } + override fun preference(): Preference = preferenceStore.getBoolean(propertyName, defaultValue) } - class IP(preferenceStore: PreferenceStore) : StringServerHostPreference( - preferenceStore, - "ip", - "0.0.0.0", - ) - class Port(override val preferenceStore: PreferenceStore) : IntServerHostPreference( - preferenceStore, - "port", - 4567, - ) + class IP( + preferenceStore: PreferenceStore, + ) : StringServerHostPreference( + preferenceStore, + "ip", + "0.0.0.0", + ) + + class Port( + override val preferenceStore: PreferenceStore, + ) : IntServerHostPreference( + preferenceStore, + "port", + 4567, + ) // Proxy - class SocksProxyEnabled(preferenceStore: PreferenceStore) : BooleanServerHostPreference( - preferenceStore, - "socksProxyEnabled", - false, - ) - class SocksProxyHost(preferenceStore: PreferenceStore) : StringServerHostPreference( - preferenceStore, - "socksProxyHost", - "", - ) - class SocksProxyPort(override val preferenceStore: PreferenceStore) : IntServerHostPreference( - preferenceStore, - "socksProxyPort", - 0, - ) + class SocksProxyEnabled( + preferenceStore: PreferenceStore, + ) : BooleanServerHostPreference( + preferenceStore, + "socksProxyEnabled", + false, + ) + + class SocksProxyHost( + preferenceStore: PreferenceStore, + ) : StringServerHostPreference( + preferenceStore, + "socksProxyHost", + "", + ) + + class SocksProxyPort( + override val preferenceStore: PreferenceStore, + ) : IntServerHostPreference( + preferenceStore, + "socksProxyPort", + 0, + ) // Misc - class DebugLogsEnabled(preferenceStore: PreferenceStore) : BooleanServerHostPreference( - preferenceStore, - "debugLogsEnabled", - false, - ) + class DebugLogsEnabled( + preferenceStore: PreferenceStore, + ) : BooleanServerHostPreference( + preferenceStore, + "debugLogsEnabled", + false, + ) - class SystemTrayEnabled(preferenceStore: PreferenceStore) : BooleanServerHostPreference( - preferenceStore, - "systemTrayEnabled", - false, - true, - ) + class SystemTrayEnabled( + preferenceStore: PreferenceStore, + ) : BooleanServerHostPreference( + preferenceStore, + "systemTrayEnabled", + false, + true, + ) // Downloader - class DownloadPath(preferenceStore: PreferenceStore) : StringServerHostPreference( - preferenceStore, - "downloadsPath", - "", - ) - class DownloadAsCbz(preferenceStore: PreferenceStore) : BooleanServerHostPreference( - preferenceStore, - "downloadAsCbz", - false, - ) + class DownloadPath( + preferenceStore: PreferenceStore, + ) : StringServerHostPreference( + preferenceStore, + "downloadsPath", + "", + ) + + class DownloadAsCbz( + preferenceStore: PreferenceStore, + ) : BooleanServerHostPreference( + preferenceStore, + "downloadAsCbz", + false, + ) // WebUI - class WebUIEnabled(preferenceStore: PreferenceStore) : BooleanServerHostPreference( - preferenceStore, - "webUIEnabled", - false, - true, - ) + class WebUIEnabled( + preferenceStore: PreferenceStore, + ) : BooleanServerHostPreference( + preferenceStore, + "webUIEnabled", + false, + true, + ) - class OpenInBrowserEnabled(preferenceStore: PreferenceStore) : BooleanServerHostPreference( - preferenceStore, - "initialOpenInBrowserEnabled", - false, - true, - ) + class OpenInBrowserEnabled( + preferenceStore: PreferenceStore, + ) : BooleanServerHostPreference( + preferenceStore, + "initialOpenInBrowserEnabled", + false, + true, + ) // Authentication - class BasicAuthEnabled(preferenceStore: PreferenceStore) : BooleanServerHostPreference( - preferenceStore, - "basicAuthEnabled", - false, - ) - class BasicAuthUsername(preferenceStore: PreferenceStore) : StringServerHostPreference( - preferenceStore, - "basicAuthUsername", - "", - ) - class BasicAuthPassword(preferenceStore: PreferenceStore) : StringServerHostPreference( - preferenceStore, - "basicAuthPassword", - "", - ) + class BasicAuthEnabled( + preferenceStore: PreferenceStore, + ) : BooleanServerHostPreference( + preferenceStore, + "basicAuthEnabled", + false, + ) + + class BasicAuthUsername( + preferenceStore: PreferenceStore, + ) : StringServerHostPreference( + preferenceStore, + "basicAuthUsername", + "", + ) + + class BasicAuthPassword( + preferenceStore: PreferenceStore, + ) : StringServerHostPreference( + preferenceStore, + "basicAuthPassword", + "", + ) } diff --git a/ios/src/uikitMain/kotlin/ca/gosyer/jui/ios/AppComponent.kt b/ios/src/uikitMain/kotlin/ca/gosyer/jui/ios/AppComponent.kt index e667bc55..42186baa 100644 --- a/ios/src/uikitMain/kotlin/ca/gosyer/jui/ios/AppComponent.kt +++ b/ios/src/uikitMain/kotlin/ca/gosyer/jui/ios/AppComponent.kt @@ -20,7 +20,10 @@ import me.tatarka.inject.annotations.Provides abstract class AppComponent( @get:Provides val context: ContextWrapper, -) : ViewModelComponent, DataComponent, DomainComponent, UiComponent { +) : ViewModelComponent, + DataComponent, + DomainComponent, + UiComponent { abstract val appMigrations: AppMigrations @get:AppScope diff --git a/ios/src/uikitMain/kotlin/ca/gosyer/jui/ios/Main.kt b/ios/src/uikitMain/kotlin/ca/gosyer/jui/ios/Main.kt index e9045eb2..d6181fc0 100644 --- a/ios/src/uikitMain/kotlin/ca/gosyer/jui/ios/Main.kt +++ b/ios/src/uikitMain/kotlin/ca/gosyer/jui/ios/Main.kt @@ -4,11 +4,9 @@ package ca.gosyer.jui.ios import androidx.compose.animation.Crossfade import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.sizeIn -import androidx.compose.foundation.layout.windowInsetsPadding import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.Card import androidx.compose.material.Text @@ -33,34 +31,10 @@ import ca.gosyer.jui.uicore.vm.ContextWrapper import ca.gosyer.jui.uicore.vm.Length import kotlinx.cinterop.BetaInteropApi import kotlinx.cinterop.ExperimentalForeignApi -import kotlinx.cinterop.autoreleasepool -import kotlinx.cinterop.cstr -import kotlinx.cinterop.memScoped -import kotlinx.cinterop.toCValues -import kotlinx.cinterop.useContents import kotlinx.coroutines.delay import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach -import org.lighthousegames.logging.FixedLogLevel -import org.lighthousegames.logging.KmLog -import org.lighthousegames.logging.KmLogging -import org.lighthousegames.logging.LogFactory -import org.lighthousegames.logging.LogLevel -import org.lighthousegames.logging.LogLevelController -import org.lighthousegames.logging.Logger -import org.lighthousegames.logging.TagProvider -import platform.Foundation.NSStringFromClass -import platform.Foundation.NSThread -import platform.UIKit.UIApplication -import platform.UIKit.UIApplicationDelegateProtocol -import platform.UIKit.UIApplicationDelegateProtocolMeta -import platform.UIKit.UIApplicationMain -import platform.UIKit.UIResponder -import platform.UIKit.UIResponderMeta -import platform.UIKit.UIScreen import platform.UIKit.UIViewController -import platform.UIKit.UIWindow -import platform.UIKit.safeAreaInsets import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds diff --git a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/file/AndroidFileChooser.kt b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/file/AndroidFileChooser.kt index f22f7e00..10d106cb 100644 --- a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/file/AndroidFileChooser.kt +++ b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/file/AndroidFileChooser.kt @@ -17,7 +17,9 @@ import androidx.compose.ui.platform.LocalContext import okio.Source import okio.source -actual class FileChooser(private val resultLauncher: ManagedActivityResultLauncher) { +actual class FileChooser( + private val resultLauncher: ManagedActivityResultLauncher, +) { actual fun launch(extension: String) { resultLauncher.launch(MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)) } diff --git a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/image/AndroidBitmapDecoderFactory.kt b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/image/AndroidBitmapDecoderFactory.kt index d35c3813..a8ac9e17 100644 --- a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/image/AndroidBitmapDecoderFactory.kt +++ b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/image/AndroidBitmapDecoderFactory.kt @@ -10,5 +10,6 @@ import ca.gosyer.jui.uicore.vm.ContextWrapper import com.seiko.imageloader.component.decoder.BitmapFactoryDecoder import com.seiko.imageloader.component.decoder.Decoder -actual class BitmapDecoderFactory actual constructor(contextWrapper: ContextWrapper) : - Decoder.Factory by BitmapFactoryDecoder.Factory(contextWrapper, Int.MAX_VALUE) +actual class BitmapDecoderFactory actual constructor( + contextWrapper: ContextWrapper, +) : Decoder.Factory by BitmapFactoryDecoder.Factory(contextWrapper, Int.MAX_VALUE) diff --git a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/prefs/AndroidColorExtensions.kt b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/prefs/AndroidColorExtensions.kt index 9d10cfae..dcf6c08b 100644 --- a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/prefs/AndroidColorExtensions.kt +++ b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/prefs/AndroidColorExtensions.kt @@ -15,11 +15,10 @@ internal actual fun Color.toHsv(): FloatArray { return result } -internal actual fun hexStringToColor(hex: String): Color? { - return try { +internal actual fun hexStringToColor(hex: String): Color? = + try { val color = android.graphics.Color.parseColor(hex) Color(color) } catch (e: Exception) { null } -} diff --git a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/state/SavedStateHandleSupport.kt b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/state/SavedStateHandleSupport.kt index 2b2c2365..1de1070b 100644 --- a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/state/SavedStateHandleSupport.kt +++ b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/state/SavedStateHandleSupport.kt @@ -107,22 +107,20 @@ internal class SavedStateHandlesProvider( /** * Restore the state associated with a particular SavedStateHandle, identified by its [key] */ - fun consumeRestoredStateForKey(key: String): Bundle? { - return savedStateRegistry::class.java + fun consumeRestoredStateForKey(key: String): Bundle? = + savedStateRegistry::class.java .methods .find { it.name == "consumeRestoredStateForKey" } ?.invoke(savedStateRegistry, key) as? Bundle - } } inline fun CreationExtras.addScreenModelKey( screen: Screen, tag: String?, -): CreationExtras { - return MutableCreationExtras(this).apply { +): CreationExtras = + MutableCreationExtras(this).apply { set( VIEW_MODEL_KEY, "${screen.key}:${T::class.qualifiedName}:${tag ?: "default"}", ) } -} diff --git a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/theme/ThemeScrollbarStyle.kt b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/theme/ThemeScrollbarStyle.kt index f84fe5f1..ecfaccad 100644 --- a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/theme/ThemeScrollbarStyle.kt +++ b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/base/theme/ThemeScrollbarStyle.kt @@ -15,7 +15,5 @@ actual object ThemeScrollbarStyle { @Stable @Composable - actual fun getScrollbarStyle(): ScrollbarStyle { - return defaultScrollbarStyle - } + actual fun getScrollbarStyle(): ScrollbarStyle = defaultScrollbarStyle } diff --git a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/categories/OpenCategories.kt b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/categories/OpenCategories.kt index d9564fcc..8b46d934 100644 --- a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/categories/OpenCategories.kt +++ b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/categories/OpenCategories.kt @@ -11,7 +11,9 @@ import androidx.compose.runtime.remember import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.Navigator -actual class CategoriesLauncher(private val navigator: Navigator?) { +actual class CategoriesLauncher( + private val navigator: Navigator?, +) { actual fun open() { navigator?.push(CategoriesScreen()) } diff --git a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/main/about/components/getDebugInfo.kt b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/main/about/components/getDebugInfo.kt index 0602af88..ecd2d216 100644 --- a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/main/about/components/getDebugInfo.kt +++ b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/main/about/components/getDebugInfo.kt @@ -9,8 +9,8 @@ package ca.gosyer.jui.ui.main.about.components import android.os.Build import ca.gosyer.jui.presentation.build.BuildKonfig -actual fun getDebugInfo(): String { - return """ +actual fun getDebugInfo(): String = + """ App version: ${BuildKonfig.VERSION} (${ if (BuildKonfig.DEBUG) "Debug" else "Standard"}, ${BuildKonfig.MIGRATION_CODE}) Preview build: r${BuildKonfig.PREVIEW_BUILD} Android version: ${Build.VERSION.RELEASE} (SDK ${Build.VERSION.SDK_INT}) @@ -20,5 +20,4 @@ actual fun getDebugInfo(): String { Device name: ${Build.DEVICE} Device model: ${Build.MODEL} Device product name: ${Build.PRODUCT} - """.trimIndent() -} + """.trimIndent() diff --git a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/reader/AndroidReaderMenu.kt b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/reader/AndroidReaderMenu.kt index 2d55d1d5..658eb859 100644 --- a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/reader/AndroidReaderMenu.kt +++ b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/reader/AndroidReaderMenu.kt @@ -12,7 +12,9 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.platform.LocalContext -actual class ReaderLauncher(private val context: Context) { +actual class ReaderLauncher( + private val context: Context, +) { actual fun launch( chapterIndex: Int, mangaId: Long, diff --git a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/settings/AndroidSettingsServerScreen.kt b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/settings/AndroidSettingsServerScreen.kt index 9f6e7c9b..3f98c566 100644 --- a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/settings/AndroidSettingsServerScreen.kt +++ b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/settings/AndroidSettingsServerScreen.kt @@ -13,10 +13,10 @@ import ca.gosyer.jui.uicore.vm.ViewModel import me.tatarka.inject.annotations.Inject @Composable -actual fun getServerHostItems(viewModel: @Composable () -> SettingsServerHostViewModel): LazyListScope.() -> Unit { - return {} -} +actual fun getServerHostItems(viewModel: @Composable () -> SettingsServerHostViewModel): LazyListScope.() -> Unit = {} actual class SettingsServerHostViewModel @Inject - constructor(contextWrapper: ContextWrapper) : ViewModel(contextWrapper) + constructor( + contextWrapper: ContextWrapper, + ) : ViewModel(contextWrapper) diff --git a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/util/compose/Image.kt b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/util/compose/Image.kt index 6b1f2ace..1dab9947 100644 --- a/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/util/compose/Image.kt +++ b/presentation/src/androidMain/kotlin/ca/gosyer/jui/ui/util/compose/Image.kt @@ -13,6 +13,4 @@ import io.ktor.client.statement.HttpResponse import io.ktor.client.statement.bodyAsChannel import io.ktor.utils.io.jvm.javaio.toInputStream -actual suspend fun HttpResponse.toImageBitmap(): ImageBitmap { - return BitmapFactory.decodeStream(bodyAsChannel().toInputStream()).asImageBitmap() -} +actual suspend fun HttpResponse.toImageBitmap(): ImageBitmap = BitmapFactory.decodeStream(bodyAsChannel().toInputStream()).asImageBitmap() diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/chapter/ChapterDownloadButtons.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/chapter/ChapterDownloadButtons.kt index f519b512..281114af 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/chapter/ChapterDownloadButtons.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/chapter/ChapterDownloadButtons.kt @@ -91,9 +91,7 @@ data class ChapterDownloadItem( _downloadState.value = ChapterDownloadState.NotDownloaded } - fun isSelected(selectedItems: List): Boolean { - return (chapter.id in selectedItems).also { _isSelected.value = it } - } + fun isSelected(selectedItems: List): Boolean = (chapter.id in selectedItems).also { _isSelected.value = it } } enum class ChapterDownloadState { diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/dialog/MaterialDialogProperties.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/dialog/MaterialDialogProperties.kt index bdf9e73a..65e07499 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/dialog/MaterialDialogProperties.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/dialog/MaterialDialogProperties.kt @@ -29,8 +29,8 @@ fun getMaterialDialogProperties( title: String = BuildKonfig.NAME, icon: Painter = MR.images.icon.toPainter(), resizable: Boolean = true, -): MaterialDialogProperties { - return MaterialDialogProperties( +): MaterialDialogProperties = + MaterialDialogProperties( dismissOnBackPress = dismissOnBackPress, dismissOnClickOutside = dismissOnClickOutside, securePolicy = securePolicy, @@ -41,4 +41,3 @@ fun getMaterialDialogProperties( windowIcon = icon, windowIsResizable = resizable, ) -} diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/image/BitmapDecoderFactory.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/image/BitmapDecoderFactory.kt index 696299b9..f539ba80 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/image/BitmapDecoderFactory.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/image/BitmapDecoderFactory.kt @@ -9,4 +9,6 @@ package ca.gosyer.jui.ui.base.image import ca.gosyer.jui.uicore.vm.ContextWrapper import com.seiko.imageloader.component.decoder.Decoder -expect class BitmapDecoderFactory constructor(contextWrapper: ContextWrapper) : Decoder.Factory +expect class BitmapDecoderFactory constructor( + contextWrapper: ContextWrapper, +) : Decoder.Factory diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/model/Holder.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/model/Holder.kt index 25c243c0..25af6853 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/model/Holder.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/model/Holder.kt @@ -10,11 +10,15 @@ import androidx.compose.runtime.Immutable import androidx.compose.runtime.Stable @Stable -class StableHolder(val item: T) { +class StableHolder( + val item: T, +) { operator fun component1(): T = item } @Immutable -class ImmutableHolder(val item: T) { +class ImmutableHolder( + val item: T, +) { operator fun component1(): T = item } diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/navigation/ActionMenu.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/navigation/ActionMenu.kt index 484d1e8b..0d644059 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/navigation/ActionMenu.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/navigation/ActionMenu.kt @@ -75,7 +75,8 @@ enum class OverflowMode { @Composable fun ActionMenu( items: ImmutableList, - numIcons: Int = 3, // includes overflow menu icon; may be overridden by NEVER_OVERFLOW + // includes overflow menu icon; may be overridden by NEVER_OVERFLOW + numIcons: Int = 3, menuVisible: MutableState = remember { mutableStateOf(false) }, iconItem: @Composable (onClick: () -> Unit, name: String, icon: ImageVector, enabled: Boolean) -> Unit, ) { @@ -99,7 +100,9 @@ fun ActionMenu( } else { TextButton( onClick = when (item) { - is ActionGroup -> { { openGroup = item } } + is ActionGroup -> { + { openGroup = item } + } is ActionItem -> item.doAction }, enabled = item.enabled, diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/navigation/DisplayController.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/navigation/DisplayController.kt index 944075a2..06acbbff 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/navigation/DisplayController.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/navigation/DisplayController.kt @@ -24,6 +24,7 @@ class DisplayController( fun openSideMenu() { _sideMenuVisible.value = true } + fun closeSideMenu() { _sideMenuVisible.value = false } diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/navigation/Toolbar.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/navigation/Toolbar.kt index cd31bb23..796e75f4 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/navigation/Toolbar.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/navigation/Toolbar.kt @@ -88,8 +88,10 @@ fun Toolbar( closeIcon: ImageVector = ToolbarDefault, modifier: Modifier = Modifier, actions: @Composable () -> ImmutableList = { remember { persistentListOf() } }, - backgroundColor: Color = MaterialTheme.colors.surface, // CustomColors.current.bars, - contentColor: Color = contentColorFor(backgroundColor), // CustomColors.current.onBars, + // CustomColors.current.bars, + backgroundColor: Color = MaterialTheme.colors.surface, + // CustomColors.current.onBars, + contentColor: Color = contentColorFor(backgroundColor), elevation: Dp = Dp.Hairline, searchText: String? = null, search: ((String) -> Unit)? = null, @@ -216,6 +218,7 @@ private fun ThinToolbar( searchSubmit: (() -> Unit)?, ) { var searchMode by remember { mutableStateOf(!searchText.isNullOrEmpty()) } + fun closeSearch() { search?.invoke("") searchSubmit?.invoke() diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/prefs/ColorPickerDialog.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/prefs/ColorPickerDialog.kt index 1a43080b..9a0de8de 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/prefs/ColorPickerDialog.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/prefs/ColorPickerDialog.kt @@ -421,16 +421,12 @@ private fun satValToCoordinates( saturation: Float, value: Float, size: IntSize, -): Offset { - return Offset(saturation * size.width, ((1f - value) * size.height)) -} +): Offset = Offset(saturation * size.width, ((1f - value) * size.height)) private fun hueToCoordinate( hue: Float, size: IntSize, -): Float { - return size.height - (hue * size.height / 360f) -} +): Float = size.height - (hue * size.height / 360f) // Color space conversions @@ -439,36 +435,51 @@ fun hsvToColor( hue: Float, saturation: Float, value: Float, -): Color { - return Color.hsv(hue, saturation.coerceIn(0F, 1F), value.coerceIn(0F, 1F)) -} +): Color = Color.hsv(hue, saturation.coerceIn(0F, 1F), value.coerceIn(0F, 1F)) internal expect fun Color.toHsv(): FloatArray -private fun hueToColor(hue: Float): Color { - return hsvToColor(hue, 1f, 1f) -} +private fun hueToColor(hue: Float): Color = hsvToColor(hue, 1f, 1f) internal expect fun hexStringToColor(hex: String): Color? private val presetColors = listOf( - Color(0xFFF44336), // RED 500 - Color(0xFFE91E63), // PINK 500 - Color(0xFFFF2C93), // LIGHT PINK 500 - Color(0xFF9C27B0), // PURPLE 500 - Color(0xFF673AB7), // DEEP PURPLE 500 - Color(0xFF3F51B5), // INDIGO 500 - Color(0xFF2196F3), // BLUE 500 - Color(0xFF03A9F4), // LIGHT BLUE 500 - Color(0xFF00BCD4), // CYAN 500 - Color(0xFF009688), // TEAL 500 - Color(0xFF4CAF50), // GREEN 500 - Color(0xFF8BC34A), // LIGHT GREEN 500 - Color(0xFFCDDC39), // LIME 500 - Color(0xFFFFEB3B), // YELLOW 500 - Color(0xFFFFC107), // AMBER 500 - Color(0xFFFF9800), // ORANGE 500 - Color(0xFF795548), // BROWN 500 - Color(0xFF607D8B), // BLUE GREY 500 - Color(0xFF9E9E9E), // GREY 500 + // RED 500 + Color(0xFFF44336), + // PINK 500 + Color(0xFFE91E63), + // LIGHT PINK 500 + Color(0xFFFF2C93), + // PURPLE 500 + Color(0xFF9C27B0), + // DEEP PURPLE 500 + Color(0xFF673AB7), + // INDIGO 500 + Color(0xFF3F51B5), + // BLUE 500 + Color(0xFF2196F3), + // LIGHT BLUE 500 + Color(0xFF03A9F4), + // CYAN 500 + Color(0xFF00BCD4), + // TEAL 500 + Color(0xFF009688), + // GREEN 500 + Color(0xFF4CAF50), + // LIGHT GREEN 500 + Color(0xFF8BC34A), + // LIME 500 + Color(0xFFCDDC39), + // YELLOW 500 + Color(0xFFFFEB3B), + // AMBER 500 + Color(0xFFFFC107), + // ORANGE 500 + Color(0xFFFF9800), + // BROWN 500 + Color(0xFF795548), + // BLUE GREY 500 + Color(0xFF607D8B), + // GREY 500 + Color(0xFF9E9E9E), ).toImmutableList() diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/screen/BaseScreen.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/screen/BaseScreen.kt index 59b8c8d1..f0ce7891 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/screen/BaseScreen.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/screen/BaseScreen.kt @@ -8,4 +8,4 @@ package ca.gosyer.jui.ui.base.screen import cafe.adriel.voyager.core.screen.Screen -expect abstract class BaseScreen() : Screen +expect abstract class BaseScreen : Screen diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/theme/AppColorsPreference.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/theme/AppColorsPreference.kt index 8bf5280f..2bbd6db7 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/theme/AppColorsPreference.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/base/theme/AppColorsPreference.kt @@ -26,26 +26,23 @@ class AppColorsPreferenceState( val tertiaryStateFlow: PreferenceMutableStateFlow, ) -fun UiPreferences.getLightColors(): AppColorsPreference { - return AppColorsPreference( +fun UiPreferences.getLightColors(): AppColorsPreference = + AppColorsPreference( colorPrimaryLight().asColor(), colorSecondaryLight().asColor(), colorTertiaryLight().asColor(), ) -} -fun UiPreferences.getDarkColors(): AppColorsPreference { - return AppColorsPreference( +fun UiPreferences.getDarkColors(): AppColorsPreference = + AppColorsPreference( colorPrimaryDark().asColor(), colorSecondaryDark().asColor(), colorTertiaryDark().asColor(), ) -} -fun AppColorsPreference.asStateFlow(scope: CoroutineScope): AppColorsPreferenceState { - return AppColorsPreferenceState( +fun AppColorsPreference.asStateFlow(scope: CoroutineScope): AppColorsPreferenceState = + AppColorsPreferenceState( primary.asStateIn(scope), secondary.asStateIn(scope), tertiary.asStateIn(scope), ) -} diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/categories/CategoriesScreenViewModel.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/categories/CategoriesScreenViewModel.kt index dd14ab1d..ff95e032 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/categories/CategoriesScreenViewModel.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/categories/CategoriesScreenViewModel.kt @@ -101,7 +101,8 @@ class CategoriesScreenViewModel } fun createCategory(name: String) { - _categories.value = _categories.value.toPersistentList() + MenuCategory(order = categories.value.size + 1, name = name, default = false) + _categories.value = + _categories.value.toPersistentList() + MenuCategory(order = categories.value.size + 1, name = name, default = false) } fun moveUp(category: MenuCategory) { @@ -133,7 +134,12 @@ class CategoriesScreenViewModel private fun Category.toMenuCategory() = MenuCategory(id, order, name, default) @Stable - data class MenuCategory(val id: Long? = null, val order: Int, val name: String, val default: Boolean = false) + data class MenuCategory( + val id: Long? = null, + val order: Int, + val name: String, + val default: Boolean = false, + ) private companion object { private val log = logging() diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/downloads/components/DownloadsScreenContent.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/downloads/components/DownloadsScreenContent.kt index 65d79e24..7c72645f 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/downloads/components/DownloadsScreenContent.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/downloads/components/DownloadsScreenContent.kt @@ -235,8 +235,8 @@ private fun getActionItems( startDownloading: () -> Unit, pauseDownloading: () -> Unit, clearQueue: () -> Unit, -): ImmutableList { - return listOf( +): ImmutableList = + listOf( if (downloadStatus == DownloaderStatus.Started) { ActionItem( stringResource(MR.strings.action_pause), @@ -252,4 +252,3 @@ private fun getActionItems( }, ActionItem(stringResource(MR.strings.action_clear_queue), Icons.Rounded.ClearAll, doAction = clearQueue), ).toImmutableList() -} diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/extensions/ExtensionsScreenViewModel.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/extensions/ExtensionsScreenViewModel.kt index dce0df0f..52d312c9 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/extensions/ExtensionsScreenViewModel.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/extensions/ExtensionsScreenViewModel.kt @@ -225,6 +225,12 @@ class ExtensionsScreenViewModel @Immutable sealed class ExtensionUI { - data class Header(val header: String) : ExtensionUI() - data class ExtensionItem(val extension: Extension, val isWorking: Boolean = false) : ExtensionUI() + data class Header( + val header: String, + ) : ExtensionUI() + + data class ExtensionItem( + val extension: Extension, + val isWorking: Boolean = false, + ) : ExtensionUI() } diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/extensions/components/ExtensionsScreenContent.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/extensions/components/ExtensionsScreenContent.kt index 05dc4b41..6c0584ba 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/extensions/components/ExtensionsScreenContent.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/extensions/components/ExtensionsScreenContent.kt @@ -335,8 +335,8 @@ fun LanguageDialog( private fun getActionItems( openLanguageDialog: () -> Unit, openInstallExtensionFile: () -> Unit, -): ImmutableList { - return listOf( +): ImmutableList = + listOf( ActionItem( stringResource(MR.strings.enabled_languages), Icons.Rounded.Translate, @@ -348,4 +348,3 @@ private fun getActionItems( doAction = openInstallExtensionFile, ), ).toImmutableList() -} diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/library/LibraryScreenViewModel.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/library/LibraryScreenViewModel.kt index 4d521c03..b87383c6 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/library/LibraryScreenViewModel.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/library/LibraryScreenViewModel.kt @@ -57,7 +57,9 @@ sealed class LibraryState { object Loading : LibraryState() @Stable - data class Failed(val e: Throwable) : LibraryState() + data class Failed( + val e: Throwable, + ) : LibraryState() @Stable data class Loaded( @@ -71,7 +73,9 @@ sealed class CategoryState { object Loading : CategoryState() @Stable - data class Failed(val e: Throwable) : CategoryState() + data class Failed( + val e: Throwable, + ) : CategoryState() @Stable data class Loaded( @@ -81,18 +85,24 @@ sealed class CategoryState { } private typealias LibraryMap = MutableMap> -private data class Library(val categories: MutableStateFlow, val mangaMap: LibraryMap) + +private data class Library( + val categories: MutableStateFlow, + val mangaMap: LibraryMap, +) private fun LibraryMap.getManga(id: Long) = getOrPut(id) { MutableStateFlow(CategoryState.Loading) } + private fun LibraryMap.setError( id: Long, e: Throwable, ) { getManga(id).value = CategoryState.Failed(e) } + private fun LibraryMap.setManga( id: Long, manga: ImmutableList, @@ -274,8 +284,14 @@ class LibraryScreenViewModel .toList() } - private fun getMangaItemsFlow(unfilteredItemsFlow: StateFlow>): StateFlow> { - return combine(unfilteredItemsFlow, query) { unfilteredItems, query -> + private fun getMangaItemsFlow(unfilteredItemsFlow: StateFlow>): StateFlow> = + combine( + unfilteredItemsFlow, + query, + ) { + unfilteredItems, + query, + -> filterManga(query, unfilteredItems) }.combine(filter) { filteredManga, filterer -> filteredManga.filter(filterer) @@ -284,19 +300,15 @@ class LibraryScreenViewModel }.map { it.toImmutableList() }.stateIn(scope, SharingStarted.Eagerly, persistentListOf()) - } - fun getLibraryForCategoryId(id: Long): StateFlow { - return library.mangaMap.getManga(id) - } + fun getLibraryForCategoryId(id: Long): StateFlow = library.mangaMap.getManga(id) - private fun getCategoriesToUpdate(mangaId: Long): List { - return library.mangaMap + private fun getCategoriesToUpdate(mangaId: Long): List = + library.mangaMap .filter { mangaMapEntry -> (mangaMapEntry.value.value as? CategoryState.Loaded)?.items?.value?.firstOrNull { it.id == mangaId } != null } .mapNotNull { (id) -> (library.categories.value as? LibraryState.Loaded)?.categories?.first { it.id == id } } - } fun removeManga(mangaId: Long) { scope.launch { diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/library/components/LibraryScreenContent.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/library/components/LibraryScreenContent.kt index 7fee1595..b0450943 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/library/components/LibraryScreenContent.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/library/components/LibraryScreenContent.kt @@ -204,7 +204,8 @@ fun WideLibraryScreenContent( ) if (libraryState is LibraryState.Loaded) { LibraryTabs( - visible = true, // vm.showCategoryTabs, + // visible = vm.showCategoryTabs, + visible = true, pagerState = pagerState, categories = libraryState.categories, selectedPage = selectedCategoryIndex, @@ -332,7 +333,8 @@ fun ThinLibraryScreenContent( ) if (libraryState is LibraryState.Loaded) { LibraryTabs( - visible = true, // vm.showCategoryTabs, + // visible = vm.showCategoryTabs, + visible = true, pagerState = pagerState, categories = libraryState.categories, selectedPage = selectedCategoryIndex, @@ -388,8 +390,8 @@ private fun getActionItems( onUpdateLibrary: () -> Unit, updateWebsocketStatus: WebsocketService.Status? = null, restartLibraryUpdates: (() -> Unit)? = null, -): ImmutableList { - return listOfNotNull( +): ImmutableList = + listOfNotNull( ActionItem( name = stringResource(MR.strings.action_filter), icon = Icons.Rounded.FilterList, @@ -410,4 +412,3 @@ private fun getActionItems( null }, ).toImmutableList() -} diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/library/settings/LibraryDisplay.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/library/settings/LibraryDisplay.kt index 287c185b..bc2fee63 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/library/settings/LibraryDisplay.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/library/settings/LibraryDisplay.kt @@ -81,8 +81,8 @@ fun LibraryDisplay( checked = localBadges, onClick = { setLocalBadges(!localBadges) }, ) - // TODO: 2022-04-06 Enable when library contains manga source in manga object - /*CheckboxItem( + /* TODO: 2022-04-06 Enable when library contains manga source in manga object + CheckboxItem( text = stringResource(MR.strings.display_badge_language), checked = languageBadges, onClick = { setLanguageBadges(!languageBadges) } diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/library/settings/LibrarySheet.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/library/settings/LibrarySheet.kt index f1a136c5..6a056f32 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/library/settings/LibrarySheet.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/library/settings/LibrarySheet.kt @@ -36,7 +36,9 @@ import com.google.accompanist.pager.pagerTabIndicatorOffset import dev.icerock.moko.resources.StringResource import kotlinx.coroutines.launch -enum class LibrarySheetTabs(val res: StringResource) { +enum class LibrarySheetTabs( + val res: StringResource, +) { FILTERS(MR.strings.action_filter), SORT(MR.strings.library_sort), DISPLAY(MR.strings.library_display), diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/MainMenu.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/MainMenu.kt index 6d5199c9..4b7cbc99 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/MainMenu.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/MainMenu.kt @@ -110,10 +110,11 @@ fun WideMainMenu( } withDisplayController(controller) { val insets = WindowInsets.navigationBars.only(WindowInsetsSides.Start) - MainWindow(navigator, + MainWindow( + navigator, Modifier.padding(start = startPadding) .windowInsetsPadding(insets) - .consumeWindowInsets(insets) + .consumeWindowInsets(insets), ) } } diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/about/AboutViewModel.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/about/AboutViewModel.kt index d02d4c5d..28c1e0ee 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/about/AboutViewModel.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/about/AboutViewModel.kt @@ -66,9 +66,7 @@ class AboutViewModel } } - private fun getFormattedDate(time: Instant): String { - return dateHandler.dateTimeFormat(time) - } + private fun getFormattedDate(time: Instant): String = dateHandler.dateTimeFormat(time) companion object { private val log = logging() diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/about/components/AboutContent.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/about/components/AboutContent.kt index b16c8b5e..670c8057 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/about/components/AboutContent.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/about/components/AboutContent.kt @@ -223,11 +223,20 @@ private fun OpenSourceLicenses(openSourceLicenses: () -> Unit) { } sealed class LinkIcon { - data class Resource(val res: ImageResource) : LinkIcon() - data class Icon(val icon: ImageVector) : LinkIcon() + data class Resource( + val res: ImageResource, + ) : LinkIcon() + + data class Icon( + val icon: ImageVector, + ) : LinkIcon() } -enum class Link(val nameRes: StringResource, val icon: LinkIcon, val uri: String) { +enum class Link( + val nameRes: StringResource, + val icon: LinkIcon, + val uri: String, +) { Github(MR.strings.github, LinkIcon.Resource(MR.images.github), "https://github.com/Suwayomi/Tachidesk-JUI"), Discord(MR.strings.discord, LinkIcon.Resource(MR.images.discord), "https://discord.gg/DDZdqZWaHA"), Reddit(MR.strings.reddit, LinkIcon.Resource(MR.images.reddit), "https://reddit.com/r/Tachidesk/"), diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/manga/MangaScreen.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/manga/MangaScreen.kt index 8683aa50..846e82d9 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/manga/MangaScreen.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/manga/MangaScreen.kt @@ -14,7 +14,9 @@ import cafe.adriel.voyager.core.screen.Screen import cafe.adriel.voyager.core.screen.ScreenKey import cafe.adriel.voyager.core.screen.uniqueScreenKey -class MangaScreen(private val mangaId: Long) : Screen { +class MangaScreen( + private val mangaId: Long, +) : Screen { override val key: ScreenKey = uniqueScreenKey @Composable diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/manga/MangaScreenViewModel.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/manga/MangaScreenViewModel.kt index 85b13de3..e4065c91 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/manga/MangaScreenViewModel.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/manga/MangaScreenViewModel.kt @@ -259,7 +259,9 @@ class MangaScreenViewModel } } } + fun markRead(id: Long?) = setRead(listOfNotNull(id).ifEmpty { _selectedIds.value }, true) + fun markUnread(id: Long?) = setRead(listOfNotNull(id).ifEmpty { _selectedIds.value }, false) private fun setBookmarked( @@ -273,7 +275,9 @@ class MangaScreenViewModel } } } + fun bookmarkChapter(id: Long?) = setBookmarked(listOfNotNull(id).ifEmpty { _selectedIds.value }, true) + fun unBookmarkChapter(id: Long?) = setBookmarked(listOfNotNull(id).ifEmpty { _selectedIds.value }, false) fun markPreviousRead(index: Int) { @@ -332,6 +336,7 @@ class MangaScreenViewModel _selectedIds.value = _selectedIds.value.plus(id).toImmutableList() } } + fun unselectChapter(id: Long) { scope.launch { _selectedIds.value = _selectedIds.value.minus(id).toImmutableList() @@ -385,7 +390,9 @@ class MangaScreenViewModel ChapterDownloadItem(null, it) }.toImmutableList() - data class Params(val mangaId: Long) + data class Params( + val mangaId: Long, + ) private companion object { private val log = logging() diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/manga/components/MangaScreenContent.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/manga/components/MangaScreenContent.kt index df7279b2..15ee8bc3 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/manga/components/MangaScreenContent.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/manga/components/MangaScreenContent.kt @@ -226,7 +226,15 @@ fun MangaScreenContent( chapter, dateTimeFormatter, onClick = if (inActionMode) { - { if (chapter.isSelected.value) onUnselectChapter(chapter.chapter.id) else onSelectChapter(chapter.chapter.id) } + { + if (chapter.isSelected.value) { + onUnselectChapter( + chapter.chapter.id, + ) + } else { + onSelectChapter(chapter.chapter.id) + } + } } else { { readerLauncher.launch(it, manga.id) } }, @@ -293,8 +301,8 @@ private fun getActionItems( downloadNext: (Int) -> Unit, downloadUnread: () -> Unit, downloadAll: () -> Unit, -): ImmutableList { - return listOfNotNull( +): ImmutableList = + listOfNotNull( ActionItem( name = stringResource(MR.strings.action_refresh_manga), icon = Icons.Rounded.Refresh, @@ -353,15 +361,14 @@ private fun getActionItems( doAction = openInBrowser, ), ).toImmutableList() -} @Composable @Stable private fun getActionModeActionItems( selectAll: () -> Unit, invertSelection: () -> Unit, -): ImmutableList { - return listOf( +): ImmutableList = + listOf( ActionItem( name = stringResource(MR.strings.action_select_all), icon = Icons.Rounded.SelectAll, @@ -373,7 +380,6 @@ private fun getActionModeActionItems( doAction = invertSelection, ), ).toImmutableList() -} @Composable @Stable @@ -386,8 +392,8 @@ private fun getBottomActionItems( markPreviousAsRead: (Int) -> Unit, deleteChapter: () -> Unit, downloadChapters: () -> Unit, -): ImmutableList { - return listOfNotNull( +): ImmutableList = + listOfNotNull( BottomActionItem( name = stringResource(MR.strings.action_bookmark), icon = Icons.Rounded.BookmarkAdd, @@ -424,4 +430,3 @@ private fun getBottomActionItems( onClick = deleteChapter, ).takeIf { selectedItems.fastAny { it.downloadState.value == ChapterDownloadState.Downloaded } }, ).toImmutableList() -} diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/ChapterLoader.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/ChapterLoader.kt index e3a474bb..1e620f2c 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/ChapterLoader.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/ChapterLoader.kt @@ -56,9 +56,7 @@ class ChapterLoader( /** * Checks [chapter] to be loaded based on present pages and loader in addition to state. */ - private fun chapterIsReady(chapter: ReaderChapter): Boolean { - return chapter.state is ReaderChapter.State.Loaded && chapter.pageLoader != null - } + private fun chapterIsReady(chapter: ReaderChapter): Boolean = chapter.state is ReaderChapter.State.Loaded && chapter.pageLoader != null private companion object { private val log = logging() diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/ReaderMenuViewModel.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/ReaderMenuViewModel.kt index 47136bbb..cb7f2778 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/ReaderMenuViewModel.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/ReaderMenuViewModel.kt @@ -117,7 +117,7 @@ class ReaderMenuViewModel cur.orEmpty() + ReaderPageSeparator(viewerChapters.currChapter, viewerChapters.nextChapter) + next.orEmpty() - ).toImmutableList() + ).toImmutableList() } }.stateIn(scope, SharingStarted.Eagerly, persistentListOf()) @@ -441,7 +441,10 @@ class ReaderMenuViewModel scope.cancel() } - data class Params(val chapterIndex: Int, val mangaId: Long) + data class Params( + val chapterIndex: Int, + val mangaId: Long, + ) private companion object { private val log = logging() diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/loader/PageLoader.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/loader/PageLoader.kt index ba809145..602f2906 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/loader/PageLoader.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/loader/PageLoader.kt @@ -48,6 +48,10 @@ abstract class PageLoader { sealed class PagesState { object Loading : PagesState() - data class Success(val pages: List) : PagesState() + + data class Success( + val pages: List, + ) : PagesState() + object Empty : PagesState() } diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/loader/TachideskPageLoader.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/loader/TachideskPageLoader.kt index 57b732e0..70aca222 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/loader/TachideskPageLoader.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/loader/TachideskPageLoader.kt @@ -11,7 +11,6 @@ import ca.gosyer.jui.core.io.SYSTEM import ca.gosyer.jui.core.lang.IO import ca.gosyer.jui.core.lang.PriorityChannel import ca.gosyer.jui.core.lang.throwIfCancellation -import ca.gosyer.jui.domain.chapter.interactor.GetChapterPage import ca.gosyer.jui.domain.reader.service.ReaderPreferences import ca.gosyer.jui.domain.server.Http import ca.gosyer.jui.ui.base.image.BitmapDecoderFactory @@ -299,9 +298,7 @@ class TachideskPageLoader( private val ReaderPage.cacheKey get() = "${chapter.chapter.mangaId}-${chapter.chapter.index}-$index" - private fun DiskCache.Snapshot.source(): BufferedSource { - return FileSystem.SYSTEM.source(data).buffer() - } + private fun DiskCache.Snapshot.source(): BufferedSource = FileSystem.SYSTEM.source(data).buffer() private fun DiskCache.Editor.abortQuietly() { try { diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/model/Navigation.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/model/Navigation.kt index c67a8299..032d380d 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/model/Navigation.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/model/Navigation.kt @@ -6,12 +6,20 @@ package ca.gosyer.jui.ui.reader.model -sealed class Navigation(val name: String) { +sealed class Navigation( + val name: String, +) { object MENU : Navigation("Menu") + object PREV : Navigation("Prev") + object NEXT : Navigation("Next") + object LEFT : Navigation("Left") + object RIGHT : Navigation("Right") + object UP : Navigation("Up") + object DOWN : Navigation("Down") } diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/model/PageMove.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/model/PageMove.kt index 07329c15..fc7d962d 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/model/PageMove.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/model/PageMove.kt @@ -7,6 +7,11 @@ package ca.gosyer.jui.ui.reader.model sealed class PageMove { - data class Direction(val moveTo: MoveTo) : PageMove() - data class Page(val page: ReaderItem) : PageMove() + data class Direction( + val moveTo: MoveTo, + ) : PageMove() + + data class Page( + val page: ReaderItem, + ) : PageMove() } diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/model/ReaderChapter.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/model/ReaderChapter.kt index 7428420e..bc78c66b 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/model/ReaderChapter.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/model/ReaderChapter.kt @@ -24,7 +24,9 @@ import kotlinx.coroutines.flow.stateIn import org.lighthousegames.logging.logging @Immutable -data class ReaderChapter(val chapter: Chapter) { +data class ReaderChapter( + val chapter: Chapter, +) { val scope = CoroutineScope(Dispatchers.Default + Job()) private val _state = MutableStateFlow(State.Wait) @@ -57,9 +59,16 @@ data class ReaderChapter(val chapter: Chapter) { sealed class State { object Wait : State() + object Loading : State() - class Error(val error: Throwable) : State() - class Loaded(val pages: StateFlow) : State() + + class Error( + val error: Throwable, + ) : State() + + class Loaded( + val pages: StateFlow, + ) : State() } private companion object { diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/model/ReaderPage.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/model/ReaderPage.kt index 1b9d77e8..67acb176 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/model/ReaderPage.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/model/ReaderPage.kt @@ -30,12 +30,16 @@ data class ReaderPage( } @Immutable - data class BitmapInfo(val size: IntSize) + data class BitmapInfo( + val size: IntSize, + ) @Immutable sealed class ImageDecodeState { @Immutable - data class Success(val bitmap: ImageBitmap) : ImageDecodeState() + data class Success( + val bitmap: ImageBitmap, + ) : ImageDecodeState() @Immutable object UnknownDecoder : ImageDecodeState() @@ -44,6 +48,8 @@ data class ReaderPage( object FailedToGetSnapShot : ImageDecodeState() @Immutable - data class FailedToDecode(val exception: Throwable) : ImageDecodeState() + data class FailedToDecode( + val exception: Throwable, + ) : ImageDecodeState() } } diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/navigation/NavigationClickable.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/navigation/NavigationClickable.kt index 27ce06c2..082cfb39 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/navigation/NavigationClickable.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/navigation/NavigationClickable.kt @@ -62,7 +62,7 @@ fun Modifier.navigationClickable( detectTapGestures( onTap = { onClick(navigation.getAction(it, layoutSize.value)) - } + }, ) } .onGloballyPositioned { diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/navigation/ViewerNavigation.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/navigation/ViewerNavigation.kt index 7df62dc4..d7f34f8b 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/navigation/ViewerNavigation.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/navigation/ViewerNavigation.kt @@ -15,7 +15,10 @@ import ca.gosyer.jui.ui.reader.model.Navigation @Immutable abstract class ViewerNavigation { - data class Rect(val xRange: IntRange, val yRange: IntRange) { + data class Rect( + val xRange: IntRange, + val yRange: IntRange, + ) { private val right get() = xRange.last private val left get() = xRange.first private val bottom get() = yRange.last diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/viewer/Continuous.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/viewer/Continuous.kt index e0dfb348..8e58f1db 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/viewer/Continuous.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/viewer/Continuous.kt @@ -123,7 +123,10 @@ fun ContinuousReader( Direction.Up -> PaddingValues(top = padding.dp) Direction.Down -> PaddingValues(bottom = padding.dp) } - fun retry(index: Int) { pages.find { it is ReaderPage && it.index == index }?.let { retry(it as ReaderPage) } } + + fun retry(index: Int) { + pages.find { it is ReaderPage && it.index == index }?.let { retry(it as ReaderPage) } + } when (direction.isVertical) { true -> { diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/viewer/Pager.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/viewer/Pager.kt index b162ec32..90cfa644 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/viewer/Pager.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/reader/viewer/Pager.kt @@ -81,7 +81,10 @@ fun PagerReader( } } val modifier = parentModifier then Modifier.fillMaxSize() - fun retry(index: Int) { pages.find { it is ReaderPage && it.index == index }?.let { retry(it as ReaderPage) } } + + fun retry(index: Int) { + pages.find { it is ReaderPage && it.index == index }?.let { retry(it as ReaderPage) } + } if (direction.isVertical) { VerticalPager( diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsAdvancedScreen.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsAdvancedScreen.kt index d9f7059a..82b5baf6 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsAdvancedScreen.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsAdvancedScreen.kt @@ -108,6 +108,7 @@ class SettingsAdvancedViewModel chapterCache.clear() } } + companion object { private val log = logging() } diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsAppearanceScreen.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsAppearanceScreen.kt index e64156c3..9622ee72 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsAppearanceScreen.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsAppearanceScreen.kt @@ -123,9 +123,7 @@ class ThemesViewModel val windowDecorations = uiPreferences.windowDecorations().asStateFlow() @Composable - fun getActiveColors(): AppColorsPreferenceState { - return if (MaterialTheme.colors.isLight) lightColors else darkColors - } + fun getActiveColors(): AppColorsPreferenceState = if (MaterialTheme.colors.isLight) lightColors else darkColors } expect val showWindowDecorationsOption: Boolean diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsBackupScreen.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsBackupScreen.kt index d294cb69..bcf4c5ff 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsBackupScreen.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsBackupScreen.kt @@ -137,6 +137,7 @@ class SettingsBackupViewModel val creatingStatus = _creatingStatus.asStateFlow() private val _createFlow = MutableSharedFlow() val createFlowHolder = StableHolder(_createFlow.asSharedFlow()) + fun restoreFile(source: Source) { scope.launch { val file = try { @@ -268,8 +269,13 @@ class SettingsBackupViewModel sealed class Status { object Nothing : Status() - data class InProgress(val progress: Float?) : Status() + + data class InProgress( + val progress: Float?, + ) : Status() + object Success : Status() + object Error : Status() } diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsGeneralScreen.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsGeneralScreen.kt index 35983c0d..99987266 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsGeneralScreen.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsGeneralScreen.kt @@ -123,19 +123,16 @@ class SettingsGeneralViewModel } @Composable - fun getDateChoices(): ImmutableMap { - return dateHandler.formatOptions + fun getDateChoices(): ImmutableMap = + dateHandler.formatOptions .associateWith { it.ifEmpty { stringResource(MR.strings.date_system_default) } + " (${getFormattedDate(it)})" } .toImmutableMap() - } @Composable - private fun getFormattedDate(prefValue: String): String { - return dateHandler.getDateFormat(prefValue).invoke(now) - } + private fun getFormattedDate(prefValue: String): String = dateHandler.getDateFormat(prefValue).invoke(now) } @Composable diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsServerScreen.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsServerScreen.kt index 859ecce2..7c832747 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsServerScreen.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/settings/SettingsServerScreen.kt @@ -123,11 +123,13 @@ class SettingsServerViewModel Auth.BASIC to stringResource(MR.strings.basic_auth), Auth.DIGEST to stringResource(MR.strings.digest_auth), ) + val authUsername = serverPreferences.authUsername().asStateIn(scope) val authPassword = serverPreferences.authPassword().asStateIn(scope) private val _serverSettingChanged = MutableStateFlow(false) val serverSettingChanged = _serverSettingChanged.asStateFlow() + fun serverSettingChanged() { _serverSettingChanged.value = true } diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/SourceScreen.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/SourceScreen.kt index 0c639ce6..ddbf094c 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/SourceScreen.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/SourceScreen.kt @@ -20,7 +20,10 @@ import cafe.adriel.voyager.core.screen.ScreenKey import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow -class SourceScreen(val source: Source, private val initialQuery: String? = null) : BaseScreen() { +class SourceScreen( + val source: Source, + private val initialQuery: String? = null, +) : BaseScreen() { override val key: ScreenKey = source.id.toString() @Composable diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/SourceScreenViewModel.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/SourceScreenViewModel.kt index 4135f538..493abd6f 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/SourceScreenViewModel.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/SourceScreenViewModel.kt @@ -160,6 +160,7 @@ class SourceScreenViewModel( fun search(query: String) { _sourceSearchQuery.value = query } + fun submitSearch() { startSearch(sourceSearchQuery.value) } @@ -168,7 +169,10 @@ class SourceScreenViewModel( catalogPreferences.displayMode().set(displayMode) } - data class Params(val source: Source, val initialQuery: String?) + data class Params( + val source: Source, + val initialQuery: String?, + ) override fun onDispose() { super.onDispose() diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/components/SourceScreenContent.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/components/SourceScreenContent.kt index 2902e1e2..9f74155d 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/components/SourceScreenContent.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/components/SourceScreenContent.kt @@ -522,8 +522,8 @@ private fun getActionItems( onToggleFiltersClick: () -> Unit, onClickMode: () -> Unit, openDisplayModeSelect: () -> Unit, -): ImmutableList { - return listOfNotNull( +): ImmutableList = + listOfNotNull( if (showFilterButton) { ActionItem( name = stringResource(MR.strings.action_filter), @@ -568,4 +568,3 @@ private fun getActionItems( null }, ).toImmutableList() -} diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/filter/SourceFiltersMenu.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/filter/SourceFiltersMenu.kt index 56d0b40d..e7af7198 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/filter/SourceFiltersMenu.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/filter/SourceFiltersMenu.kt @@ -252,11 +252,13 @@ fun SortRow( } val angle: Float by animateFloatAsState( targetValue = if (rotation > 360 - rotation) { - -(360 - rotation) } else { + -(360 - rotation) + } else { rotation }, animationSpec = tween( - durationMillis = 500, // rotation is retrieved with this frequency + // rotation is retrieved with this frequency + durationMillis = 500, easing = LinearEasing, ), ) diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/filter/SourceFiltersViewModel.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/filter/SourceFiltersViewModel.kt index 2fbddef9..6196a07d 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/filter/SourceFiltersViewModel.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/filter/SourceFiltersViewModel.kt @@ -132,7 +132,9 @@ class SourceFiltersViewModel( getFilters(initialLoad = true) } - data class Params(val sourceId: Long) + data class Params( + val sourceId: Long, + ) private fun List.toView() = mapIndexed { index, sourcePreference -> diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/filter/model/SourceFiltersView.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/filter/model/SourceFiltersView.kt index a1a03693..743d902b 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/filter/model/SourceFiltersView.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/browse/filter/model/SourceFiltersView.kt @@ -23,6 +23,7 @@ sealed class SourceFiltersView { abstract val index: Int abstract val name: String abstract val state: StateFlow + abstract fun updateState(value: R) abstract val filter: T @@ -34,6 +35,7 @@ sealed class SourceFiltersView { private val _state: MutableStateFlow = MutableStateFlow(filter.state), ) : SourceFiltersView() { override val state: StateFlow = _state.asStateFlow() + override fun updateState(value: Boolean) { _state.value = value } @@ -50,6 +52,7 @@ sealed class SourceFiltersView { override val filter: HeaderFilter.HeaderProps, ) : SourceFiltersView() { override val state: StateFlow = MutableStateFlow(filter.state).asStateFlow() + override fun updateState(value: Any) { // NO-OP } @@ -59,12 +62,14 @@ sealed class SourceFiltersView { filter.filter, ) } + data class Separator internal constructor( override val index: Int, override val name: String, override val filter: SeparatorFilter.SeparatorProps, ) : SourceFiltersView() { override val state: StateFlow = MutableStateFlow(filter.state).asStateFlow() + override fun updateState(value: Any) { // NO-OP } @@ -82,6 +87,7 @@ sealed class SourceFiltersView { ) : SourceFiltersView() { private val _state = MutableStateFlow(filter.state) override val state: StateFlow = _state.asStateFlow() + override fun updateState(value: String) { _state.value = value } @@ -99,6 +105,7 @@ sealed class SourceFiltersView { private val _state: MutableStateFlow = MutableStateFlow(filter.state), ) : SourceFiltersView() { override val state: StateFlow = _state.asStateFlow() + override fun updateState(value: Int) { _state.value = value } @@ -116,6 +123,7 @@ sealed class SourceFiltersView { private val _state: MutableStateFlow = MutableStateFlow(filter.state), ) : SourceFiltersView() { override val state: StateFlow = _state.asStateFlow() + override fun updateState(value: Int) { _state.value = value } @@ -125,6 +133,7 @@ sealed class SourceFiltersView { filter.filter, ) } + data class Sort internal constructor( override val index: Int, override val name: String, @@ -132,6 +141,7 @@ sealed class SourceFiltersView { private val _state: MutableStateFlow = MutableStateFlow(filter.state), ) : SourceFiltersView() { override val state: StateFlow = _state.asStateFlow() + override fun updateState(value: SortFilter.Selection?) { _state.value = value } @@ -152,6 +162,7 @@ sealed class SourceFiltersView { SourceFiltersView(itemIndex, sourceFilter) }, ).asStateFlow() + override fun updateState(value: List>) { // NO-OP } @@ -167,8 +178,8 @@ sealed class SourceFiltersView { fun SourceFiltersView( index: Int, sourceFilter: SourceFilter, -): SourceFiltersView<*, *> { - return when (sourceFilter) { +): SourceFiltersView<*, *> = + when (sourceFilter) { is CheckBoxFilter -> SourceFiltersView.CheckBox(index, sourceFilter) is HeaderFilter -> SourceFiltersView.Header(index, sourceFilter) is SeparatorFilter -> SourceFiltersView.Separator(index, sourceFilter) @@ -178,4 +189,3 @@ fun SourceFiltersView( is SortFilter -> SourceFiltersView.Sort(index, sourceFilter) is GroupFilter -> SourceFiltersView.Group(index, sourceFilter) } -} diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/components/SourcesNavigator.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/components/SourcesNavigator.kt index 47e6b55e..e2947885 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/components/SourcesNavigator.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/components/SourcesNavigator.kt @@ -69,11 +69,10 @@ private val disposableEvents: Set = private fun rememberNavigator( parent: Navigator, homeScreen: SourceHomeScreen, -): SourcesNavigator { - return rememberSaveable(saver = navigatorSaver(parent, homeScreen)) { +): SourcesNavigator = + rememberSaveable(saver = navigatorSaver(parent, homeScreen)) { SourcesNavigator(parent, homeScreen) } -} private fun navigatorSaver( parent: Navigator, @@ -113,8 +112,12 @@ private fun SourceNavigatorDisposableEffect(navigator: SourcesNavigator) { sealed class SourceNavigatorScreen { object HomeScreen : SourceNavigatorScreen() + object SearchScreen : SourceNavigatorScreen() - data class SourceScreen(val source: Source) : SourceNavigatorScreen() + + data class SourceScreen( + val source: Source, + ) : SourceNavigatorScreen() } class SourcesNavigator internal constructor( diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/globalsearch/GlobalSearchScreen.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/globalsearch/GlobalSearchScreen.kt index 6b883c15..ab40a756 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/globalsearch/GlobalSearchScreen.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/globalsearch/GlobalSearchScreen.kt @@ -17,7 +17,9 @@ import ca.gosyer.jui.ui.stateViewModel import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow -class GlobalSearchScreen(private val initialQuery: String) : BaseScreen() { +class GlobalSearchScreen( + private val initialQuery: String, +) : BaseScreen() { @Composable override fun Content() { val vm = stateViewModel { diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/globalsearch/GlobalSearchViewModel.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/globalsearch/GlobalSearchViewModel.kt index abd56e73..a5a19b0f 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/globalsearch/GlobalSearchViewModel.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/globalsearch/GlobalSearchViewModel.kt @@ -147,12 +147,20 @@ class GlobalSearchViewModel search.value = query } - data class Params(val initialQuery: String) + data class Params( + val initialQuery: String, + ) sealed class Search { object Searching : Search() - data class Success(val mangaList: ImmutableList) : Search() - data class Failure(val e: String?) : Search() { + + data class Success( + val mangaList: ImmutableList, + ) : Search() + + data class Failure( + val e: String?, + ) : Search() { constructor(e: Throwable) : this(e.message) } } diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/globalsearch/components/GlobalSearchScreenContent.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/globalsearch/components/GlobalSearchScreenContent.kt index 1a3b6f4e..e626ed82 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/globalsearch/components/GlobalSearchScreenContent.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/globalsearch/components/GlobalSearchScreenContent.kt @@ -190,10 +190,16 @@ fun GlobalSearchItem( Spacer(Modifier.height(4.dp)) when (search) { - is Search.Failure -> Box(Modifier.fillMaxWidth().padding(vertical = 8.dp, horizontal = 16.dp), contentAlignment = Alignment.Center) { + is Search.Failure -> Box( + Modifier.fillMaxWidth().padding(vertical = 8.dp, horizontal = 16.dp), + contentAlignment = Alignment.Center, + ) { ErrorScreen(search.e) } - Search.Searching -> Box(Modifier.fillMaxWidth().padding(vertical = 8.dp, horizontal = 16.dp), contentAlignment = Alignment.Center) { + Search.Searching -> Box( + Modifier.fillMaxWidth().padding(vertical = 8.dp, horizontal = 16.dp), + contentAlignment = Alignment.Center, + ) { CircularProgressIndicator() } is Search.Success -> Box( diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/home/SourceHomeScreenViewModel.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/home/SourceHomeScreenViewModel.kt index 1e6a5638..cc2ad0bf 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/home/SourceHomeScreenViewModel.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/home/SourceHomeScreenViewModel.kt @@ -131,8 +131,12 @@ class SourceHomeScreenViewModel @Stable sealed class SourceUI { @Stable - data class Header(val header: String) : SourceUI() + data class Header( + val header: String, + ) : SourceUI() @Stable - data class SourceItem(val source: Source) : SourceUI() + data class SourceItem( + val source: Source, + ) : SourceUI() } diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/home/components/SourceHomeScreenContent.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/home/components/SourceHomeScreenContent.kt index 8e3baafd..e5bf0757 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/home/components/SourceHomeScreenContent.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/home/components/SourceHomeScreenContent.kt @@ -350,12 +350,11 @@ fun ThinSourceItem( @Composable @Stable -private fun getActionItems(openEnabledLanguagesClick: () -> Unit): ImmutableList { - return persistentListOf( +private fun getActionItems(openEnabledLanguagesClick: () -> Unit): ImmutableList = + persistentListOf( ActionItem( stringResource(MR.strings.enabled_languages), Icons.Rounded.Translate, doAction = openEnabledLanguagesClick, ), ).toImmutableList() -} diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/settings/SourceSettingsScreen.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/settings/SourceSettingsScreen.kt index f0c0f17f..0ddedfd7 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/settings/SourceSettingsScreen.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/settings/SourceSettingsScreen.kt @@ -14,7 +14,9 @@ import cafe.adriel.voyager.core.screen.Screen import cafe.adriel.voyager.core.screen.ScreenKey import cafe.adriel.voyager.core.screen.uniqueScreenKey -class SourceSettingsScreen(private val sourceId: Long) : Screen { +class SourceSettingsScreen( + private val sourceId: Long, +) : Screen { override val key: ScreenKey = uniqueScreenKey @Composable diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/settings/SourceSettingsScreenViewModel.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/settings/SourceSettingsScreenViewModel.kt index 19dab39c..0356ad9b 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/settings/SourceSettingsScreenViewModel.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/settings/SourceSettingsScreenViewModel.kt @@ -78,7 +78,9 @@ class SourceSettingsScreenViewModel .launchIn(scope) } - data class Params(val sourceId: Long) + data class Params( + val sourceId: Long, + ) private fun List.toView() = mapIndexed { index, sourcePreference -> diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/settings/model/SourceSettingsView.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/settings/model/SourceSettingsView.kt index 5b625057..f99852be 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/settings/model/SourceSettingsView.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/sources/settings/model/SourceSettingsView.kt @@ -28,6 +28,7 @@ sealed class SourceSettingsView { abstract val title: String? abstract val subtitle: String? abstract val state: StateFlow + abstract fun updateState(value: R) abstract val props: T @@ -44,6 +45,7 @@ sealed class SourceSettingsView { ), ) : SourceSettingsView() { override val state: StateFlow = _state.asStateFlow() + override fun updateState(value: Boolean) { _state.value = value } @@ -87,6 +89,7 @@ sealed class SourceSettingsView { props.currentValue ?: props.defaultValue ?: "0", ) override val state: StateFlow = _state.asStateFlow() + override fun updateState(value: String) { _state.value = value } @@ -116,6 +119,7 @@ sealed class SourceSettingsView { props.currentValue?.toImmutableList() ?: props.defaultValue?.toImmutableList(), ) override val state: StateFlow?> = _state.asStateFlow() + override fun updateState(value: ImmutableList?) { _state.value = value } @@ -150,6 +154,7 @@ sealed class SourceSettingsView { ) : SourceSettingsView() { private val _state = MutableStateFlow(props.currentValue ?: props.defaultValue.orEmpty()) override val state: StateFlow = _state.asStateFlow() + override fun updateState(value: String) { _state.value = value } @@ -167,19 +172,16 @@ sealed class SourceSettingsView { private fun withFormat( text: String, value: Any?, -): String { - return stringFormat(text, value) -} +): String = stringFormat(text, value) fun SourceSettingsView( index: Int, preference: SourcePreference, -): SourceSettingsView<*, *> { - return when (preference) { +): SourceSettingsView<*, *> = + when (preference) { is CheckBoxPreference -> SourceSettingsView.CheckBox(index, preference) is SwitchPreference -> SourceSettingsView.Switch(index, preference) is ListPreference -> SourceSettingsView.List(index, preference) is MultiSelectListPreference -> SourceSettingsView.MultiSelect(index, preference) is EditTextPreference -> SourceSettingsView.EditText(index, preference) } -} diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/updates/UpdatesScreenViewModel.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/updates/UpdatesScreenViewModel.kt index e570bb5d..1ed43688 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/updates/UpdatesScreenViewModel.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/updates/UpdatesScreenViewModel.kt @@ -123,7 +123,9 @@ class UpdatesScreenViewModel _selectedIds.value = persistentListOf() } } + fun markRead(id: Long?) = setRead(listOfNotNull(id).ifEmpty { _selectedIds.value }, true) + fun markUnread(id: Long?) = setRead(listOfNotNull(id).ifEmpty { _selectedIds.value }, false) private fun setBookmarked( @@ -135,7 +137,9 @@ class UpdatesScreenViewModel _selectedIds.value = persistentListOf() } } + fun bookmarkChapter(id: Long?) = setBookmarked(listOfNotNull(id).ifEmpty { _selectedIds.value }, true) + fun unBookmarkChapter(id: Long?) = setBookmarked(listOfNotNull(id).ifEmpty { _selectedIds.value }, false) fun downloadChapter(chapter: Chapter?) { @@ -207,6 +211,7 @@ class UpdatesScreenViewModel _selectedIds.value = _selectedIds.value.plus(id).toImmutableList() } } + fun unselectChapter(id: Long) { scope.launchDefault { _selectedIds.value = _selectedIds.value.minus(id).toImmutableList() @@ -234,6 +239,11 @@ class UpdatesScreenViewModel } sealed class UpdatesUI { - data class Item(val chapterDownloadItem: ChapterDownloadItem) : UpdatesUI() - data class Header(val date: String) : UpdatesUI() + data class Item( + val chapterDownloadItem: ChapterDownloadItem, + ) : UpdatesUI() + + data class Header( + val date: String, + ) : UpdatesUI() } diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/updates/components/UpdatesScreenContent.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/updates/components/UpdatesScreenContent.kt index 21e19b6d..1f525de0 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/updates/components/UpdatesScreenContent.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/updates/components/UpdatesScreenContent.kt @@ -128,7 +128,8 @@ fun UpdatesScreenContent( getActionItems( onUpdateLibrary, updateWebsocketStatus, - restartLibraryUpdates, // todo set null if wide screen + // todo set null if wide screen + restartLibraryUpdates, ) } }, @@ -190,7 +191,13 @@ fun UpdatesScreenContent( chapterDownloadItem = item.chapterDownloadItem, onClickItem = if (inActionMode) { { - if (item.chapterDownloadItem.isSelected.value) onUnselectChapter(item.chapterDownloadItem.chapter.id) else onSelectChapter(item.chapterDownloadItem.chapter.id) + if (item.chapterDownloadItem.isSelected.value) { + onUnselectChapter( + item.chapterDownloadItem.chapter.id, + ) + } else { + onSelectChapter(item.chapterDownloadItem.chapter.id) + } } } else { { openChapter(chapter.index, manga.id) } @@ -234,8 +241,8 @@ private fun getActionItems( onUpdateLibrary: () -> Unit, updateWebsocketStatus: WebsocketService.Status? = null, restartLibraryUpdates: (() -> Unit)? = null, -): ImmutableList { - return listOfNotNull( +): ImmutableList = + listOfNotNull( ActionItem( name = stringResource(MR.strings.action_update_library), icon = Icons.Rounded.Refresh, @@ -251,15 +258,14 @@ private fun getActionItems( null }, ).toImmutableList() -} @Composable @Stable private fun getActionModeActionItems( selectAll: () -> Unit, invertSelection: () -> Unit, -): ImmutableList { - return listOf( +): ImmutableList = + listOf( ActionItem( name = stringResource(MR.strings.action_select_all), icon = Icons.Rounded.SelectAll, @@ -271,7 +277,6 @@ private fun getActionModeActionItems( doAction = invertSelection, ), ).toImmutableList() -} @Composable @Stable @@ -283,8 +288,8 @@ private fun getBottomActionItems( unBookmarkChapter: () -> Unit, deleteChapter: () -> Unit, downloadChapters: () -> Unit, -): ImmutableList { - return listOfNotNull( +): ImmutableList = + listOfNotNull( BottomActionItem( name = stringResource(MR.strings.action_bookmark), icon = Icons.Rounded.BookmarkAdd, @@ -316,4 +321,3 @@ private fun getBottomActionItems( onClick = deleteChapter, ).takeIf { selectedItems.fastAny { it.downloadState.value == ChapterDownloadState.Downloaded } }, ).toImmutableList() -} diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/util/compose/Offset.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/util/compose/Offset.kt index bed2e7fb..de40a081 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/util/compose/Offset.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/util/compose/Offset.kt @@ -11,10 +11,6 @@ import androidx.compose.ui.geometry.Size import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.IntSize -operator fun IntSize.contains(offset: IntOffset): Boolean { - return offset.x <= width && offset.y <= height -} +operator fun IntSize.contains(offset: IntOffset): Boolean = offset.x <= width && offset.y <= height -operator fun Size.contains(offset: Offset): Boolean { - return offset.x <= width && offset.y <= height -} +operator fun Size.contains(offset: Offset): Boolean = offset.x <= width && offset.y <= height diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/util/lang/Collator.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/util/lang/Collator.kt index fb32b9fe..e416c09c 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/util/lang/Collator.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/util/lang/Collator.kt @@ -8,7 +8,9 @@ package ca.gosyer.jui.ui.util.lang import androidx.compose.ui.text.intl.Locale -expect class CollatorComparator(locale: Locale) : Comparator { +expect class CollatorComparator( + locale: Locale, +) : Comparator { override fun compare( source: String, target: String, diff --git a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/components/DesktopTooltipArea.kt b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/components/DesktopTooltipArea.kt index ffa0bef4..37ed8323 100644 --- a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/components/DesktopTooltipArea.kt +++ b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/components/DesktopTooltipArea.kt @@ -22,10 +22,10 @@ actual class CursorPointImpl actual constructor( alignment: Alignment, windowMargin: Dp, ) : TooltipPlacement by androidx.compose.foundation.TooltipPlacement.CursorPoint( - offset = offset, - alignment = alignment, - windowMargin = windowMargin -) + offset = offset, + alignment = alignment, + windowMargin = windowMargin, + ) @OptIn(ExperimentalFoundationApi::class) actual class ComponentRectImpl actual constructor( @@ -33,10 +33,10 @@ actual class ComponentRectImpl actual constructor( alignment: Alignment, offset: DpOffset, ) : TooltipPlacement by androidx.compose.foundation.TooltipPlacement.ComponentRect( - anchor = anchor, - alignment = alignment, - offset = offset -) + anchor = anchor, + alignment = alignment, + offset = offset, + ) @OptIn(ExperimentalFoundationApi::class) @Composable diff --git a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/file/DesktopFileChooser.kt b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/file/DesktopFileChooser.kt index 023b71de..36c3480c 100644 --- a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/file/DesktopFileChooser.kt +++ b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/file/DesktopFileChooser.kt @@ -16,7 +16,10 @@ import okio.source import javax.swing.JFileChooser import javax.swing.filechooser.FileNameExtensionFilter -actual class FileChooser(private val onFileFound: (Source) -> Unit, private val scope: CoroutineScope) { +actual class FileChooser( + private val onFileFound: (Source) -> Unit, + private val scope: CoroutineScope, +) { private val fileChooser = JFileChooser() .apply { val details = actionMap.get("viewTypeDetails") diff --git a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/image/DesktopBitmapDecoderFactory.kt b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/image/DesktopBitmapDecoderFactory.kt index 260338fe..d924ff09 100644 --- a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/image/DesktopBitmapDecoderFactory.kt +++ b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/image/DesktopBitmapDecoderFactory.kt @@ -10,5 +10,6 @@ import ca.gosyer.jui.uicore.vm.ContextWrapper import com.seiko.imageloader.component.decoder.Decoder import com.seiko.imageloader.component.decoder.SkiaImageDecoder -actual class BitmapDecoderFactory actual constructor(contextWrapper: ContextWrapper) : - Decoder.Factory by SkiaImageDecoder.Factory() +actual class BitmapDecoderFactory actual constructor( + contextWrapper: ContextWrapper, +) : Decoder.Factory by SkiaImageDecoder.Factory() diff --git a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/prefs/DesktopColorExtensions.kt b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/prefs/DesktopColorExtensions.kt index 15602307..4fbbf5e2 100644 --- a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/prefs/DesktopColorExtensions.kt +++ b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/prefs/DesktopColorExtensions.kt @@ -17,11 +17,10 @@ internal actual fun Color.toHsv(): FloatArray { return result } -internal actual fun hexStringToColor(hex: String): Color? { - return try { +internal actual fun hexStringToColor(hex: String): Color? = + try { val color = java.awt.Color.decode(hex) Color(color.red, color.green, color.blue, color.alpha) } catch (e: Exception) { null } -} diff --git a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/theme/ThemeScrollbarStyle.kt b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/theme/ThemeScrollbarStyle.kt index 4d13b676..281cb5d8 100644 --- a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/theme/ThemeScrollbarStyle.kt +++ b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/base/theme/ThemeScrollbarStyle.kt @@ -15,8 +15,8 @@ import ca.gosyer.jui.uicore.components.ScrollbarStyle actual object ThemeScrollbarStyle { @Stable @Composable - actual fun getScrollbarStyle(): ScrollbarStyle { - return androidx.compose.foundation.ScrollbarStyle( + actual fun getScrollbarStyle(): ScrollbarStyle = + androidx.compose.foundation.ScrollbarStyle( minimalHeight = 16.dp, thickness = 8.dp, shape = MaterialTheme.shapes.small, @@ -24,5 +24,4 @@ actual object ThemeScrollbarStyle { unhoverColor = MaterialTheme.colors.onSurface.copy(alpha = 0.30f), hoverColor = MaterialTheme.colors.onSurface.copy(alpha = 0.70f), ) - } } diff --git a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/categories/CategoriesWindow.kt b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/categories/CategoriesWindow.kt index f75987f8..097c022a 100644 --- a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/categories/CategoriesWindow.kt +++ b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/categories/CategoriesWindow.kt @@ -16,7 +16,9 @@ import androidx.compose.ui.window.Window import ca.gosyer.jui.presentation.build.BuildKonfig import cafe.adriel.voyager.navigator.Navigator -actual class CategoriesLauncher(private val notifyFinished: () -> Unit) { +actual class CategoriesLauncher( + private val notifyFinished: () -> Unit, +) { private var isOpen by mutableStateOf(false) actual fun open() { @@ -38,6 +40,5 @@ actual class CategoriesLauncher(private val notifyFinished: () -> Unit) { } @Composable -actual fun rememberCategoriesLauncher(notifyFinished: () -> Unit): CategoriesLauncher { - return remember(notifyFinished) { CategoriesLauncher(notifyFinished) } -} +actual fun rememberCategoriesLauncher(notifyFinished: () -> Unit): CategoriesLauncher = + remember(notifyFinished) { CategoriesLauncher(notifyFinished) } diff --git a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/library/components/DesktopLibraryGrid.kt b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/library/components/DesktopLibraryGrid.kt index 2516757a..0aff5f85 100644 --- a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/library/components/DesktopLibraryGrid.kt +++ b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/library/components/DesktopLibraryGrid.kt @@ -29,8 +29,7 @@ actual fun Modifier.libraryMangaModifier( @Composable @Stable -private fun getContextItems(onClickRemoveManga: () -> Unit): List { - return listOf( +private fun getContextItems(onClickRemoveManga: () -> Unit): List = + listOf( ContextMenuItem(stringResource(MR.strings.action_remove_favorite), onClickRemoveManga), ) -} diff --git a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/manga/components/DesktopChapterItem.kt b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/manga/components/DesktopChapterItem.kt index 2e776dd1..d5944ae2 100644 --- a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/manga/components/DesktopChapterItem.kt +++ b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/manga/components/DesktopChapterItem.kt @@ -55,12 +55,11 @@ private fun getContextItems( bookmarkChapter: (() -> Unit)?, unBookmarkChapter: (() -> Unit)?, markPreviousAsRead: () -> Unit, -): List { - return listOfNotNull( +): List = + listOfNotNull( if (bookmarkChapter != null) ContextMenuItem(stringResource(MR.strings.action_bookmark), bookmarkChapter) else null, if (unBookmarkChapter != null) ContextMenuItem(stringResource(MR.strings.action_remove_bookmark), unBookmarkChapter) else null, if (markRead != null) ContextMenuItem(stringResource(MR.strings.action_mark_as_read), markRead) else null, if (markUnread != null) ContextMenuItem(stringResource(MR.strings.action_mark_as_unread), markUnread) else null, ContextMenuItem(stringResource(MR.strings.action_mark_previous_read), markPreviousAsRead), ) -} diff --git a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/reader/DesktopReaderMenu.kt b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/reader/DesktopReaderMenu.kt index e3f3c002..2448856b 100644 --- a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/reader/DesktopReaderMenu.kt +++ b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/reader/DesktopReaderMenu.kt @@ -67,6 +67,4 @@ actual class ReaderLauncher { } @Composable -actual fun rememberReaderLauncher(): ReaderLauncher { - return remember { ReaderLauncher() } -} +actual fun rememberReaderLauncher(): ReaderLauncher = remember { ReaderLauncher() } diff --git a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/settings/DesktopSettingsServerScreen.kt b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/settings/DesktopSettingsServerScreen.kt index ff8ec4d7..67b2cf73 100644 --- a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/settings/DesktopSettingsServerScreen.kt +++ b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/settings/DesktopSettingsServerScreen.kt @@ -108,6 +108,7 @@ actual class SettingsServerHostViewModel private val _serverSettingChanged = MutableStateFlow(false) val serverSettingChanged = _serverSettingChanged.asStateFlow() + fun serverSettingChanged() { _serverSettingChanged.value = true } diff --git a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/updates/components/DesktopUpdatesItem.kt b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/updates/components/DesktopUpdatesItem.kt index 2d989859..a5ed62b8 100644 --- a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/updates/components/DesktopUpdatesItem.kt +++ b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/updates/components/DesktopUpdatesItem.kt @@ -52,11 +52,10 @@ private fun getContextItems( markUnread: (() -> Unit)?, bookmarkChapter: (() -> Unit)?, unBookmarkChapter: (() -> Unit)?, -): List { - return listOfNotNull( +): List = + listOfNotNull( if (bookmarkChapter != null) ContextMenuItem(stringResource(MR.strings.action_bookmark), bookmarkChapter) else null, if (unBookmarkChapter != null) ContextMenuItem(stringResource(MR.strings.action_remove_bookmark), unBookmarkChapter) else null, if (markRead != null) ContextMenuItem(stringResource(MR.strings.action_mark_as_read), markRead) else null, if (markUnread != null) ContextMenuItem(stringResource(MR.strings.action_mark_as_unread), markUnread) else null, ) -} diff --git a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/util/compose/Image.kt b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/util/compose/Image.kt index da237dea..4cd1069e 100644 --- a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/util/compose/Image.kt +++ b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/util/compose/Image.kt @@ -19,22 +19,18 @@ import okio.Path import okio.buffer import org.jetbrains.skia.Image -fun imageFromFile(file: Path): ImageBitmap { - return Image.makeFromEncoded(FileSystem.SYSTEM.source(file).buffer().readByteArray()) +fun imageFromFile(file: Path): ImageBitmap = + Image.makeFromEncoded(FileSystem.SYSTEM.source(file).buffer().readByteArray()) .toComposeImageBitmap() -} suspend fun imageFromUrl( client: Http, url: String, block: HttpRequestBuilder.() -> Unit, -): ImageBitmap { - return client.get(url) { +): ImageBitmap = + client.get(url) { expectSuccess = true block() }.toImageBitmap() -} -actual suspend fun HttpResponse.toImageBitmap(): ImageBitmap { - return Image.makeFromEncoded(body()).toComposeImageBitmap() -} +actual suspend fun HttpResponse.toImageBitmap(): ImageBitmap = Image.makeFromEncoded(body()).toComposeImageBitmap() diff --git a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/file/IosFileChooser.kt b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/file/IosFileChooser.kt index 606300f4..b82759cc 100644 --- a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/file/IosFileChooser.kt +++ b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/file/IosFileChooser.kt @@ -10,13 +10,13 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import okio.Source -actual class FileChooser(private val onFileFound: (Source) -> Unit) { +actual class FileChooser( + private val onFileFound: (Source) -> Unit, +) { actual fun launch(extension: String) { TODO() } } @Composable -actual fun rememberFileChooser(onFileFound: (Source) -> Unit): FileChooser { - return remember { FileChooser(onFileFound) } -} +actual fun rememberFileChooser(onFileFound: (Source) -> Unit): FileChooser = remember { FileChooser(onFileFound) } diff --git a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/file/IosFileSaver.kt b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/file/IosFileSaver.kt index 529231b3..a4e9579a 100644 --- a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/file/IosFileSaver.kt +++ b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/file/IosFileSaver.kt @@ -25,6 +25,4 @@ internal actual fun realRememberFileSaver( onFileSelected: (Sink) -> Unit, onCancel: () -> Unit, onError: () -> Unit, -): FileSaver { - return remember { FileSaver(onFileSelected, onCancel, onError) } -} +): FileSaver = remember { FileSaver(onFileSelected, onCancel, onError) } diff --git a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/image/IosBitmapDecoderFactory.kt b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/image/IosBitmapDecoderFactory.kt index 260338fe..d924ff09 100644 --- a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/image/IosBitmapDecoderFactory.kt +++ b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/image/IosBitmapDecoderFactory.kt @@ -10,5 +10,6 @@ import ca.gosyer.jui.uicore.vm.ContextWrapper import com.seiko.imageloader.component.decoder.Decoder import com.seiko.imageloader.component.decoder.SkiaImageDecoder -actual class BitmapDecoderFactory actual constructor(contextWrapper: ContextWrapper) : - Decoder.Factory by SkiaImageDecoder.Factory() +actual class BitmapDecoderFactory actual constructor( + contextWrapper: ContextWrapper, +) : Decoder.Factory by SkiaImageDecoder.Factory() diff --git a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/image/IosImageLoaderBuilder.kt b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/image/IosImageLoaderBuilder.kt index 04934f8c..d0732c19 100644 --- a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/image/IosImageLoaderBuilder.kt +++ b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/image/IosImageLoaderBuilder.kt @@ -41,15 +41,14 @@ actual fun DiskCacheBuilder.configure( } @OptIn(ExperimentalForeignApi::class) -private fun getCacheDir(): String { - return NSFileManager.defaultManager.URLForDirectory( +private fun getCacheDir(): String = + NSFileManager.defaultManager.URLForDirectory( NSCachesDirectory, NSUserDomainMask, null, true, null, )!!.path.orEmpty() -} actual fun MemoryCacheBuilder.configure(contextWrapper: ContextWrapper) { maxSizePercent(0.25) diff --git a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/prefs/IosColorExtensions.kt b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/prefs/IosColorExtensions.kt index 0d0f2d64..06c104e3 100644 --- a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/prefs/IosColorExtensions.kt +++ b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/prefs/IosColorExtensions.kt @@ -30,11 +30,10 @@ internal actual fun Color.toHsv(): FloatArray = floatArrayOf(hue.value.toFloat(), saturation.value.toFloat(), brightness.value.toFloat()) } -internal actual fun hexStringToColor(hex: String): Color? { - return try { +internal actual fun hexStringToColor(hex: String): Color? = + try { val i = hex.removePrefix("#").toInt(16) Color(i shr 16 and 0xFF, i shr 8 and 0xFF, i and 0xFF) } catch (e: Exception) { null } -} diff --git a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/theme/ThemeScrollbarStyle.kt b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/theme/ThemeScrollbarStyle.kt index f84fe5f1..ecfaccad 100644 --- a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/theme/ThemeScrollbarStyle.kt +++ b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/base/theme/ThemeScrollbarStyle.kt @@ -15,7 +15,5 @@ actual object ThemeScrollbarStyle { @Stable @Composable - actual fun getScrollbarStyle(): ScrollbarStyle { - return defaultScrollbarStyle - } + actual fun getScrollbarStyle(): ScrollbarStyle = defaultScrollbarStyle } diff --git a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/categories/OpenCategories.kt b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/categories/OpenCategories.kt index d9564fcc..8b46d934 100644 --- a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/categories/OpenCategories.kt +++ b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/categories/OpenCategories.kt @@ -11,7 +11,9 @@ import androidx.compose.runtime.remember import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.Navigator -actual class CategoriesLauncher(private val navigator: Navigator?) { +actual class CategoriesLauncher( + private val navigator: Navigator?, +) { actual fun open() { navigator?.push(CategoriesScreen()) } diff --git a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/main/components/DebugOverlayViewModel.kt b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/main/components/DebugOverlayViewModel.kt index dceef75c..191228b4 100644 --- a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/main/components/DebugOverlayViewModel.kt +++ b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/main/components/DebugOverlayViewModel.kt @@ -13,7 +13,9 @@ import me.tatarka.inject.annotations.Inject actual class DebugOverlayViewModel @Inject - constructor(contextWrapper: ContextWrapper) : ViewModel(contextWrapper) { + constructor( + contextWrapper: ContextWrapper, + ) : ViewModel(contextWrapper) { actual val maxMemory: String get() = "" actual val usedMemoryFlow: MutableStateFlow = MutableStateFlow("") diff --git a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/reader/IosReaderMenu.kt b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/reader/IosReaderMenu.kt index 5072cd2d..bec36deb 100644 --- a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/reader/IosReaderMenu.kt +++ b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/reader/IosReaderMenu.kt @@ -13,7 +13,10 @@ import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.Navigator import cafe.adriel.voyager.navigator.currentOrThrow -class ReaderScreen(val chapterIndex: Int, val mangaId: Long) : Screen { +class ReaderScreen( + val chapterIndex: Int, + val mangaId: Long, +) : Screen { @Composable override fun Content() { val navigator = LocalNavigator.currentOrThrow @@ -25,7 +28,9 @@ class ReaderScreen(val chapterIndex: Int, val mangaId: Long) : Screen { } } -actual class ReaderLauncher(private val navigator: Navigator?) { +actual class ReaderLauncher( + private val navigator: Navigator?, +) { actual fun launch( chapterIndex: Int, mangaId: Long, diff --git a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/settings/IosSettingsServerScreen.kt b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/settings/IosSettingsServerScreen.kt index 9f6e7c9b..3f98c566 100644 --- a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/settings/IosSettingsServerScreen.kt +++ b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/settings/IosSettingsServerScreen.kt @@ -13,10 +13,10 @@ import ca.gosyer.jui.uicore.vm.ViewModel import me.tatarka.inject.annotations.Inject @Composable -actual fun getServerHostItems(viewModel: @Composable () -> SettingsServerHostViewModel): LazyListScope.() -> Unit { - return {} -} +actual fun getServerHostItems(viewModel: @Composable () -> SettingsServerHostViewModel): LazyListScope.() -> Unit = {} actual class SettingsServerHostViewModel @Inject - constructor(contextWrapper: ContextWrapper) : ViewModel(contextWrapper) + constructor( + contextWrapper: ContextWrapper, + ) : ViewModel(contextWrapper) diff --git a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/util/compose/Image.kt b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/util/compose/Image.kt index 2abfc0cb..91587bff 100644 --- a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/util/compose/Image.kt +++ b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/util/compose/Image.kt @@ -12,6 +12,4 @@ import io.ktor.client.call.body import io.ktor.client.statement.HttpResponse import org.jetbrains.skia.Image -actual suspend fun HttpResponse.toImageBitmap(): ImageBitmap { - return Image.makeFromEncoded(body()).toComposeImageBitmap() -} +actual suspend fun HttpResponse.toImageBitmap(): ImageBitmap = Image.makeFromEncoded(body()).toComposeImageBitmap() diff --git a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/util/compose/IosColor.kt b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/util/compose/IosColor.kt index cae849f2..6349c7f1 100644 --- a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/util/compose/IosColor.kt +++ b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/util/compose/IosColor.kt @@ -11,8 +11,6 @@ import androidx.compose.ui.graphics.toArgb import platform.Foundation.NSString import platform.Foundation.stringWithFormat -actual fun Color.toHexString(): String { - return NSString.stringWithFormat("#%06X", (0xFFFFFF and toArgb())) -} +actual fun Color.toHexString(): String = NSString.stringWithFormat("#%06X", (0xFFFFFF and toArgb())) actual fun Color.toLong() = NSString.stringWithFormat("%06X", 0xFFFFFF and toArgb()).toLong(16) diff --git a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/util/lang/Collator.kt b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/util/lang/Collator.kt index 1104b563..d3f0d32c 100644 --- a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/util/lang/Collator.kt +++ b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/util/lang/Collator.kt @@ -10,7 +10,7 @@ import androidx.compose.ui.text.intl.Locale import platform.Foundation.NSString import platform.Foundation.localizedCaseInsensitiveCompare -actual class CollatorComparator() : Comparator { +actual class CollatorComparator : Comparator { actual constructor(locale: Locale) : this() actual override fun compare( diff --git a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/util/lang/IosOkio.kt b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/util/lang/IosOkio.kt index aa16a316..3bad8b84 100644 --- a/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/util/lang/IosOkio.kt +++ b/presentation/src/iosMain/kotlin/ca/gosyer/jui/ui/util/lang/IosOkio.kt @@ -11,6 +11,4 @@ import io.ktor.util.toByteArray import io.ktor.utils.io.ByteReadChannel import okio.Source -actual suspend fun ByteReadChannel.toSource(): Source { - return this.toByteArray().source() -} +actual suspend fun ByteReadChannel.toSource(): Source = this.toByteArray().source() diff --git a/presentation/src/jvmMain/kotlin/ca/gosyer/jui/ui/main/components/DebugOverlayViewModel.kt b/presentation/src/jvmMain/kotlin/ca/gosyer/jui/ui/main/components/DebugOverlayViewModel.kt index 9169e5d2..665cb3d6 100644 --- a/presentation/src/jvmMain/kotlin/ca/gosyer/jui/ui/main/components/DebugOverlayViewModel.kt +++ b/presentation/src/jvmMain/kotlin/ca/gosyer/jui/ui/main/components/DebugOverlayViewModel.kt @@ -18,7 +18,9 @@ import kotlin.time.Duration.Companion.milliseconds actual class DebugOverlayViewModel @Inject - constructor(contextWrapper: ContextWrapper) : ViewModel(contextWrapper) { + constructor( + contextWrapper: ContextWrapper, + ) : ViewModel(contextWrapper) { override val scope = MainScope() val runtime: Runtime = Runtime.getRuntime() diff --git a/presentation/src/jvmMain/kotlin/ca/gosyer/jui/ui/util/compose/JvmColor.kt b/presentation/src/jvmMain/kotlin/ca/gosyer/jui/ui/util/compose/JvmColor.kt index 0cd0700c..5975c408 100644 --- a/presentation/src/jvmMain/kotlin/ca/gosyer/jui/ui/util/compose/JvmColor.kt +++ b/presentation/src/jvmMain/kotlin/ca/gosyer/jui/ui/util/compose/JvmColor.kt @@ -9,8 +9,6 @@ package ca.gosyer.jui.ui.util.compose import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.toArgb -actual fun Color.toHexString(): String { - return String.format("#%06X", (0xFFFFFF and toArgb())) -} +actual fun Color.toHexString(): String = String.format("#%06X", (0xFFFFFF and toArgb())) actual fun Color.toLong() = String.format("%06X", 0xFFFFFF and toArgb()).toLong(16) diff --git a/presentation/src/jvmMain/kotlin/ca/gosyer/jui/ui/util/lang/Collator.kt b/presentation/src/jvmMain/kotlin/ca/gosyer/jui/ui/util/lang/Collator.kt index 317e1143..b7d6b6a1 100644 --- a/presentation/src/jvmMain/kotlin/ca/gosyer/jui/ui/util/lang/Collator.kt +++ b/presentation/src/jvmMain/kotlin/ca/gosyer/jui/ui/util/lang/Collator.kt @@ -10,7 +10,9 @@ import androidx.compose.ui.text.intl.Locale import ca.gosyer.jui.core.lang.toPlatform import java.text.Collator -actual class CollatorComparator(private val collator: Collator) : Comparator { +actual class CollatorComparator( + private val collator: Collator, +) : Comparator { actual constructor(locale: Locale) : this(Collator.getInstance(locale.toPlatform())) init { @@ -20,7 +22,5 @@ actual class CollatorComparator(private val collator: Collator) : Comparator Image( painter = rememberImageActionPainter( imageAction, - filterQuality = filterQuality + filterQuality = filterQuality, ), contentDescription = contentDescription, modifier = Modifier.fillMaxSize(), diff --git a/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/pager/Pager.kt b/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/pager/Pager.kt index 97182a50..05f29fa9 100644 --- a/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/pager/Pager.kt +++ b/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/pager/Pager.kt @@ -181,7 +181,9 @@ fun rememberPagerState(initialPage: Int = 0) = class PagerState( currentPage: Int = 0, ) { - init { check(currentPage >= 0) { "currentPage cannot be less than zero" } } + init { + check(currentPage >= 0) { "currentPage cannot be less than zero" } + } val lazyListState = LazyListState(firstVisibleItemIndex = currentPage) @@ -234,7 +236,7 @@ class PagerState( // https://android.googlesource.com/platform/frameworks/support/+/refs/changes/78/2160778/35/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/snapping/LazyListSnapLayoutInfoProvider.kt private fun lazyListSnapLayoutInfoProvider( lazyListState: LazyListState, - positionInLayout: SnapPositionInLayout = CenterToCenter + positionInLayout: SnapPositionInLayout = CenterToCenter, ) = object : SnapLayoutInfoProvider { private val layoutInfo: LazyListLayoutInfo get() = lazyListState.layoutInfo @@ -255,7 +257,7 @@ private fun lazyListSnapLayoutInfoProvider( itemSize = item.size, itemOffset = item.offset, itemIndex = item.index, - snapPositionInLayout = positionInLayout + snapPositionInLayout = positionInLayout, ) // Find item that is closest to the center @@ -272,7 +274,7 @@ private fun lazyListSnapLayoutInfoProvider( return calculateFinalOffset( currentVelocity, lowerBoundOffset, - upperBoundOffset + upperBoundOffset, ) } @@ -284,7 +286,7 @@ private fun lazyListSnapLayoutInfoProvider( itemSize: Int, itemOffset: Int, itemIndex: Int, - snapPositionInLayout: SnapPositionInLayout + snapPositionInLayout: SnapPositionInLayout, ): Float { val containerSize = mainAxisViewPortSize - beforeContentPadding - afterContentPadding @@ -295,9 +297,11 @@ private fun lazyListSnapLayoutInfoProvider( return itemOffset - desiredDistance } - - private fun calculateFinalOffset(velocity: Float, lowerBound: Float, upperBound: Float): Float { - + private fun calculateFinalOffset( + velocity: Float, + lowerBound: Float, + upperBound: Float, + ): Float { fun Float.isValidDistance(): Boolean { return this != Float.POSITIVE_INFINITY && this != Float.NEGATIVE_INFINITY } diff --git a/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/prefs/ColorPreference.kt b/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/prefs/ColorPreference.kt index 3c298830..94bf215f 100644 --- a/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/prefs/ColorPreference.kt +++ b/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/prefs/ColorPreference.kt @@ -19,17 +19,14 @@ import kotlinx.coroutines.flow.stateIn class ColorPreference( private val preference: Preference, ) : Preference { - override fun key(): String { - return preference.key() - } + override fun key(): String = preference.key() - override fun get(): Color { - return if (isSet()) { + override fun get(): Color = + if (isSet()) { Color(preference.get()) } else { Color.Unspecified } - } override fun set(value: Color) { if (value != Color.Unspecified) { @@ -39,28 +36,22 @@ class ColorPreference( } } - override fun isSet(): Boolean { - return preference.isSet() - } + override fun isSet(): Boolean = preference.isSet() override fun delete() { preference.delete() } - override fun defaultValue(): Color { - return Color.Unspecified - } + override fun defaultValue(): Color = Color.Unspecified - override fun changes(): Flow { - return preference.changes() + override fun changes(): Flow = + preference.changes() .map { get() } - } - override fun stateIn(scope: CoroutineScope): StateFlow { - return preference.changes().map { get() }.stateIn(scope, SharingStarted.Eagerly, get()) - } + override fun stateIn(scope: CoroutineScope): StateFlow = + preference.changes().map { + get() + }.stateIn(scope, SharingStarted.Eagerly, get()) } -fun Preference.asColor(): ColorPreference { - return ColorPreference(this) -} +fun Preference.asColor(): ColorPreference = ColorPreference(this) diff --git a/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/prefs/IntStringPreference.kt b/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/prefs/IntStringPreference.kt index 89b84a9b..70014646 100644 --- a/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/prefs/IntStringPreference.kt +++ b/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/prefs/IntStringPreference.kt @@ -14,40 +14,32 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn -fun Preference.asStringStateIn(scope: CoroutineScope): PreferenceMutableStateFlow { - return PreferenceMutableStateFlow(IntStringPreference(this), scope) -} +fun Preference.asStringStateIn(scope: CoroutineScope): PreferenceMutableStateFlow = + PreferenceMutableStateFlow( + IntStringPreference(this), + scope, + ) -class IntStringPreference(private val int: Preference) : Preference { - override fun key(): String { - return int.key() - } +class IntStringPreference( + private val int: Preference, +) : Preference { + override fun key(): String = int.key() - override fun get(): String { - return int.get().toString() - } + override fun get(): String = int.get().toString() override fun set(value: String) { value.toIntOrNull()?.let { int.set(it) } } - override fun isSet(): Boolean { - return int.isSet() - } + override fun isSet(): Boolean = int.isSet() override fun delete() { int.delete() } - override fun defaultValue(): String { - return int.defaultValue().toString() - } + override fun defaultValue(): String = int.defaultValue().toString() - override fun changes(): Flow { - return int.changes().map { it.toString() } - } + override fun changes(): Flow = int.changes().map { it.toString() } - override fun stateIn(scope: CoroutineScope): StateFlow { - return changes().stateIn(scope, SharingStarted.Eagerly, get()) - } + override fun stateIn(scope: CoroutineScope): StateFlow = changes().stateIn(scope, SharingStarted.Eagerly, get()) } diff --git a/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/prefs/PreferenceMutableState.kt b/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/prefs/PreferenceMutableState.kt index 90b1a79e..7170d281 100644 --- a/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/prefs/PreferenceMutableState.kt +++ b/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/prefs/PreferenceMutableState.kt @@ -30,6 +30,4 @@ class PreferenceMutableStateFlow( } } -fun Preference.asStateIn(scope: CoroutineScope): PreferenceMutableStateFlow { - return PreferenceMutableStateFlow(this, scope) -} +fun Preference.asStateIn(scope: CoroutineScope): PreferenceMutableStateFlow = PreferenceMutableStateFlow(this, scope) diff --git a/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/theme/ExtraColors.kt b/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/theme/ExtraColors.kt index 6701d0d1..555e1c4e 100644 --- a/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/theme/ExtraColors.kt +++ b/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/theme/ExtraColors.kt @@ -36,12 +36,11 @@ class ExtraColors( onTertiary, ) - override fun toString(): String { - return "ExtraColors(" + + override fun toString(): String = + "ExtraColors(" + "tertiary=$tertiary, " + "onTertiary=$onTertiary, " + ")" - } companion object { @Composable diff --git a/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/theme/RandomColors.kt b/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/theme/RandomColors.kt index 3dee8b9e..96d5ee5d 100644 --- a/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/theme/RandomColors.kt +++ b/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/theme/RandomColors.kt @@ -31,11 +31,7 @@ object RandomColors { Color(0xff90a4ae), ) - fun get(key: Any): Color { - return colors[abs(key.hashCode()) % colors.size] - } + fun get(key: Any): Color = colors[abs(key.hashCode()) % colors.size] - fun random(): Color { - return colors[Random.nextInt(colors.size)] - } + fun random(): Color = colors[Random.nextInt(colors.size)] } diff --git a/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/theme/Themes.kt b/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/theme/Themes.kt index 19012b6e..de321a05 100644 --- a/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/theme/Themes.kt +++ b/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/theme/Themes.kt @@ -153,10 +153,8 @@ val themes = listOf( ), extraColors(), ), - /** - * Green Apple theme - * Original color scheme by CarlosEsco, Jays2Kings and CrepeTF - */ + // Green Apple theme + // Original color scheme by CarlosEsco, Jays2Kings and CrepeTF Theme( 5, MR.strings.theme_green_apple, @@ -194,10 +192,8 @@ val themes = listOf( onTertiary = Color(0xFF680006), ), ), - /** - * Lavender theme - * Original color scheme by CrepeTF - */ + // Lavender theme + // Original color scheme by CrepeTF Theme( 7, MR.strings.theme_lavender, @@ -238,10 +234,8 @@ val themes = listOf( onTertiary = Color(0xFFE8E8E8), ), ), - /** - * Midnight Dusk theme - * Original color scheme by CrepeTF - */ + // Midnight Dusk theme + // Original color scheme by CrepeTF Theme( 9, MR.strings.theme_midnight_dusk, @@ -278,10 +272,8 @@ val themes = listOf( tertiary = Color(0xFF55971C), ), ), - /** - * Strawberry Daiquiri theme - * Original color scheme by Soitora - */ + // Strawberry Daiquiri theme + // Original color scheme by Soitora Theme( 11, MR.strings.theme_strawberry_daiquiri, @@ -319,10 +311,8 @@ val themes = listOf( onTertiary = Color(0xFF432C06), ), ), - /** - * Strawberry Tako theme - * Original color scheme by ghostbear - */ + // Strawberry Tako theme + // Original color scheme by ghostbear Theme( 13, MR.strings.theme_tako, @@ -363,9 +353,7 @@ val themes = listOf( onTertiary = Color(0xFFF3B375), ), ), - /** - * Teal & Turquoise theme - */ + // Teal & Turquoise theme Theme( 15, MR.strings.theme_tealturquoise, @@ -403,10 +391,8 @@ val themes = listOf( tertiary = Color(0xFFBF1F2F), ), ), - /** - * Tidal Wave theme - * Original color scheme by NahutabDevelop - */ + // Tidal Wave theme + // Original color scheme by NahutabDevelop Theme( 17, MR.strings.theme_tidal_wave, @@ -445,10 +431,8 @@ val themes = listOf( onTertiary = Color(0xFF001C3B), ), ), - /** - * Yin & Yang theme - * Original color scheme by Riztard - */ + // Yin & Yang theme + // Original color scheme by Riztard Theme( 19, MR.strings.theme_yinyang, @@ -489,10 +473,8 @@ val themes = listOf( onTertiary = Color.White, ), ), - /** - * Yotsuba theme - * Original color scheme by ztimms73 - */ + // Yotsuba theme + // Original color scheme by ztimms73 Theme( 21, MR.strings.theme_yotsuba, diff --git a/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/vm/ContextWrapper.kt b/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/vm/ContextWrapper.kt index 928aad77..600bb234 100644 --- a/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/vm/ContextWrapper.kt +++ b/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/vm/ContextWrapper.kt @@ -10,15 +10,18 @@ import dev.icerock.moko.resources.StringResource expect class ContextWrapper { fun toPlatformString(stringResource: StringResource): String + fun toPlatformString( stringResource: StringResource, vararg args: Any, ): String + fun toast( string: String, length: Length, ) } + enum class Length { SHORT, LONG, diff --git a/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/vm/ViewModel.kt b/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/vm/ViewModel.kt index f8e2c402..2403f742 100644 --- a/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/vm/ViewModel.kt +++ b/ui-core/src/commonMain/kotlin/ca/gosyer/jui/uicore/vm/ViewModel.kt @@ -18,7 +18,9 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch -abstract class ViewModel(private val contextWrapper: ContextWrapper) : ScreenModel { +abstract class ViewModel( + private val contextWrapper: ContextWrapper, +) : ScreenModel { protected open val scope: CoroutineScope get() = screenModelScope @@ -32,12 +34,10 @@ abstract class ViewModel(private val contextWrapper: ContextWrapper) : ScreenMod return state } - fun StringResource.toPlatformString(): String { - return contextWrapper.toPlatformString(this) - } - fun StringResource.toPlatformString(vararg args: Any): String { - return contextWrapper.toPlatformString(this, *args) - } + fun StringResource.toPlatformString(): String = contextWrapper.toPlatformString(this) + + fun StringResource.toPlatformString(vararg args: Any): String = contextWrapper.toPlatformString(this, *args) + fun toast( string: String, length: Length = Length.SHORT, diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/jui/uicore/components/DesktopScrollbar.kt b/ui-core/src/desktopMain/kotlin/ca/gosyer/jui/uicore/components/DesktopScrollbar.kt index cbc1fcac..a231ca16 100644 --- a/ui-core/src/desktopMain/kotlin/ca/gosyer/jui/uicore/components/DesktopScrollbar.kt +++ b/ui-core/src/desktopMain/kotlin/ca/gosyer/jui/uicore/components/DesktopScrollbar.kt @@ -56,31 +56,25 @@ internal actual fun RealHorizontalScrollbar( ) @Composable -actual fun rememberScrollbarAdapter(scrollState: ScrollState): ScrollbarAdapter { - return androidx.compose.foundation.rememberScrollbarAdapter(scrollState) -} +actual fun rememberScrollbarAdapter(scrollState: ScrollState): ScrollbarAdapter = + androidx.compose.foundation.rememberScrollbarAdapter(scrollState) @Composable -actual fun rememberScrollbarAdapter(scrollState: LazyListState): ScrollbarAdapter { - return androidx.compose.foundation.rememberScrollbarAdapter(scrollState) -} +actual fun rememberScrollbarAdapter(scrollState: LazyListState): ScrollbarAdapter = + androidx.compose.foundation.rememberScrollbarAdapter(scrollState) @Composable internal actual fun realRememberVerticalScrollbarAdapter( scrollState: LazyGridState, gridCells: GridCells, arrangement: Arrangement.Vertical?, -): ScrollbarAdapter { - return androidx.compose.foundation.rememberScrollbarAdapter(scrollState) -} +): ScrollbarAdapter = androidx.compose.foundation.rememberScrollbarAdapter(scrollState) @Composable internal actual fun realRememberHorizontalScrollbarAdapter( scrollState: LazyGridState, gridCells: GridCells, arrangement: Arrangement.Horizontal?, -): ScrollbarAdapter { - return androidx.compose.foundation.rememberScrollbarAdapter(scrollState) -} +): ScrollbarAdapter = androidx.compose.foundation.rememberScrollbarAdapter(scrollState) actual fun Modifier.scrollbarPadding() = padding(horizontal = 4.dp, vertical = 8.dp) diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/jui/uicore/resources/DesktopImageResource.kt b/ui-core/src/desktopMain/kotlin/ca/gosyer/jui/uicore/resources/DesktopImageResource.kt index e65a6292..58da8a93 100644 --- a/ui-core/src/desktopMain/kotlin/ca/gosyer/jui/uicore/resources/DesktopImageResource.kt +++ b/ui-core/src/desktopMain/kotlin/ca/gosyer/jui/uicore/resources/DesktopImageResource.kt @@ -13,6 +13,4 @@ import androidx.compose.ui.graphics.toPainter import dev.icerock.moko.resources.ImageResource @Composable -actual fun ImageResource.toPainter(): Painter { - return remember { image.toPainter() } -} +actual fun ImageResource.toPainter(): Painter = remember { image.toPainter() } diff --git a/ui-core/src/desktopMain/kotlin/ca/gosyer/jui/uicore/vm/ContextWrapper.kt b/ui-core/src/desktopMain/kotlin/ca/gosyer/jui/uicore/vm/ContextWrapper.kt index 88a66db6..3bf49d87 100644 --- a/ui-core/src/desktopMain/kotlin/ca/gosyer/jui/uicore/vm/ContextWrapper.kt +++ b/ui-core/src/desktopMain/kotlin/ca/gosyer/jui/uicore/vm/ContextWrapper.kt @@ -19,15 +19,13 @@ actual class ContextWrapper { private val _toasts = MutableSharedFlow>() val toasts = _toasts.asSharedFlow() - actual fun toPlatformString(stringResource: StringResource): String { - return stringResource.localized() - } + actual fun toPlatformString(stringResource: StringResource): String = stringResource.localized() + actual fun toPlatformString( stringResource: StringResource, vararg args: Any, - ): String { - return stringResource.format(*args).localized() - } + ): String = stringResource.format(*args).localized() + actual fun toast( string: String, length: Length, diff --git a/ui-core/src/iosArm64Main/kotlin/ca/gosyer/jui/uicore/resources/IosStringResource.kt b/ui-core/src/iosArm64Main/kotlin/ca/gosyer/jui/uicore/resources/IosStringResource.kt index 4f8b3316..d125ec30 100644 --- a/ui-core/src/iosArm64Main/kotlin/ca/gosyer/jui/uicore/resources/IosStringResource.kt +++ b/ui-core/src/iosArm64Main/kotlin/ca/gosyer/jui/uicore/resources/IosStringResource.kt @@ -10,4 +10,5 @@ import dev.icerock.moko.resources.desc.PluralFormattedStringDesc import dev.icerock.moko.resources.desc.PluralStringDesc actual fun PluralStringDesc.localized(): String = localized() + actual fun PluralFormattedStringDesc.localized() = localized() diff --git a/ui-core/src/iosMain/kotlin/ca/gosyer/jui/uicore/components/IosScrollbar.kt b/ui-core/src/iosMain/kotlin/ca/gosyer/jui/uicore/components/IosScrollbar.kt index 0f33bba7..9192ba4d 100644 --- a/ui-core/src/iosMain/kotlin/ca/gosyer/jui/uicore/components/IosScrollbar.kt +++ b/ui-core/src/iosMain/kotlin/ca/gosyer/jui/uicore/components/IosScrollbar.kt @@ -48,11 +48,19 @@ import kotlinx.coroutines.flow.Flow actual interface ScrollbarAdapter -class ScrollStateScrollbarAdapter(val scrollState: ScrollState) : ScrollbarAdapter +class ScrollStateScrollbarAdapter( + val scrollState: ScrollState, +) : ScrollbarAdapter -class LazyListStateScrollbarAdapter(val lazyListState: LazyListState) : ScrollbarAdapter +class LazyListStateScrollbarAdapter( + val lazyListState: LazyListState, +) : ScrollbarAdapter -class LazyGridStateScrollbarAdapter(val lazyGridState: LazyGridState, val gridCells: GridCells, val spacing: Dp) : ScrollbarAdapter +class LazyGridStateScrollbarAdapter( + val lazyGridState: LazyGridState, + val gridCells: GridCells, + val spacing: Dp, +) : ScrollbarAdapter @Immutable actual class ScrollbarStyle diff --git a/ui-core/src/iosMain/kotlin/ca/gosyer/jui/uicore/resources/IosImageResource.kt b/ui-core/src/iosMain/kotlin/ca/gosyer/jui/uicore/resources/IosImageResource.kt index b8e16fbf..87e3dc5a 100644 --- a/ui-core/src/iosMain/kotlin/ca/gosyer/jui/uicore/resources/IosImageResource.kt +++ b/ui-core/src/iosMain/kotlin/ca/gosyer/jui/uicore/resources/IosImageResource.kt @@ -57,9 +57,16 @@ private fun UIImage.toSkiaImage(): Image? { val alphaInfo = CGImageGetAlphaInfo(imageRef) val alphaType = when (alphaInfo) { - CGImageAlphaInfo.kCGImageAlphaPremultipliedFirst, CGImageAlphaInfo.kCGImageAlphaPremultipliedLast -> ColorAlphaType.PREMUL - CGImageAlphaInfo.kCGImageAlphaFirst, CGImageAlphaInfo.kCGImageAlphaLast -> ColorAlphaType.UNPREMUL - CGImageAlphaInfo.kCGImageAlphaNone, CGImageAlphaInfo.kCGImageAlphaNoneSkipFirst, CGImageAlphaInfo.kCGImageAlphaNoneSkipLast -> ColorAlphaType.OPAQUE + CGImageAlphaInfo.kCGImageAlphaPremultipliedFirst, + CGImageAlphaInfo.kCGImageAlphaPremultipliedLast, + -> ColorAlphaType.PREMUL + CGImageAlphaInfo.kCGImageAlphaFirst, + CGImageAlphaInfo.kCGImageAlphaLast, + -> ColorAlphaType.UNPREMUL + CGImageAlphaInfo.kCGImageAlphaNone, + CGImageAlphaInfo.kCGImageAlphaNoneSkipFirst, + CGImageAlphaInfo.kCGImageAlphaNoneSkipLast, + -> ColorAlphaType.OPAQUE else -> ColorAlphaType.UNKNOWN } @@ -70,7 +77,12 @@ private fun UIImage.toSkiaImage(): Image? { CFRelease(imageRef) return Image.makeRaster( - imageInfo = ImageInfo(width = width, height = height, colorType = ColorType.RGBA_8888, alphaType = alphaType), + imageInfo = ImageInfo( + width = width, + height = height, + colorType = ColorType.RGBA_8888, + alphaType = alphaType, + ), bytes = byteArray, rowBytes = bytesPerRow.toInt(), ) diff --git a/ui-core/src/iosMain/kotlin/ca/gosyer/jui/uicore/resources/IosStringResource.kt b/ui-core/src/iosMain/kotlin/ca/gosyer/jui/uicore/resources/IosStringResource.kt index 2fc7faa0..7b4293ce 100644 --- a/ui-core/src/iosMain/kotlin/ca/gosyer/jui/uicore/resources/IosStringResource.kt +++ b/ui-core/src/iosMain/kotlin/ca/gosyer/jui/uicore/resources/IosStringResource.kt @@ -18,6 +18,7 @@ import dev.icerock.moko.resources.desc.ResourceFormatted import dev.icerock.moko.resources.desc.StringDesc expect fun PluralStringDesc.localized(): String + expect fun PluralFormattedStringDesc.localized(): String @Composable diff --git a/ui-core/src/iosMain/kotlin/ca/gosyer/jui/uicore/vm/ContextWrapper.kt b/ui-core/src/iosMain/kotlin/ca/gosyer/jui/uicore/vm/ContextWrapper.kt index 7b9121a2..f8e63112 100644 --- a/ui-core/src/iosMain/kotlin/ca/gosyer/jui/uicore/vm/ContextWrapper.kt +++ b/ui-core/src/iosMain/kotlin/ca/gosyer/jui/uicore/vm/ContextWrapper.kt @@ -21,15 +21,13 @@ actual class ContextWrapper private val _toasts = MutableSharedFlow>() val toasts = _toasts.asSharedFlow() - actual fun toPlatformString(stringResource: StringResource): String { - return stringResource.desc().localized() - } + actual fun toPlatformString(stringResource: StringResource): String = stringResource.desc().localized() + actual fun toPlatformString( stringResource: StringResource, vararg args: Any, - ): String { - return stringResource.format(*args).localized() - } + ): String = stringResource.format(*args).localized() + actual fun toast( string: String, length: Length, diff --git a/ui-core/src/iosSimulatorArm64Main/kotlin/ca/gosyer/jui/uicore/resources/IosStringResource.kt b/ui-core/src/iosSimulatorArm64Main/kotlin/ca/gosyer/jui/uicore/resources/IosStringResource.kt index 4f8b3316..d125ec30 100644 --- a/ui-core/src/iosSimulatorArm64Main/kotlin/ca/gosyer/jui/uicore/resources/IosStringResource.kt +++ b/ui-core/src/iosSimulatorArm64Main/kotlin/ca/gosyer/jui/uicore/resources/IosStringResource.kt @@ -10,4 +10,5 @@ import dev.icerock.moko.resources.desc.PluralFormattedStringDesc import dev.icerock.moko.resources.desc.PluralStringDesc actual fun PluralStringDesc.localized(): String = localized() + actual fun PluralFormattedStringDesc.localized() = localized() diff --git a/ui-core/src/iosX64Main/kotlin/ca/gosyer/jui/uicore/resources/IosStringResource.kt b/ui-core/src/iosX64Main/kotlin/ca/gosyer/jui/uicore/resources/IosStringResource.kt index 4f8b3316..d125ec30 100644 --- a/ui-core/src/iosX64Main/kotlin/ca/gosyer/jui/uicore/resources/IosStringResource.kt +++ b/ui-core/src/iosX64Main/kotlin/ca/gosyer/jui/uicore/resources/IosStringResource.kt @@ -10,4 +10,5 @@ import dev.icerock.moko.resources.desc.PluralFormattedStringDesc import dev.icerock.moko.resources.desc.PluralStringDesc actual fun PluralStringDesc.localized(): String = localized() + actual fun PluralFormattedStringDesc.localized() = localized()