From cf1e9f510ab33bc7de6ca8332f800da978f6192d Mon Sep 17 00:00:00 2001 From: Syer10 Date: Sat, 4 Oct 2025 00:08:40 -0400 Subject: [PATCH] Fix formatting in a few more files --- .../ca/gosyer/jui/android/AppMigrations.kt | 33 ++++---- .../jui/core/prefs/PreferenceStoreFactory.kt | 27 ++++--- .../jui/core/prefs/PreferenceStoreFactory.kt | 23 +++--- .../jui/core/prefs/PreferenceStoreFactory.kt | 19 +++-- .../ca/gosyer/jui/core/util/DateHandler.kt | 75 +++++++++--------- .../ca/gosyer/jui/core/util/DateHandler.kt | 59 +++++++------- .../ca/gosyer/jui/desktop/AppMigrations.kt | 77 +++++++++---------- .../kotlin/ca/gosyer/jui/ios/AppMigrations.kt | 31 ++++---- .../ca/gosyer/jui/uicore/vm/ContextWrapper.kt | 45 ++++++----- .../ca/gosyer/jui/uicore/vm/ContextWrapper.kt | 33 ++++---- 10 files changed, 206 insertions(+), 216 deletions(-) diff --git a/android/src/main/kotlin/ca/gosyer/jui/android/AppMigrations.kt b/android/src/main/kotlin/ca/gosyer/jui/android/AppMigrations.kt index 81dee2aa..ba491820 100644 --- a/android/src/main/kotlin/ca/gosyer/jui/android/AppMigrations.kt +++ b/android/src/main/kotlin/ca/gosyer/jui/android/AppMigrations.kt @@ -11,25 +11,24 @@ import ca.gosyer.jui.domain.migration.service.MigrationPreferences import ca.gosyer.jui.uicore.vm.ContextWrapper import me.tatarka.inject.annotations.Inject -class AppMigrations - @Inject - constructor( - private val migrationPreferences: MigrationPreferences, - private val contextWrapper: ContextWrapper, - ) { - fun runMigrations(): Boolean { - val oldVersion = migrationPreferences.appVersion().get() - if (oldVersion < BuildConfig.VERSION_CODE) { - migrationPreferences.appVersion().set(BuildConfig.VERSION_CODE) +@Inject +class AppMigrations( + private val migrationPreferences: MigrationPreferences, + private val contextWrapper: ContextWrapper, +) { + fun runMigrations(): Boolean { + val oldVersion = migrationPreferences.appVersion().get() + if (oldVersion < BuildConfig.VERSION_CODE) { + migrationPreferences.appVersion().set(BuildConfig.VERSION_CODE) - UpdateCheckWorker.setupTask(contextWrapper) + UpdateCheckWorker.setupTask(contextWrapper) - // Fresh install - if (oldVersion == 0) { - return false - } - return true + // Fresh install + if (oldVersion == 0) { + return false } - return false + return true } + return false } +} 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 0dab11ab..5afb19fa 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 @@ -10,18 +10,17 @@ import android.content.Context import com.russhwolf.settings.SharedPreferencesSettings import me.tatarka.inject.annotations.Inject -actual class PreferenceStoreFactory - @Inject - constructor( - private val context: Context, - ) { - actual fun create(vararg names: String): PreferenceStore = - StandardPreferenceStore( - SharedPreferencesSettings( - context.getSharedPreferences( - names.joinToString(separator = "_"), - Context.MODE_PRIVATE, - ), +@Inject +actual class PreferenceStoreFactory( + private val context: Context, +) { + actual fun create(vararg names: String): PreferenceStore = + StandardPreferenceStore( + SharedPreferencesSettings( + context.getSharedPreferences( + names.joinToString(separator = "_"), + Context.MODE_PRIVATE, ), - ) - } + ), + ) +} 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 e19094f8..0eccc50a 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 @@ -10,16 +10,15 @@ import com.russhwolf.settings.PreferencesSettings import me.tatarka.inject.annotations.Inject import java.util.prefs.Preferences -actual class PreferenceStoreFactory - @Inject - constructor() { - private val rootNode: Preferences = Preferences.userRoot() - .node("ca/gosyer/tachideskjui") +@Inject +actual class PreferenceStoreFactory() { + private val rootNode: Preferences = Preferences.userRoot() + .node("ca/gosyer/tachideskjui") - actual fun create(vararg names: String): PreferenceStore = - StandardPreferenceStore( - PreferencesSettings( - rootNode.node(names.joinToString(separator = "/")), - ), - ) - } + 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 50f14c0c..6b241ea2 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 @@ -10,13 +10,12 @@ import com.russhwolf.settings.NSUserDefaultsSettings import me.tatarka.inject.annotations.Inject import platform.Foundation.NSUserDefaults -actual class PreferenceStoreFactory - @Inject - constructor() { - actual fun create(vararg names: String): PreferenceStore = - StandardPreferenceStore( - NSUserDefaultsSettings( - NSUserDefaults.standardUserDefaults, - ), - ) - } +@Inject +actual class PreferenceStoreFactory() { + actual fun create(vararg names: String): PreferenceStore = + StandardPreferenceStore( + NSUserDefaultsSettings( + NSUserDefaults.standardUserDefaults, + ), + ) +} diff --git a/core/src/iosMain/kotlin/ca/gosyer/jui/core/util/DateHandler.kt b/core/src/iosMain/kotlin/ca/gosyer/jui/core/util/DateHandler.kt index 3a213257..2de2f507 100644 --- a/core/src/iosMain/kotlin/ca/gosyer/jui/core/util/DateHandler.kt +++ b/core/src/iosMain/kotlin/ca/gosyer/jui/core/util/DateHandler.kt @@ -5,48 +5,47 @@ import ca.gosyer.jui.core.lang.toPlatform import kotlinx.datetime.Instant import me.tatarka.inject.annotations.Inject -actual class DateHandler - @Inject - constructor() { - actual val formatOptions by lazy { - listOf( - "", - "MM/dd/yy", - "dd/MM/yy", - "yyyy-MM-dd", - ) +@Inject +actual class DateHandler() { + actual val formatOptions by lazy { + listOf( + "", + "MM/dd/yy", + "dd/MM/yy", + "yyyy-MM-dd", + ) + } + + actual fun getDateFormat(format: String): (Instant) -> String = + when (format) { + "" -> NSDateFormatter() + .apply { + setDateStyle(NSDateFormatterShortStyle) + setTimeStyle(NSDateFormatterNoStyle) + setLocale(Locale.current.toPlatform()) + } + + else -> NSDateFormatter() + .apply { + setDateFormat(format) + } + }.let { formatter -> + { + formatter.stringFromDate(it.toNSDate()) + } } - actual fun getDateFormat(format: String): (Instant) -> String = - when (format) { - "" -> NSDateFormatter() - .apply { - setDateStyle(NSDateFormatterShortStyle) - setTimeStyle(NSDateFormatterNoStyle) - setLocale(Locale.current.toPlatform()) - } - - else -> NSDateFormatter() - .apply { - setDateFormat(format) - } - }.let { formatter -> + actual val dateTimeFormat: (Instant) -> String by lazy { + NSDateFormatter() + .apply { + setDateStyle(NSDateFormatterShortStyle) + setTimeStyle(NSDateFormatterShortStyle) + setLocale(Locale.current.toPlatform()) + } + .let { formatter -> { formatter.stringFromDate(it.toNSDate()) } } - - actual val dateTimeFormat: (Instant) -> String by lazy { - NSDateFormatter() - .apply { - setDateStyle(NSDateFormatterShortStyle) - setTimeStyle(NSDateFormatterShortStyle) - setLocale(Locale.current.toPlatform()) - } - .let { formatter -> - { - formatter.stringFromDate(it.toNSDate()) - } - } - } } +} diff --git a/core/src/jvmMain/kotlin/ca/gosyer/jui/core/util/DateHandler.kt b/core/src/jvmMain/kotlin/ca/gosyer/jui/core/util/DateHandler.kt index a99de235..17ac7930 100644 --- a/core/src/jvmMain/kotlin/ca/gosyer/jui/core/util/DateHandler.kt +++ b/core/src/jvmMain/kotlin/ca/gosyer/jui/core/util/DateHandler.kt @@ -9,40 +9,39 @@ import java.time.ZoneId import java.time.format.DateTimeFormatter import java.time.format.FormatStyle -actual class DateHandler - @Inject - constructor() { - actual val formatOptions by lazy { - listOf( - "", - "MM/dd/yy", - "dd/MM/yy", - "yyyy-MM-dd", - ) +@Inject +actual class DateHandler() { + actual val formatOptions by lazy { + listOf( + "", + "MM/dd/yy", + "dd/MM/yy", + "yyyy-MM-dd", + ) + } + + actual fun getDateFormat(format: String): (Instant) -> String = + when (format) { + "" -> DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT) + .withLocale(Locale.current.toPlatform()) + .withZone(ZoneId.systemDefault()) + + else -> DateTimeFormatter.ofPattern(format) + .withZone(ZoneId.systemDefault()) + }.let { formatter -> + { + formatter.format(it.toJavaInstant()) + } } - actual fun getDateFormat(format: String): (Instant) -> String = - when (format) { - "" -> DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT) - .withLocale(Locale.current.toPlatform()) - .withZone(ZoneId.systemDefault()) - - else -> DateTimeFormatter.ofPattern(format) - .withZone(ZoneId.systemDefault()) - }.let { formatter -> + actual val dateTimeFormat: (Instant) -> String by lazy { + DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT) + .withLocale(Locale.current.toPlatform()) + .withZone(ZoneId.systemDefault()) + .let { formatter -> { formatter.format(it.toJavaInstant()) } } - - actual val dateTimeFormat: (Instant) -> String by lazy { - DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT) - .withLocale(Locale.current.toPlatform()) - .withZone(ZoneId.systemDefault()) - .let { formatter -> - { - formatter.format(it.toJavaInstant()) - } - } - } } +} diff --git a/desktop/src/main/kotlin/ca/gosyer/jui/desktop/AppMigrations.kt b/desktop/src/main/kotlin/ca/gosyer/jui/desktop/AppMigrations.kt index b71cd184..4512c7b9 100644 --- a/desktop/src/main/kotlin/ca/gosyer/jui/desktop/AppMigrations.kt +++ b/desktop/src/main/kotlin/ca/gosyer/jui/desktop/AppMigrations.kt @@ -15,47 +15,46 @@ import okio.FileSystem import okio.Path.Companion.toPath import org.lighthousegames.logging.logging -class AppMigrations - @Inject - constructor( - private val migrationPreferences: MigrationPreferences, - private val contextWrapper: ContextWrapper, - ) { - @Suppress("KotlinConstantConditions") - fun runMigrations(): Boolean { - val oldVersion = migrationPreferences.appVersion().get() - if (oldVersion < BuildConfig.MIGRATION_CODE) { - migrationPreferences.appVersion().set(BuildConfig.MIGRATION_CODE) +@Inject +class AppMigrations( + private val migrationPreferences: MigrationPreferences, + private val contextWrapper: ContextWrapper, +) { + @Suppress("KotlinConstantConditions") + fun runMigrations(): Boolean { + val oldVersion = migrationPreferences.appVersion().get() + if (oldVersion < BuildConfig.MIGRATION_CODE) { + migrationPreferences.appVersion().set(BuildConfig.MIGRATION_CODE) - // Fresh install - if (oldVersion == 0) { - return false - } - - if (oldVersion < 5) { - val oldDir = AppDirs("Tachidesk-JUI").getUserDataDir().toPath() - val newDir = AppDirs("Suwayomi-JUI").getUserDataDir().toPath() - try { - FileSystem.SYSTEM.list(oldDir) - .filter { FileSystem.SYSTEM.metadata(it).isDirectory } - .forEach { path -> - runCatching { - FileSystem.SYSTEM.atomicMove(path, newDir / path.name) - }.onFailure { - log.e(it) { "Failed to move directory ${path.name}" } - } - } - } catch (e: Exception) { - log.e(e) { "Failed to run directory migration" } - } - } - - return true + // Fresh install + if (oldVersion == 0) { + return false } - return false - } - companion object { - private val log = logging() + if (oldVersion < 5) { + val oldDir = AppDirs("Tachidesk-JUI").getUserDataDir().toPath() + val newDir = AppDirs("Suwayomi-JUI").getUserDataDir().toPath() + try { + FileSystem.SYSTEM.list(oldDir) + .filter { FileSystem.SYSTEM.metadata(it).isDirectory } + .forEach { path -> + runCatching { + FileSystem.SYSTEM.atomicMove(path, newDir / path.name) + }.onFailure { + log.e(it) { "Failed to move directory ${path.name}" } + } + } + } catch (e: Exception) { + log.e(e) { "Failed to run directory migration" } + } + } + + return true } + return false } + + companion object { + private val log = logging() + } +} diff --git a/ios/src/uikitMain/kotlin/ca/gosyer/jui/ios/AppMigrations.kt b/ios/src/uikitMain/kotlin/ca/gosyer/jui/ios/AppMigrations.kt index bfa66f83..e6bbf053 100644 --- a/ios/src/uikitMain/kotlin/ca/gosyer/jui/ios/AppMigrations.kt +++ b/ios/src/uikitMain/kotlin/ca/gosyer/jui/ios/AppMigrations.kt @@ -11,23 +11,22 @@ import ca.gosyer.jui.ios.build.BuildKonfig import ca.gosyer.jui.uicore.vm.ContextWrapper import me.tatarka.inject.annotations.Inject -class AppMigrations - @Inject - constructor( - private val migrationPreferences: MigrationPreferences, - private val contextWrapper: ContextWrapper, - ) { - fun runMigrations(): Boolean { - val oldVersion = migrationPreferences.appVersion().get() - if (oldVersion < BuildKonfig.MIGRATION_CODE) { - migrationPreferences.appVersion().set(BuildKonfig.MIGRATION_CODE) +@Inject +class AppMigrations( + private val migrationPreferences: MigrationPreferences, + private val contextWrapper: ContextWrapper, +) { + fun runMigrations(): Boolean { + val oldVersion = migrationPreferences.appVersion().get() + if (oldVersion < BuildKonfig.MIGRATION_CODE) { + migrationPreferences.appVersion().set(BuildKonfig.MIGRATION_CODE) - // Fresh install - if (oldVersion == 0) { - return false - } - return true + // Fresh install + if (oldVersion == 0) { + return false } - return false + return true } + return false } +} diff --git a/ui-core/src/androidMain/kotlin/ca/gosyer/jui/uicore/vm/ContextWrapper.kt b/ui-core/src/androidMain/kotlin/ca/gosyer/jui/uicore/vm/ContextWrapper.kt index 5530ea8b..fdbba8cd 100644 --- a/ui-core/src/androidMain/kotlin/ca/gosyer/jui/uicore/vm/ContextWrapper.kt +++ b/ui-core/src/androidMain/kotlin/ca/gosyer/jui/uicore/vm/ContextWrapper.kt @@ -14,29 +14,28 @@ import dev.icerock.moko.resources.desc.desc import dev.icerock.moko.resources.format import me.tatarka.inject.annotations.Inject -actual class ContextWrapper - @Inject - constructor( - context: Context, - ) : ContextWrapper(context) { - actual fun toPlatformString(stringResource: StringResource): String = stringResource.desc().toString(this) +@Inject +actual class ContextWrapper( + context: Context, +) : ContextWrapper(context) { + actual fun toPlatformString(stringResource: StringResource): String = stringResource.desc().toString(this) - actual fun toPlatformString( - stringResource: StringResource, - vararg args: Any, - ): String = stringResource.format(*args).toString(this) + actual fun toPlatformString( + stringResource: StringResource, + vararg args: Any, + ): String = stringResource.format(*args).toString(this) - actual fun toast( - string: String, - length: Length, - ) { - Toast.makeText( - this, - string, - when (length) { - Length.SHORT -> Toast.LENGTH_SHORT - Length.LONG -> Toast.LENGTH_LONG - }, - ).show() - } + actual fun toast( + string: String, + length: Length, + ) { + Toast.makeText( + this, + string, + when (length) { + Length.SHORT -> Toast.LENGTH_SHORT + Length.LONG -> Toast.LENGTH_LONG + }, + ).show() } +} 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 f8e63112..3cb32b97 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 @@ -15,25 +15,24 @@ import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow import me.tatarka.inject.annotations.Inject -actual class ContextWrapper - @Inject - constructor() { - private val _toasts = MutableSharedFlow>() - val toasts = _toasts.asSharedFlow() +@Inject +actual class ContextWrapper() { + private val _toasts = MutableSharedFlow>() + val toasts = _toasts.asSharedFlow() - actual fun toPlatformString(stringResource: StringResource): String = stringResource.desc().localized() + actual fun toPlatformString(stringResource: StringResource): String = stringResource.desc().localized() - actual fun toPlatformString( - stringResource: StringResource, - vararg args: Any, - ): String = stringResource.format(*args).localized() + actual fun toPlatformString( + stringResource: StringResource, + vararg args: Any, + ): String = stringResource.format(*args).localized() - actual fun toast( - string: String, - length: Length, - ) { - GlobalScope.launchDefault { - _toasts.emit(string to length) - } + actual fun toast( + string: String, + length: Length, + ) { + GlobalScope.launchDefault { + _toasts.emit(string to length) } } +}