Default Category now matches langauge

Also more bug fixes with material dialogs
This commit is contained in:
Jay 2020-01-15 19:10:16 -08:00
parent 6c6d9fbe07
commit de66a66961
8 changed files with 20 additions and 33 deletions

View File

@ -1,5 +1,7 @@
package eu.kanade.tachiyomi.data.database.models package eu.kanade.tachiyomi.data.database.models
import android.content.Context
import eu.kanade.tachiyomi.R
import java.io.Serializable import java.io.Serializable
interface Category : Serializable { interface Category : Serializable {
@ -25,7 +27,10 @@ interface Category : Serializable {
this.name = name 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 }
} }
} }

View File

@ -169,7 +169,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
} }
else { else {
category.mangaSort = ('a' + (it.second - 1)) category.mangaSort = ('a' + (it.second - 1))
if (category.name == "Default") if (category.id == 0)
preferences.defaultMangaOrder().set(category.mangaSort.toString()) preferences.defaultMangaOrder().set(category.mangaSort.toString())
else else
db.insertCategory(category).asRxObservable().subscribe() 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 } val mangaIds = adapter.currentItems.mapNotNull { it.manga.id }
category.mangaSort = null category.mangaSort = null
category.mangaOrder = mangaIds category.mangaOrder = mangaIds
if (category.name == "Default") if (category.id == 0)
preferences.defaultMangaOrder().set(mangaIds.joinToString("/")) preferences.defaultMangaOrder().set(mangaIds.joinToString("/"))
else else
db.insertCategory(category).asRxObservable().subscribe() db.insertCategory(category).asRxObservable().subscribe()

View File

@ -332,6 +332,9 @@ class LibraryController(
else else
activeCategory activeCategory
categories.find { it.id == 0 }?.let {
it.name = resources?.getString(R.string.default_columns) ?: "Default"
}
// Set the categories // Set the categories
adapter.categories = categories adapter.categories = categories

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.library
import android.os.Bundle import android.os.Bundle
import com.jakewharton.rxrelay.BehaviorRelay import com.jakewharton.rxrelay.BehaviorRelay
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.cache.CoverCache
import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Category
@ -201,7 +202,7 @@ class LibraryPresenter(
db.getTotalChapterManga().executeAsBlocking().associate { it.id!! to counter++ } db.getTotalChapterManga().executeAsBlocking().associate { it.id!! to counter++ }
} }
val catListing by lazy { val catListing by lazy {
val default = Category.createDefault() val default = Category.createDefault(context)
val defOrder = preferences.defaultMangaOrder().getOrDefault() val defOrder = preferences.defaultMangaOrder().getOrDefault()
if (defOrder.firstOrNull()?.isLetter() == true) default.mangaSort = defOrder.first() if (defOrder.firstOrNull()?.isLetter() == true) default.mangaSort = defOrder.first()
else default.mangaOrder = defOrder.split("/").mapNotNull { it.toLongOrNull() } else default.mangaOrder = defOrder.split("/").mapNotNull { it.toLongOrNull() }
@ -285,7 +286,8 @@ class LibraryPresenter(
*/ */
private fun getLibraryObservable(): Observable<Library> { private fun getLibraryObservable(): Observable<Library> {
return Observable.combineLatest(getCategoriesObservable(), getLibraryMangasObservable()) { dbCategories, libraryManga -> 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 else dbCategories
this.categories = categories this.categories = categories

View File

@ -62,31 +62,6 @@ class SettingsGeneralController : SettingsController() {
entryRange = 1..3 entryRange = 1..3
defaultValue = 1 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 { switchPreference {
key = Keys.automaticUpdates key = Keys.automaticUpdates
titleRes = R.string.pref_enable_automatic_updates titleRes = R.string.pref_enable_automatic_updates

View File

@ -76,7 +76,7 @@ class SettingsLibraryController : SettingsController() {
titleRes = R.string.pref_library_update_restriction titleRes = R.string.pref_library_update_restriction
entriesRes = arrayOf(R.string.wifi, R.string.charging) entriesRes = arrayOf(R.string.wifi, R.string.charging)
entryValues = listOf("wifi", "ac") entryValues = listOf("wifi", "ac")
customSummartRes = R.string.pref_library_update_restriction_summary customSummaryRes = R.string.pref_library_update_restriction_summary
preferences.libraryUpdateInterval().asObservable() preferences.libraryUpdateInterval().asObservable()
.subscribeUntilDestroy { isVisible = it > 0 } .subscribeUntilDestroy { isVisible = it > 0 }
@ -132,7 +132,7 @@ class SettingsLibraryController : SettingsController() {
key = Keys.defaultCategory key = Keys.defaultCategory
titleRes = R.string.default_category 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)) + entries = listOf(context.getString(R.string.default_category_summary)) +
categories.map { it.name }.toTypedArray() categories.map { it.name }.toTypedArray()
entryValues = listOf(-1) + categories.mapNotNull { it.id }.toList() entryValues = listOf(-1) + categories.mapNotNull { it.id }.toList()

View File

@ -71,6 +71,7 @@ open class ListMatPreference @JvmOverloads constructor(context: Context, attrs:
else { else {
prefs.getStringPref(key, defValue).set(value) prefs.getStringPref(key, defValue).set(value)
this@ListMatPreference.summary = this@ListMatPreference.summary this@ListMatPreference.summary = this@ListMatPreference.summary
callChangeListener(value)
} }
dismiss() dismiss()
} }

View File

@ -14,7 +14,7 @@ class MultiListMatPreference @JvmOverloads constructor(context: Context, attrs:
ListMatPreference(context, attrs) { ListMatPreference(context, attrs) {
var allSelectionRes:Int? = null var allSelectionRes:Int? = null
var customSummartRes:Int var customSummaryRes:Int
get() = 0 get() = 0
set(value) { customSummary = context.getString(value) } set(value) { customSummary = context.getString(value) }
var customSummary:String? = null var customSummary:String? = null
@ -53,6 +53,7 @@ class MultiListMatPreference @JvmOverloads constructor(context: Context, attrs:
if (pos.isEmpty()) checkItem(0) if (pos.isEmpty()) checkItem(0)
else uncheckItem(0) else uncheckItem(0)
} }
callChangeListener(positions)
} }
} }
} }