Use CommonMain for presentation, use Klock date/format library

This commit is contained in:
Syer10
2022-03-16 23:11:16 -04:00
parent a40383879e
commit 2be40fe12a
145 changed files with 270 additions and 74 deletions

View File

@@ -80,6 +80,7 @@ dependencies {
// Utility
implementation(libs.krokiCoroutines)
implementation(libs.klock)
// Localization
implementation(libs.moko.core)

View File

@@ -48,6 +48,7 @@ kotlin {
api(libs.multiplatformSettings.coroutines)
api(libs.multiplatformSettings.serialization)
api(libs.locale)
api(libs.klock)
}
}
val commonTest by getting {

View File

@@ -8,4 +8,5 @@ package ca.gosyer.core.io
import okio.FileSystem
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
expect val FileSystem.Companion.SYSTEM: FileSystem

View File

@@ -9,4 +9,5 @@ package ca.gosyer.core.lang
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
expect val Dispatchers.IO: CoroutineDispatcher

View File

@@ -9,3 +9,9 @@ package ca.gosyer.core.lang
import io.fluidsonic.locale.Locale
expect fun Locale.Companion.getDefault(): Locale
expect fun Locale.getDisplayLanguage(displayLocale: Locale): String
expect fun Locale.getDisplayName(displayLocale: Locale): String
expect val Locale.displayName: String

View File

@@ -6,6 +6,8 @@
package ca.gosyer.core.lang
import io.fluidsonic.locale.Locale
/**
* Replaces the given string to have at most [count] characters using [replacement] at its end.
* If [replacement] is longer than [count] an exception will be thrown when `length > count`.
@@ -17,3 +19,9 @@ fun String.chop(count: Int, replacement: String = "…"): String {
this
}
}
expect fun String.uppercase(locale: Locale): String
expect fun String.lowercase(locale: Locale): String
expect fun Char.titlecase(locale: Locale): String

View File

@@ -8,6 +8,15 @@ package ca.gosyer.core.lang
import io.fluidsonic.locale.Locale
import io.fluidsonic.locale.toCommon
import io.fluidsonic.locale.toPlatform
import java.util.Locale as PlatformLocale
actual fun Locale.Companion.getDefault(): Locale = PlatformLocale.getDefault().toCommon()
actual fun Locale.getDisplayLanguage(displayLocale: Locale): String = toPlatform()
.getDisplayLanguage(displayLocale.toPlatform())
actual fun Locale.getDisplayName(displayLocale: Locale): String = toPlatform()
.getDisplayName(displayLocale.toPlatform())
actual val Locale.displayName get() = toPlatform().displayName

View File

@@ -7,7 +7,15 @@
package ca.gosyer.core.lang
import java.util.Locale
import io.fluidsonic.locale.Locale
import io.fluidsonic.locale.toPlatform
fun String.capitalize(locale: Locale = Locale.getDefault()) =
replaceFirstChar { if (it.isLowerCase()) it.titlecase(locale) else it.toString() }
actual fun String.uppercase(locale: Locale): String = uppercase(locale.toPlatform())
actual fun String.lowercase(locale: Locale): String = lowercase(locale.toPlatform())
actual fun Char.titlecase(locale: Locale): String = titlecase(locale.toPlatform())

View File

@@ -43,9 +43,10 @@ kotlin {
api(libs.ktor.websockets)
api(libs.ktor.okHttp)
api(libs.okio)
api(libs.locale)
api(libs.klock)
api(projects.core)
api(projects.i18n)
api(libs.locale)
}
}
val commonTest by getting {

View File

@@ -81,6 +81,7 @@ dependencies {
// Utility
implementation(libs.krokiCoroutines)
implementation(libs.klock)
// Localization
implementation(libs.moko.core)

View File

@@ -50,6 +50,7 @@ multiplatformSettings = "0.8.1"
# Utility
kroki = "1.22"
desugarJdkLibs = "1.1.5"
klock = "2.2.0"
# Localization
locale = "0.11.0"
@@ -137,6 +138,7 @@ multiplatformSettings-coroutines = { module = "com.russhwolf:multiplatform-setti
# Utility
krokiCoroutines = { module = "io.github.kerubistan.kroki:kroki-coroutines", version.ref = "kroki" }
desugarJdkLibs = { module = "com.android.tools:desugar_jdk_libs", version.ref = "desugarJdkLibs" }
klock = { module = "com.soywiz.korlibs.klock:klock", version.ref = "klock" }
# Localization
moko-core = { module = "dev.icerock.moko:resources", version.ref = "moko" }

View File

@@ -51,6 +51,7 @@ kotlin {
api(libs.accompanist.flowLayout)
api(libs.krokiCoroutines)
api(libs.locale)
api(libs.klock)
api(projects.core)
api(projects.i18n)
api(projects.data)

View File

@@ -14,7 +14,6 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.ContentAlpha
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.LocalContentColor
@@ -39,6 +38,7 @@ import ca.gosyer.data.models.Manga
import ca.gosyer.data.server.interactions.ChapterInteractionHandler
import ca.gosyer.i18n.MR
import ca.gosyer.uicore.components.DropdownIconButton
import ca.gosyer.uicore.components.DropdownMenuItem
import ca.gosyer.uicore.resources.stringResource
import io.ktor.client.statement.HttpResponse
import kotlinx.coroutines.flow.Flow

View File

@@ -6,9 +6,10 @@
package ca.gosyer.ui.base.components
import java.util.Locale
import ca.gosyer.core.lang.getDefault
import ca.gosyer.core.lang.getDisplayLanguage
import io.fluidsonic.locale.Locale
fun localeToString(locale: String) = Locale.forLanguageTag(locale)
?.getDisplayLanguage(Locale.getDefault())
?.ifBlank { null }
?: locale.uppercase()
.getDisplayLanguage(Locale.getDefault())
.ifBlank { locale.uppercase() }

View File

@@ -6,8 +6,6 @@
package ca.gosyer.ui.base.navigation
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.LocalContentAlpha
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
@@ -24,6 +22,8 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.util.fastForEach
import ca.gosyer.i18n.MR
import ca.gosyer.uicore.components.DropdownMenu
import ca.gosyer.uicore.components.DropdownMenuItem
import ca.gosyer.uicore.resources.stringResource
// Originally from https://gist.github.com/MachFour/369ebb56a66e2f583ebfb988dda2decf

View File

@@ -56,7 +56,6 @@ import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.isSpecified
import androidx.compose.ui.graphics.luminance
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.input.pointer.PointerInputScope
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.onSizeChanged
@@ -65,6 +64,8 @@ import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastForEachIndexed
import ca.gosyer.ui.base.dialog.getMaterialDialogProperties
import ca.gosyer.ui.util.compose.toHexString
import ca.gosyer.ui.util.compose.toLong
import ca.gosyer.uicore.components.keyboardHandler
import com.vanpra.composematerialdialogs.MaterialDialog
import com.vanpra.composematerialdialogs.MaterialDialogState
@@ -203,7 +204,7 @@ private fun ColorPresetItem(
}
private fun getColorShades(color: Color): List<Color> {
val f = String.format("%06X", 0xFFFFFF and color.toArgb()).toLong(16)
val f = color.toLong()
return listOf(
shadeColor(f, 0.9), shadeColor(f, 0.7), shadeColor(f, 0.5),
shadeColor(f, 0.333), shadeColor(f, 0.166), shadeColor(f, -0.125),
@@ -422,10 +423,6 @@ private fun hueToColor(hue: Float): Color {
return hsvToColor(hue, 1f, 1f)
}
private fun Color.toHexString(): String {
return String.format("#%06X", (0xFFFFFF and toArgb()))
}
internal expect fun hexStringToColor(hex: String): Color?
private val presetColors = listOf(

View File

@@ -4,8 +4,6 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
@file:JvmName("ThemeScrollbarStyleKt")
package ca.gosyer.ui.base.theme
import androidx.compose.foundation.isSystemInDarkTheme

View File

@@ -13,6 +13,7 @@ import ca.gosyer.uicore.vm.viewModel
import cafe.adriel.voyager.core.screen.Screen
import cafe.adriel.voyager.core.screen.ScreenKey
import cafe.adriel.voyager.core.screen.uniqueScreenKey
import kotlin.jvm.Transient
expect class CategoriesLauncher {

View File

@@ -20,7 +20,6 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.Icon
import androidx.compose.material.LinearProgressIndicator
import androidx.compose.material.MaterialTheme
@@ -48,6 +47,7 @@ import ca.gosyer.i18n.MR
import ca.gosyer.ui.base.navigation.ActionItem
import ca.gosyer.ui.base.navigation.Toolbar
import ca.gosyer.uicore.components.DropdownIconButton
import ca.gosyer.uicore.components.DropdownMenuItem
import ca.gosyer.uicore.components.MangaListItem
import ca.gosyer.uicore.components.MangaListItemColumn
import ca.gosyer.uicore.components.MangaListItemImage

View File

@@ -6,6 +6,7 @@
package ca.gosyer.ui.extensions
import ca.gosyer.core.lang.displayName
import ca.gosyer.core.logging.CKLogger
import ca.gosyer.data.extension.ExtensionPreferences
import ca.gosyer.data.models.Extension
@@ -13,6 +14,7 @@ import ca.gosyer.data.server.interactions.ExtensionInteractionHandler
import ca.gosyer.i18n.MR
import ca.gosyer.uicore.vm.ContextWrapper
import ca.gosyer.uicore.vm.ViewModel
import io.fluidsonic.locale.Locale
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.asStateFlow
@@ -24,7 +26,6 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
import me.tatarka.inject.annotations.Inject
import java.util.Locale
class ExtensionsScreenViewModel @Inject constructor(
private val extensionHandler: ExtensionInteractionHandler,
@@ -128,7 +129,7 @@ class ExtensionsScreenViewModel @Inject constructor(
val queries = searchQuery.split(" ")
val filteredExtensions = extensions.toMutableList()
queries.forEach { query ->
filteredExtensions.removeIf { !it.name.contains(query, true) }
filteredExtensions.removeAll { !it.name.contains(query, true) }
}
filteredExtensions.toList().splitSort()
}

View File

@@ -46,6 +46,9 @@ import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import ca.gosyer.core.lang.getDefault
import ca.gosyer.core.lang.getDisplayName
import ca.gosyer.core.lang.uppercase
import ca.gosyer.data.models.Extension
import ca.gosyer.i18n.MR
import ca.gosyer.presentation.build.BuildKonfig
@@ -61,8 +64,8 @@ import com.vanpra.composematerialdialogs.MaterialDialog
import com.vanpra.composematerialdialogs.MaterialDialogState
import com.vanpra.composematerialdialogs.rememberMaterialDialogState
import com.vanpra.composematerialdialogs.title
import io.fluidsonic.locale.Locale
import io.kamel.image.lazyPainterResource
import java.util.Locale
@Composable
fun ExtensionsScreenContent(
@@ -233,7 +236,7 @@ fun LanguageDialog(
horizontalArrangement = Arrangement.SpaceBetween
) {
val langName by derivedStateOf {
Locale.forLanguageTag(lang)?.getDisplayName(locale) ?: lang
Locale.forLanguageTag(lang).getDisplayName(locale).ifBlank { lang }
}
Text(langName)
Switch(

View File

@@ -6,6 +6,8 @@
package ca.gosyer.ui.library
import ca.gosyer.core.lang.getDefault
import ca.gosyer.core.lang.lowercase
import ca.gosyer.core.lang.withDefaultContext
import ca.gosyer.core.logging.CKLogger
import ca.gosyer.data.library.LibraryPreferences
@@ -16,8 +18,10 @@ import ca.gosyer.data.server.interactions.CategoryInteractionHandler
import ca.gosyer.data.server.interactions.LibraryInteractionHandler
import ca.gosyer.data.server.interactions.UpdatesInteractionHandler
import ca.gosyer.i18n.MR
import ca.gosyer.ui.util.lang.Collator
import ca.gosyer.uicore.vm.ContextWrapper
import ca.gosyer.uicore.vm.ViewModel
import io.fluidsonic.locale.Locale
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.flow.MutableStateFlow
@@ -36,9 +40,6 @@ import kotlinx.coroutines.flow.single
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.toList
import me.tatarka.inject.annotations.Inject
import java.text.Collator
import java.util.Collections
import java.util.Locale
private typealias CategoryItems = Pair<StateFlow<List<Manga>>, MutableStateFlow<List<Manga>>>
private typealias LibraryMap = MutableMap<Long, CategoryItems>
@@ -117,9 +118,7 @@ class LibraryScreenViewModel @Inject constructor(
val sortFn = when (sortMode) {
Sort.ALPHABETICAL -> {
val locale = Locale.getDefault()
val collator = Collator.getInstance(locale).apply {
strength = Collator.PRIMARY
};
val collator = Collator(locale);
{ a: Manga, b: Manga ->
collator.compare(a.title.lowercase(locale), b.title.lowercase(locale))
@@ -139,7 +138,7 @@ class LibraryScreenViewModel @Inject constructor(
return if (ascending) {
Comparator(sortFn)
} else {
Collections.reverseOrder(sortFn)
Comparator(sortFn).reversed()
}
}

View File

@@ -0,0 +1,15 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package ca.gosyer.ui.main.components
import ca.gosyer.uicore.vm.ViewModel
import kotlinx.coroutines.flow.MutableStateFlow
expect class DebugOverlayViewModel : ViewModel {
val maxMemory: String
val usedMemoryFlow: MutableStateFlow<String>
}

View File

@@ -20,6 +20,9 @@ import ca.gosyer.data.ui.UiPreferences
import ca.gosyer.ui.base.chapter.ChapterDownloadItem
import ca.gosyer.uicore.vm.ContextWrapper
import ca.gosyer.uicore.vm.ViewModel
import com.soywiz.klock.DateFormat
import com.soywiz.klock.KlockLocale
import com.soywiz.klock.PatternDateFormat
import kotlinx.coroutines.async
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
@@ -35,10 +38,6 @@ import kotlinx.coroutines.flow.single
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import me.tatarka.inject.annotations.Inject
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
import java.util.Locale
class MangaScreenViewModel @Inject constructor(
private val mangaHandler: MangaInteractionHandler,
@@ -214,12 +213,9 @@ class MangaScreenViewModel @Inject constructor(
}
}
private fun getDateFormat(format: String): DateTimeFormatter = when (format) {
"" -> DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)
.withLocale(Locale.getDefault())
.withZone(ZoneId.systemDefault())
else -> DateTimeFormatter.ofPattern(format)
.withZone(ZoneId.systemDefault())
private fun getDateFormat(format: String): DateFormat = when (format) {
"" -> KlockLocale.default.formatDateShort
else -> PatternDateFormat(format)
}
fun toggleRead(index: Int) {

View File

@@ -32,7 +32,7 @@ import ca.gosyer.i18n.MR
import ca.gosyer.ui.base.chapter.ChapterDownloadIcon
import ca.gosyer.ui.base.chapter.ChapterDownloadItem
import ca.gosyer.uicore.resources.stringResource
import java.time.Instant
import com.soywiz.klock.DateTime
expect fun Modifier.chapterItemModifier(
onClick: () -> Unit,
@@ -44,7 +44,7 @@ expect fun Modifier.chapterItemModifier(
@Composable
fun ChapterItem(
chapterDownload: ChapterDownloadItem,
format: (Instant) -> String,
format: (DateTime) -> String,
onClick: (Int) -> Unit,
toggleRead: (Int) -> Unit,
toggleBookmarked: (Int) -> Unit,
@@ -86,7 +86,7 @@ fun ChapterItem(
}
val subtitleStr = buildAnnotatedString {
if (chapter.uploadDate > 0) {
append(format(Instant.ofEpochMilli(chapter.uploadDate)))
append(format(DateTime.fromUnix(chapter.uploadDate)))
}
if (!chapter.read && chapter.lastPageRead > 0) {
if (length > 0) append("")

View File

@@ -38,16 +38,17 @@ import ca.gosyer.uicore.components.LoadingScreen
import ca.gosyer.uicore.components.VerticalScrollbar
import ca.gosyer.uicore.components.rememberScrollbarAdapter
import ca.gosyer.uicore.resources.stringResource
import com.soywiz.klock.DateFormat
import com.soywiz.klock.format
import com.vanpra.composematerialdialogs.rememberMaterialDialogState
import kotlinx.coroutines.flow.SharedFlow
import java.time.format.DateTimeFormatter
@Composable
fun MangaScreenContent(
isLoading: Boolean,
manga: Manga?,
chapters: List<ChapterDownloadItem>,
dateTimeFormatter: DateTimeFormatter,
dateTimeFormatter: DateFormat,
categoriesExist: Boolean,
chooseCategoriesFlow: SharedFlow<Unit>,
availableCategories: List<Category>,

View File

@@ -6,6 +6,7 @@
package ca.gosyer.ui.reader.loader
import ca.gosyer.core.lang.IO
import ca.gosyer.core.lang.throwIfCancellation
import ca.gosyer.core.logging.CKLogger
import ca.gosyer.data.reader.ReaderPreferences
@@ -13,7 +14,8 @@ import ca.gosyer.data.server.interactions.ChapterInteractionHandler
import ca.gosyer.ui.reader.model.ReaderChapter
import ca.gosyer.ui.reader.model.ReaderPage
import ca.gosyer.ui.util.compose.toImageBitmap
import io.github.kerubistan.kroki.coroutines.priorityChannel
import ca.gosyer.ui.util.lang.priorityChannel
import cafe.adriel.voyager.core.concurrent.AtomicInt32
import io.ktor.client.features.onDownload
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -27,7 +29,6 @@ import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import java.util.concurrent.atomic.AtomicInteger
class TachideskPageLoader(
val chapter: ReaderChapter,
@@ -39,7 +40,7 @@ class TachideskPageLoader(
/**
* A channel used to manage requests one by one while allowing priorities.
*/
private val channel = priorityChannel<PriorityPage>()
private val channel = priorityChannel<PriorityPage>(scope = scope)
/**
* The amount of pages to preload before stopping
@@ -169,10 +170,10 @@ class TachideskPageLoader(
val priority: Int
) : Comparable<PriorityPage> {
companion object {
private val idGenerator = AtomicInteger()
private val idGenerator = AtomicInt32(1)
}
private val identifier = idGenerator.incrementAndGet()
private val identifier = idGenerator.getAndIncrement()
override fun compareTo(other: PriorityPage): Int {
val p = other.priority.compareTo(priority)

View File

@@ -33,6 +33,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import ca.gosyer.core.io.SYSTEM
import ca.gosyer.core.io.copyTo
import ca.gosyer.core.io.saveTo
import ca.gosyer.core.lang.throwIfCancellation
@@ -44,6 +45,7 @@ import ca.gosyer.ui.base.file.rememberFileChooser
import ca.gosyer.ui.base.file.rememberFileSaver
import ca.gosyer.ui.base.navigation.Toolbar
import ca.gosyer.ui.base.prefs.PreferenceRow
import ca.gosyer.ui.util.lang.toSource
import ca.gosyer.uicore.components.VerticalScrollbar
import ca.gosyer.uicore.components.rememberScrollbarAdapter
import ca.gosyer.uicore.resources.stringResource
@@ -60,7 +62,6 @@ import com.vanpra.composematerialdialogs.title
import io.ktor.client.features.onDownload
import io.ktor.client.features.onUpload
import io.ktor.http.isSuccess
import io.ktor.utils.io.jvm.javaio.toInputStream
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
@@ -79,7 +80,6 @@ import okio.Path
import okio.Sink
import okio.Source
import okio.buffer
import okio.source
import kotlin.random.Random
class SettingsBackupScreen : Screen {
@@ -208,9 +208,7 @@ class SettingsBackupViewModel @Inject constructor(
mutex.tryLock()
scope.launch {
try {
backup.content.toInputStream()
.source()
.saveTo(it)
backup.content.toSource().saveTo(it)
} catch (e: Exception) {
e.throwIfCancellation()
info(e) { "Error creating backup" }

View File

@@ -20,6 +20,8 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import ca.gosyer.core.lang.getDefault
import ca.gosyer.core.lang.getDisplayName
import ca.gosyer.data.ui.UiPreferences
import ca.gosyer.data.ui.model.StartScreen
import ca.gosyer.i18n.MR
@@ -37,17 +39,17 @@ import ca.gosyer.uicore.vm.viewModel
import cafe.adriel.voyager.core.screen.Screen
import cafe.adriel.voyager.core.screen.ScreenKey
import cafe.adriel.voyager.core.screen.uniqueScreenKey
import com.soywiz.klock.DateTime
import com.soywiz.klock.KlockLocale
import com.soywiz.klock.PatternDateFormat
import com.soywiz.klock.format
import io.fluidsonic.locale.Locale
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonPrimitive
import me.tatarka.inject.annotations.Inject
import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
import java.util.Locale
class SettingsGeneralScreen : Screen {
override val key: ScreenKey = uniqueScreenKey
@@ -77,7 +79,7 @@ class SettingsGeneralViewModel @Inject constructor(
val language = uiPreferences.language().asStateFlow()
val dateFormat = uiPreferences.dateFormat().asStateFlow()
private val now: Instant = Instant.now()
private val now = DateTime.now()
private val currentLocale = Locale.getDefault()
@Composable
@@ -99,7 +101,7 @@ class SettingsGeneralViewModel @Inject constructor(
}
return mapOf("" to stringResource(MR.strings.language_system_default, currentLocale.getDisplayName(currentLocale)))
.plus(langs)
.toSortedMap(compareBy(String.CASE_INSENSITIVE_ORDER) { it })
.toMap()
}
@Composable
@@ -115,10 +117,8 @@ class SettingsGeneralViewModel @Inject constructor(
@Composable
private fun getFormattedDate(prefValue: String): String {
return when (prefValue) {
"" -> DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)
.withLocale(Locale.getDefault())
.withZone(ZoneId.systemDefault())
else -> DateTimeFormatter.ofPattern(prefValue).withZone(ZoneId.systemDefault())
"" -> KlockLocale.default.formatDateShort
else -> PatternDateFormat(prefValue)
}.format(now)
}
}

Some files were not shown because too many files have changed in this diff Show More