Fix formatting in a few more files

This commit is contained in:
Syer10
2025-10-04 00:08:40 -04:00
parent 9c8fd0257d
commit cf1e9f510a
10 changed files with 206 additions and 216 deletions

View File

@@ -11,25 +11,24 @@ import ca.gosyer.jui.domain.migration.service.MigrationPreferences
import ca.gosyer.jui.uicore.vm.ContextWrapper import ca.gosyer.jui.uicore.vm.ContextWrapper
import me.tatarka.inject.annotations.Inject import me.tatarka.inject.annotations.Inject
class AppMigrations @Inject
@Inject class AppMigrations(
constructor( private val migrationPreferences: MigrationPreferences,
private val migrationPreferences: MigrationPreferences, private val contextWrapper: ContextWrapper,
private val contextWrapper: ContextWrapper, ) {
) { fun runMigrations(): Boolean {
fun runMigrations(): Boolean { val oldVersion = migrationPreferences.appVersion().get()
val oldVersion = migrationPreferences.appVersion().get() if (oldVersion < BuildConfig.VERSION_CODE) {
if (oldVersion < BuildConfig.VERSION_CODE) { migrationPreferences.appVersion().set(BuildConfig.VERSION_CODE)
migrationPreferences.appVersion().set(BuildConfig.VERSION_CODE)
UpdateCheckWorker.setupTask(contextWrapper) UpdateCheckWorker.setupTask(contextWrapper)
// Fresh install // Fresh install
if (oldVersion == 0) { if (oldVersion == 0) {
return false return false
}
return true
} }
return false return true
} }
return false
} }
}

View File

@@ -10,18 +10,17 @@ import android.content.Context
import com.russhwolf.settings.SharedPreferencesSettings import com.russhwolf.settings.SharedPreferencesSettings
import me.tatarka.inject.annotations.Inject import me.tatarka.inject.annotations.Inject
actual class PreferenceStoreFactory @Inject
@Inject actual class PreferenceStoreFactory(
constructor( private val context: Context,
private val context: Context, ) {
) { actual fun create(vararg names: String): PreferenceStore =
actual fun create(vararg names: String): PreferenceStore = StandardPreferenceStore(
StandardPreferenceStore( SharedPreferencesSettings(
SharedPreferencesSettings( context.getSharedPreferences(
context.getSharedPreferences( names.joinToString(separator = "_"),
names.joinToString(separator = "_"), Context.MODE_PRIVATE,
Context.MODE_PRIVATE,
),
), ),
) ),
} )
}

View File

@@ -10,16 +10,15 @@ import com.russhwolf.settings.PreferencesSettings
import me.tatarka.inject.annotations.Inject import me.tatarka.inject.annotations.Inject
import java.util.prefs.Preferences import java.util.prefs.Preferences
actual class PreferenceStoreFactory @Inject
@Inject actual class PreferenceStoreFactory() {
constructor() { private val rootNode: Preferences = Preferences.userRoot()
private val rootNode: Preferences = Preferences.userRoot() .node("ca/gosyer/tachideskjui")
.node("ca/gosyer/tachideskjui")
actual fun create(vararg names: String): PreferenceStore = actual fun create(vararg names: String): PreferenceStore =
StandardPreferenceStore( StandardPreferenceStore(
PreferencesSettings( PreferencesSettings(
rootNode.node(names.joinToString(separator = "/")), rootNode.node(names.joinToString(separator = "/")),
), ),
) )
} }

View File

@@ -10,13 +10,12 @@ import com.russhwolf.settings.NSUserDefaultsSettings
import me.tatarka.inject.annotations.Inject import me.tatarka.inject.annotations.Inject
import platform.Foundation.NSUserDefaults import platform.Foundation.NSUserDefaults
actual class PreferenceStoreFactory @Inject
@Inject actual class PreferenceStoreFactory() {
constructor() { actual fun create(vararg names: String): PreferenceStore =
actual fun create(vararg names: String): PreferenceStore = StandardPreferenceStore(
StandardPreferenceStore( NSUserDefaultsSettings(
NSUserDefaultsSettings( NSUserDefaults.standardUserDefaults,
NSUserDefaults.standardUserDefaults, ),
), )
) }
}

View File

@@ -5,48 +5,47 @@ import ca.gosyer.jui.core.lang.toPlatform
import kotlinx.datetime.Instant import kotlinx.datetime.Instant
import me.tatarka.inject.annotations.Inject import me.tatarka.inject.annotations.Inject
actual class DateHandler @Inject
@Inject actual class DateHandler() {
constructor() { actual val formatOptions by lazy {
actual val formatOptions by lazy { listOf(
listOf( "",
"", "MM/dd/yy",
"MM/dd/yy", "dd/MM/yy",
"dd/MM/yy", "yyyy-MM-dd",
"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 = actual val dateTimeFormat: (Instant) -> String by lazy {
when (format) { NSDateFormatter()
"" -> NSDateFormatter() .apply {
.apply { setDateStyle(NSDateFormatterShortStyle)
setDateStyle(NSDateFormatterShortStyle) setTimeStyle(NSDateFormatterShortStyle)
setTimeStyle(NSDateFormatterNoStyle) setLocale(Locale.current.toPlatform())
setLocale(Locale.current.toPlatform()) }
} .let { formatter ->
else -> NSDateFormatter()
.apply {
setDateFormat(format)
}
}.let { formatter ->
{ {
formatter.stringFromDate(it.toNSDate()) 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())
}
}
}
} }
}

View File

@@ -9,40 +9,39 @@ import java.time.ZoneId
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle import java.time.format.FormatStyle
actual class DateHandler @Inject
@Inject actual class DateHandler() {
constructor() { actual val formatOptions by lazy {
actual val formatOptions by lazy { listOf(
listOf( "",
"", "MM/dd/yy",
"MM/dd/yy", "dd/MM/yy",
"dd/MM/yy", "yyyy-MM-dd",
"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 = actual val dateTimeFormat: (Instant) -> String by lazy {
when (format) { DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
"" -> DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT) .withLocale(Locale.current.toPlatform())
.withLocale(Locale.current.toPlatform()) .withZone(ZoneId.systemDefault())
.withZone(ZoneId.systemDefault()) .let { formatter ->
else -> DateTimeFormatter.ofPattern(format)
.withZone(ZoneId.systemDefault())
}.let { formatter ->
{ {
formatter.format(it.toJavaInstant()) 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())
}
}
}
} }
}

View File

@@ -15,47 +15,46 @@ import okio.FileSystem
import okio.Path.Companion.toPath import okio.Path.Companion.toPath
import org.lighthousegames.logging.logging import org.lighthousegames.logging.logging
class AppMigrations @Inject
@Inject class AppMigrations(
constructor( private val migrationPreferences: MigrationPreferences,
private val migrationPreferences: MigrationPreferences, private val contextWrapper: ContextWrapper,
private val contextWrapper: ContextWrapper, ) {
) { @Suppress("KotlinConstantConditions")
@Suppress("KotlinConstantConditions") fun runMigrations(): Boolean {
fun runMigrations(): Boolean { val oldVersion = migrationPreferences.appVersion().get()
val oldVersion = migrationPreferences.appVersion().get() if (oldVersion < BuildConfig.MIGRATION_CODE) {
if (oldVersion < BuildConfig.MIGRATION_CODE) { migrationPreferences.appVersion().set(BuildConfig.MIGRATION_CODE)
migrationPreferences.appVersion().set(BuildConfig.MIGRATION_CODE)
// Fresh install // Fresh install
if (oldVersion == 0) { if (oldVersion == 0) {
return false 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
} }
return false
}
companion object { if (oldVersion < 5) {
private val log = logging() 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()
}
}

View File

@@ -11,23 +11,22 @@ import ca.gosyer.jui.ios.build.BuildKonfig
import ca.gosyer.jui.uicore.vm.ContextWrapper import ca.gosyer.jui.uicore.vm.ContextWrapper
import me.tatarka.inject.annotations.Inject import me.tatarka.inject.annotations.Inject
class AppMigrations @Inject
@Inject class AppMigrations(
constructor( private val migrationPreferences: MigrationPreferences,
private val migrationPreferences: MigrationPreferences, private val contextWrapper: ContextWrapper,
private val contextWrapper: ContextWrapper, ) {
) { fun runMigrations(): Boolean {
fun runMigrations(): Boolean { val oldVersion = migrationPreferences.appVersion().get()
val oldVersion = migrationPreferences.appVersion().get() if (oldVersion < BuildKonfig.MIGRATION_CODE) {
if (oldVersion < BuildKonfig.MIGRATION_CODE) { migrationPreferences.appVersion().set(BuildKonfig.MIGRATION_CODE)
migrationPreferences.appVersion().set(BuildKonfig.MIGRATION_CODE)
// Fresh install // Fresh install
if (oldVersion == 0) { if (oldVersion == 0) {
return false return false
}
return true
} }
return false return true
} }
return false
} }
}

View File

@@ -14,29 +14,28 @@ import dev.icerock.moko.resources.desc.desc
import dev.icerock.moko.resources.format import dev.icerock.moko.resources.format
import me.tatarka.inject.annotations.Inject import me.tatarka.inject.annotations.Inject
actual class ContextWrapper @Inject
@Inject actual class ContextWrapper(
constructor( context: Context,
context: Context, ) : ContextWrapper(context) {
) : ContextWrapper(context) { actual fun toPlatformString(stringResource: StringResource): String = stringResource.desc().toString(this)
actual fun toPlatformString(stringResource: StringResource): String = stringResource.desc().toString(this)
actual fun toPlatformString( actual fun toPlatformString(
stringResource: StringResource, stringResource: StringResource,
vararg args: Any, vararg args: Any,
): String = stringResource.format(*args).toString(this) ): String = stringResource.format(*args).toString(this)
actual fun toast( actual fun toast(
string: String, string: String,
length: Length, length: Length,
) { ) {
Toast.makeText( Toast.makeText(
this, this,
string, string,
when (length) { when (length) {
Length.SHORT -> Toast.LENGTH_SHORT Length.SHORT -> Toast.LENGTH_SHORT
Length.LONG -> Toast.LENGTH_LONG Length.LONG -> Toast.LENGTH_LONG
}, },
).show() ).show()
}
} }
}

View File

@@ -15,25 +15,24 @@ import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asSharedFlow
import me.tatarka.inject.annotations.Inject import me.tatarka.inject.annotations.Inject
actual class ContextWrapper @Inject
@Inject actual class ContextWrapper() {
constructor() { private val _toasts = MutableSharedFlow<Pair<String, Length>>()
private val _toasts = MutableSharedFlow<Pair<String, Length>>() val toasts = _toasts.asSharedFlow()
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( actual fun toPlatformString(
stringResource: StringResource, stringResource: StringResource,
vararg args: Any, vararg args: Any,
): String = stringResource.format(*args).localized() ): String = stringResource.format(*args).localized()
actual fun toast( actual fun toast(
string: String, string: String,
length: Length, length: Length,
) { ) {
GlobalScope.launchDefault { GlobalScope.launchDefault {
_toasts.emit(string to length) _toasts.emit(string to length)
}
} }
} }
}