mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 11:31:54 +01:00
Updates to manage category dialog
Fixes to default category basically + adding global update check to default
This commit is contained in:
parent
d72189b8e4
commit
63e6fb715d
@ -70,11 +70,13 @@ class ManageCategoryDialog(bundle: Bundle? = null) :
|
||||
}
|
||||
|
||||
private fun onPositiveButtonClick(): Boolean {
|
||||
if (category?.id ?: 0 <= 0 && category != null) return false
|
||||
val text = binding.title.text.toString()
|
||||
val categoryExists = categoryExists(text)
|
||||
val category = this.category ?: Category.create(text)
|
||||
if (text.isNotBlank() && !categoryExists && !text.equals(this.category?.name ?: "", true)) {
|
||||
if (category.id != 0) {
|
||||
if (text.isNotBlank() && !categoryExists &&
|
||||
!text.equals(this.category?.name ?: "", true)
|
||||
) {
|
||||
category.name = text
|
||||
if (this.category == null) {
|
||||
val categories = db.getCategories().executeAsBlocking()
|
||||
@ -87,19 +89,21 @@ class ManageCategoryDialog(bundle: Bundle? = null) :
|
||||
db.insertCategory(category).executeAsBlocking()
|
||||
}
|
||||
} else if (categoryExists) {
|
||||
binding.categoryTextLayout.error = binding.categoryTextLayout.context.getString(R.string.category_with_name_exists)
|
||||
binding.categoryTextLayout.error =
|
||||
binding.categoryTextLayout.context.getString(R.string.category_with_name_exists)
|
||||
return false
|
||||
} else if (text.isBlank()) {
|
||||
binding.categoryTextLayout.error = binding.categoryTextLayout.context.getString(R.string.category_cannot_be_blank)
|
||||
binding.categoryTextLayout.error =
|
||||
binding.categoryTextLayout.context.getString(R.string.category_cannot_be_blank)
|
||||
return false
|
||||
}
|
||||
if (!updatePref(preferences.downloadNewCategories(), binding.downloadNew)) {
|
||||
preferences.downloadNew().set(false)
|
||||
} else {
|
||||
preferences.downloadNew().set(true)
|
||||
}
|
||||
when (updatePref(preferences.downloadNewCategories(), binding.downloadNew)) {
|
||||
true -> preferences.downloadNew().set(true)
|
||||
false -> preferences.downloadNew().set(false)
|
||||
}
|
||||
if (preferences.libraryUpdateInterval().getOrDefault() > 0 &&
|
||||
!updatePref(preferences.libraryUpdateCategories(), binding.includeGlobal)
|
||||
updatePref(preferences.libraryUpdateCategories(), binding.includeGlobal) == false
|
||||
) {
|
||||
preferences.libraryUpdateInterval().set(0)
|
||||
LibraryUpdateJob.setupTask(0)
|
||||
@ -119,10 +123,8 @@ class ManageCategoryDialog(bundle: Bundle? = null) :
|
||||
|
||||
fun onViewCreated() {
|
||||
if (category?.id ?: 0 <= 0 && category != null) {
|
||||
binding.title.isVisible = false
|
||||
binding.categoryTextLayout.isVisible = false
|
||||
binding.downloadNew.isVisible = false
|
||||
binding.includeGlobal.isVisible = false
|
||||
return
|
||||
}
|
||||
binding.editCategories.isVisible = category != null
|
||||
binding.editCategories.setOnClickListener {
|
||||
@ -134,6 +136,7 @@ class ManageCategoryDialog(bundle: Bundle? = null) :
|
||||
}
|
||||
binding.title.hint = category?.name ?: binding.editCategories.context.getString(R.string.category)
|
||||
binding.title.append(category?.name ?: "")
|
||||
if (binding.downloadNew.isVisible) {
|
||||
val downloadNew = preferences.downloadNew().get()
|
||||
setCheckbox(
|
||||
binding.downloadNew,
|
||||
@ -147,6 +150,7 @@ class ManageCategoryDialog(bundle: Bundle? = null) :
|
||||
}
|
||||
binding.downloadNew.isChecked =
|
||||
preferences.downloadNew().get() && binding.downloadNew.isChecked
|
||||
}
|
||||
setCheckbox(
|
||||
binding.includeGlobal,
|
||||
preferences.libraryUpdateCategories(),
|
||||
@ -155,8 +159,9 @@ class ManageCategoryDialog(bundle: Bundle? = null) :
|
||||
}
|
||||
|
||||
/** Update a pref based on checkbox, and return if the pref is not empty */
|
||||
private fun updatePref(categories: Preference<Set<String>>, box: CompoundButton): Boolean {
|
||||
val categoryId = category?.id ?: return true
|
||||
private fun updatePref(categories: Preference<Set<String>>, box: CompoundButton): Boolean? {
|
||||
val categoryId = category?.id ?: return null
|
||||
if (!box.isVisible) return null
|
||||
val updateCategories = categories.get().toMutableSet()
|
||||
if (box.isChecked) {
|
||||
updateCategories.add(categoryId.toString())
|
||||
|
Loading…
Reference in New Issue
Block a user