From de66a66961bbcdb4625b6ccb26d0a6bd74ec78d8 Mon Sep 17 00:00:00 2001 From: Jay Date: Wed, 15 Jan 2020 19:10:16 -0800 Subject: [PATCH] Default Category now matches langauge Also more bug fixes with material dialogs --- .../data/database/models/Category.kt | 7 +++++- .../ui/library/LibraryCategoryView.kt | 4 +-- .../tachiyomi/ui/library/LibraryController.kt | 3 +++ .../tachiyomi/ui/library/LibraryPresenter.kt | 6 +++-- .../ui/setting/SettingsGeneralController.kt | 25 ------------------- .../ui/setting/SettingsLibraryController.kt | 4 +-- .../widget/preference/ListMatPreference.kt | 1 + .../preference/MultiListMatPreference.kt | 3 ++- 8 files changed, 20 insertions(+), 33 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 258f476303..1991e74bb6 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 java.io.Serializable interface Category : Serializable { @@ -25,7 +27,10 @@ interface Category : Serializable { this.name = name } - fun createDefault(): Category = create("Default").apply { id = 0 } + fun createDefault(context: Context): Category = create(context.getString(R.string.default_columns)) + .apply { + id = + 0 } } } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt index 65bc1c0351..b23be673cd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt @@ -169,7 +169,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att } else { category.mangaSort = ('a' + (it.second - 1)) - if (category.name == "Default") + if (category.id == 0) preferences.defaultMangaOrder().set(category.mangaSort.toString()) else db.insertCategory(category).asRxObservable().subscribe() @@ -329,7 +329,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att val mangaIds = adapter.currentItems.mapNotNull { it.manga.id } category.mangaSort = null category.mangaOrder = mangaIds - if (category.name == "Default") + if (category.id == 0) preferences.defaultMangaOrder().set(mangaIds.joinToString("/")) else db.insertCategory(category).asRxObservable().subscribe() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 4a578074a0..ffdede61bb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -332,6 +332,9 @@ class LibraryController( else activeCategory + categories.find { it.id == 0 }?.let { + it.name = resources?.getString(R.string.default_columns) ?: "Default" + } // Set the categories adapter.categories = categories 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 daa00e65da..caf2188211 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 @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.library import android.os.Bundle import com.jakewharton.rxrelay.BehaviorRelay +import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Category @@ -201,7 +202,7 @@ class LibraryPresenter( db.getTotalChapterManga().executeAsBlocking().associate { it.id!! to counter++ } } val catListing by lazy { - val default = Category.createDefault() + val default = Category.createDefault(context) val defOrder = preferences.defaultMangaOrder().getOrDefault() if (defOrder.firstOrNull()?.isLetter() == true) default.mangaSort = defOrder.first() else default.mangaOrder = defOrder.split("/").mapNotNull { it.toLongOrNull() } @@ -285,7 +286,8 @@ class LibraryPresenter( */ private fun getLibraryObservable(): Observable { return Observable.combineLatest(getCategoriesObservable(), getLibraryMangasObservable()) { dbCategories, libraryManga -> - val categories = if (libraryManga.containsKey(0)) arrayListOf(Category.createDefault()) + dbCategories + val categories = if (libraryManga.containsKey(0)) arrayListOf(Category.createDefault + (context.applicationContext)) + dbCategories else dbCategories this.categories = 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 4337eada69..0c4b96b92e 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 @@ -62,31 +62,6 @@ class SettingsGeneralController : SettingsController() { entryRange = 1..3 defaultValue = 1 } - - /*intListPreference { - key = Keys.theme - titleRes = R.string.pref_theme - entriesRes = arrayOf(R.string.light_theme, R.string.dark_theme, - R.string.amoled_theme, R.string.darkblue_theme, - R.string.system_theme, R.string.system_amoled_theme, R.string.system_darkblue_theme) - entryValues = arrayOf("1", "2", "3", "4", "5", "6", "7") - defaultValue = "5" - summary = "%s" - - onChange { newValue -> - activity?.recreate() - true - } - } - intListPreference { - key = Keys.startScreen - titleRes = R.string.pref_start_screen - entriesRes = arrayOf(R.string.label_library, R.string.label_recent_manga, - R.string.label_recent_updates) - entryValues = arrayOf("1", "2", "3") - defaultValue = "1" - summary = "%s" - }*/ switchPreference { key = Keys.automaticUpdates titleRes = R.string.pref_enable_automatic_updates 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 402e8f48c2..d9f7a16b17 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 @@ -76,7 +76,7 @@ class SettingsLibraryController : SettingsController() { titleRes = R.string.pref_library_update_restriction entriesRes = arrayOf(R.string.wifi, R.string.charging) entryValues = listOf("wifi", "ac") - customSummartRes = R.string.pref_library_update_restriction_summary + customSummaryRes = R.string.pref_library_update_restriction_summary preferences.libraryUpdateInterval().asObservable() .subscribeUntilDestroy { isVisible = it > 0 } @@ -132,7 +132,7 @@ class SettingsLibraryController : SettingsController() { key = Keys.defaultCategory titleRes = R.string.default_category - val categories = listOf(Category.createDefault()) + dbCategories + val categories = listOf(Category.createDefault(context)) + dbCategories entries = listOf(context.getString(R.string.default_category_summary)) + categories.map { it.name }.toTypedArray() entryValues = listOf(-1) + categories.mapNotNull { it.id }.toList() diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ListMatPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ListMatPreference.kt index 7b742d6a25..6c78716f62 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ListMatPreference.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ListMatPreference.kt @@ -71,6 +71,7 @@ open class ListMatPreference @JvmOverloads constructor(context: Context, attrs: else { prefs.getStringPref(key, defValue).set(value) this@ListMatPreference.summary = this@ListMatPreference.summary + callChangeListener(value) } dismiss() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/MultiListMatPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/MultiListMatPreference.kt index a02307113d..e8db43651e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/MultiListMatPreference.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/MultiListMatPreference.kt @@ -14,7 +14,7 @@ class MultiListMatPreference @JvmOverloads constructor(context: Context, attrs: ListMatPreference(context, attrs) { var allSelectionRes:Int? = null - var customSummartRes:Int + var customSummaryRes:Int get() = 0 set(value) { customSummary = context.getString(value) } var customSummary:String? = null @@ -53,6 +53,7 @@ class MultiListMatPreference @JvmOverloads constructor(context: Context, attrs: if (pos.isEmpty()) checkItem(0) else uncheckItem(0) } + callChangeListener(positions) } } }