mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2026-01-06 03:42:33 +01:00
Fix language option crash on android
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* 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.settings
|
||||
|
||||
actual fun Any.getResourceLanguages(): Map<String, String> = mapOf()
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.settings
|
||||
|
||||
import okio.Path.Companion.toPath
|
||||
import okio.asResourceFileSystem
|
||||
import java.util.Locale
|
||||
|
||||
actual fun Any.getResourceLanguages(): Map<String, String> = this::class.java.classLoader.asResourceFileSystem().list("/localization/".toPath())
|
||||
.asSequence()
|
||||
.drop(1)
|
||||
.map { it.name.substringBeforeLast('.') }
|
||||
.map { it.substringAfter("mokoBundle_") }
|
||||
.map(String::trim)
|
||||
.map { it.replace("-r", "-") }
|
||||
.filterNot(String::isBlank)
|
||||
.associateWith { Locale.forLanguageTag(it).getDisplayName(currentLocale) }
|
||||
)
|
||||
@@ -35,8 +35,6 @@ import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.core.screen.ScreenKey
|
||||
import cafe.adriel.voyager.core.screen.uniqueScreenKey
|
||||
import me.tatarka.inject.annotations.Inject
|
||||
import okio.Path.Companion.toPath
|
||||
import okio.asResourceFileSystem
|
||||
import java.time.Instant
|
||||
import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
@@ -61,6 +59,8 @@ class SettingsGeneralScreen : Screen {
|
||||
}
|
||||
}
|
||||
|
||||
expect fun Any.getResourceLanguages(): Map<String, String>
|
||||
|
||||
class SettingsGeneralViewModel @Inject constructor(
|
||||
uiPreferences: UiPreferences,
|
||||
contextWrapper: ContextWrapper
|
||||
@@ -86,15 +86,7 @@ class SettingsGeneralViewModel @Inject constructor(
|
||||
fun getLanguageChoices(): Map<String, String> = (
|
||||
mapOf(
|
||||
"" to stringResource(MR.strings.language_system_default, currentLocale.getDisplayName(currentLocale))
|
||||
) + this::class.java.classLoader.asResourceFileSystem().list("/localization/".toPath())
|
||||
.asSequence()
|
||||
.drop(1)
|
||||
.map { it.name.substringBeforeLast('.') }
|
||||
.map { it.substringAfter("mokoBundle_") }
|
||||
.map(String::trim)
|
||||
.map { it.replace("-r", "-") }
|
||||
.filterNot(String::isBlank)
|
||||
.associateWith { Locale.forLanguageTag(it).getDisplayName(currentLocale) }
|
||||
) + getResourceLanguages()
|
||||
)
|
||||
.toSortedMap(compareBy { it.lowercase() })
|
||||
|
||||
|
||||
Reference in New Issue
Block a user