From 3670d649b8b011fd3bb10f66e33f221aea2c3b72 Mon Sep 17 00:00:00 2001 From: Andreas Date: Fri, 20 Aug 2021 00:10:43 +0200 Subject: [PATCH] Make default category translatable (#5751) * Make default category translatable * Replace duplicate strings with common one --- .../kanade/tachiyomi/data/database/models/Category.kt | 4 +++- .../tachiyomi/data/preference/PreferenceValues.kt | 2 +- .../eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt | 2 +- .../tachiyomi/ui/reader/setting/OrientationType.kt | 2 +- .../tachiyomi/ui/reader/setting/ReadingModeType.kt | 2 +- .../tachiyomi/ui/setting/SettingsDownloadController.kt | 4 ++-- .../tachiyomi/ui/setting/SettingsGeneralController.kt | 2 +- .../tachiyomi/ui/setting/SettingsLibraryController.kt | 10 +++++----- .../eu/kanade/tachiyomi/util/lang/DateExtensions.kt | 2 -- app/src/main/res/values-v28/arrays.xml | 2 +- app/src/main/res/values/arrays.xml | 10 +++++----- app/src/main/res/values/strings.xml | 8 +------- 12 files changed, 22 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Category.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Category.kt index 366a1b8550..4903dee800 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Category.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Category.kt @@ -1,5 +1,7 @@ package eu.kanade.tachiyomi.data.database.models +import android.content.Context +import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.library.setting.DisplayModeSetting import eu.kanade.tachiyomi.ui.library.setting.SortDirectionSetting import eu.kanade.tachiyomi.ui.library.setting.SortModeSetting @@ -37,6 +39,6 @@ interface Category : Serializable { this.name = name } - fun createDefault(): Category = create("Default").apply { id = 0 } + fun createDefault(context: Context): Category = create(context.getString(R.string.label_default)).apply { id = 0 } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt index b7e2f6ae0b..60192114e2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt @@ -22,7 +22,7 @@ object PreferenceValues { /* ktlint-enable experimental:enum-entry-name-case */ enum class AppTheme(val titleResId: Int?) { - DEFAULT(R.string.theme_default), + DEFAULT(R.string.label_default), MONET(R.string.theme_monet), BLUE(R.string.theme_blue), GREEN_APPLE(R.string.theme_greenapple), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index e7eaeda6f2..9b959a0b1d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -327,7 +327,7 @@ class LibraryPresenter( private fun getLibraryObservable(): Observable { return Observable.combineLatest(getCategoriesObservable(), getLibraryMangasObservable()) { dbCategories, libraryManga -> val categories = if (libraryManga.containsKey(0)) { - arrayListOf(Category.createDefault()) + dbCategories + arrayListOf(Category.createDefault(context)) + dbCategories } else { dbCategories } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/OrientationType.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/OrientationType.kt index 805c9452d4..fe0b81dd1e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/OrientationType.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/OrientationType.kt @@ -7,7 +7,7 @@ import eu.kanade.tachiyomi.R enum class OrientationType(val prefValue: Int, val flag: Int, @StringRes val stringRes: Int, @DrawableRes val iconRes: Int, val flagValue: Int) { // TODO Default icon - DEFAULT(0, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED, R.string.default_rotation_type, R.drawable.ic_screen_rotation_24dp, 0x00000000), + DEFAULT(0, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED, R.string.label_default, R.drawable.ic_screen_rotation_24dp, 0x00000000), FREE(1, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED, R.string.rotation_free, R.drawable.ic_screen_rotation_24dp, 0x00000008), PORTRAIT(2, ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT, R.string.rotation_portrait, R.drawable.ic_stay_current_portrait_24dp, 0x00000010), LANDSCAPE(3, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, R.string.rotation_landscape, R.drawable.ic_stay_current_landscape_24dp, 0x00000018), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReadingModeType.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReadingModeType.kt index ca927bfc7b..5617c7aaad 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReadingModeType.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReadingModeType.kt @@ -11,7 +11,7 @@ import eu.kanade.tachiyomi.ui.reader.viewer.pager.VerticalPagerViewer import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer enum class ReadingModeType(val prefValue: Int, @StringRes val stringRes: Int, @DrawableRes val iconRes: Int, val flagValue: Int) { - DEFAULT(0, R.string.default_viewer, R.drawable.ic_reader_default_24dp, 0x00000000), + DEFAULT(0, R.string.label_default, R.drawable.ic_reader_default_24dp, 0x00000000), LEFT_TO_RIGHT(1, R.string.left_to_right_viewer, R.drawable.ic_reader_ltr_24dp, 0x00000001), RIGHT_TO_LEFT(2, R.string.right_to_left_viewer, R.drawable.ic_reader_rtl_24dp, 0x00000002), VERTICAL(3, R.string.vertical_viewer, R.drawable.ic_reader_vertical_24dp, 0x00000003), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt index b8aed28bde..4f4b8a022f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt @@ -96,7 +96,7 @@ class SettingsDownloadController : SettingsController() { } val dbCategories = db.getCategories().executeAsBlocking() - val categories = listOf(Category.createDefault()) + dbCategories + val categories = listOf(Category.createDefault(context)) + dbCategories preferenceCategory { titleRes = R.string.pref_category_auto_download @@ -228,7 +228,7 @@ class SettingsDownloadController : SettingsController() { override fun onCreateDialog(savedViewState: Bundle?): Dialog { val dbCategories = db.getCategories().executeAsBlocking() - val categories = listOf(Category.createDefault()) + dbCategories + val categories = listOf(Category.createDefault(activity!!)) + dbCategories val items = categories.map { it.name } var selected = categories diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index 070bee9bcf..a57e1ee099 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -103,7 +103,7 @@ class SettingsGeneralController : SettingsController() { entries = entryValues.map { value -> val formattedDate = preferences.dateFormat(value.toString()).format(now) if (value == "") { - "${context.getString(R.string.system_default)} ($formattedDate)" + "${context.getString(R.string.label_default)} ($formattedDate)" } else { "$value ($formattedDate)" } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index 25f2650fe2..57ecb05386 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -51,7 +51,7 @@ class SettingsLibraryController : SettingsController() { titleRes = R.string.pref_category_library val dbCategories = db.getCategories().executeAsBlocking() - val categories = listOf(Category.createDefault()) + dbCategories + val categories = listOf(Category.createDefault(context)) + dbCategories preferenceCategory { titleRes = R.string.pref_category_display @@ -65,7 +65,7 @@ class SettingsLibraryController : SettingsController() { fun getColumnValue(value: Int): String { return if (value == 0) { - context.getString(R.string.default_columns) + context.getString(R.string.label_default) } else { value.toString() } @@ -313,7 +313,7 @@ class SettingsLibraryController : SettingsController() { fun onViewCreated(binding: PrefLibraryColumnsBinding) { with(binding.portraitColumns) { - displayedValues = arrayOf(context.getString(R.string.default_columns)) + + displayedValues = arrayOf(context.getString(R.string.label_default)) + IntRange(1, 10).map(Int::toString) value = portrait @@ -322,7 +322,7 @@ class SettingsLibraryController : SettingsController() { } } with(binding.landscapeColumns) { - displayedValues = arrayOf(context.getString(R.string.default_columns)) + + displayedValues = arrayOf(context.getString(R.string.label_default)) + IntRange(1, 10).map(Int::toString) value = landscape @@ -340,7 +340,7 @@ class SettingsLibraryController : SettingsController() { override fun onCreateDialog(savedViewState: Bundle?): Dialog { val dbCategories = db.getCategories().executeAsBlocking() - val categories = listOf(Category.createDefault()) + dbCategories + val categories = listOf(Category.createDefault(activity!!)) + dbCategories val items = categories.map { it.name } var selected = categories diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/lang/DateExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/lang/DateExtensions.kt index 521517b0f8..c39cdd9f07 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/lang/DateExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/lang/DateExtensions.kt @@ -122,5 +122,3 @@ fun Date.toRelativeString( else -> dateFormat.format(this) } } - - diff --git a/app/src/main/res/values-v28/arrays.xml b/app/src/main/res/values-v28/arrays.xml index 6a5e11f665..9718e45110 100644 --- a/app/src/main/res/values-v28/arrays.xml +++ b/app/src/main/res/values-v28/arrays.xml @@ -2,7 +2,7 @@ - @string/filter_mode_default + @string/label_default @string/filter_mode_multiply @string/filter_mode_screen diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index a516a943af..b7ba2e3dbb 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -1,7 +1,7 @@ - @string/default_viewer + @string/label_default @string/left_to_right_viewer @string/right_to_left_viewer @string/vertical_viewer @@ -63,7 +63,7 @@ - @string/default_rotation_type + @string/label_default @string/rotation_free @string/rotation_portrait @string/rotation_landscape @@ -72,7 +72,7 @@ - @string/filter_mode_default + @string/label_default @string/filter_mode_multiply @string/filter_mode_screen @@ -90,7 +90,7 @@ - @string/default_nav + @string/label_default @string/l_nav @string/kindlish_nav @string/edge_nav @@ -98,7 +98,7 @@ - @string/default_nav + @string/label_default @string/l_nav @string/kindlish_nav @string/edge_nav diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4f44316951..b8e032cb8d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -23,6 +23,7 @@ Extensions Extension info Help + Default Unlock Tachiyomi Authenticate to confirm change @@ -147,7 +148,6 @@ Off On App theme - Default Dynamic Blue Green Apple @@ -159,7 +159,6 @@ Yotsuba Pure black dark mode Start screen - Default Date format Confirm exit Hide bottom bar on scroll @@ -203,7 +202,6 @@ Items per row Portrait Landscape - Default Jump to chapters on open Global update @@ -290,7 +288,6 @@ Inverted Custom color filter Color filter blend mode - Default Overlay Multiply Screen @@ -318,8 +315,6 @@ Black Automatic Default reading mode - Default - Default L shaped Kindle-ish Edge @@ -351,7 +346,6 @@ Normal Fast Default rotation type - Default Rotation type Free Portrait