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
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 }
}
}

View File

@ -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()

View File

@ -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

View File

@ -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<Library> {
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

View File

@ -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

View File

@ -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()

View File

@ -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()
}

View File

@ -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)
}
}
}