mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-10 06:42:05 +01:00
Fix formatting in a few more files
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
)
|
||||
}
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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 = "/")),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Pair<String, Length>>()
|
||||
val toasts = _toasts.asSharedFlow()
|
||||
@Inject
|
||||
actual class ContextWrapper() {
|
||||
private val _toasts = MutableSharedFlow<Pair<String, Length>>()
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user