mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 16:11:51 +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 {
|
private fun onPositiveButtonClick(): Boolean {
|
||||||
if (category?.id ?: 0 <= 0 && category != null) return false
|
|
||||||
val text = binding.title.text.toString()
|
val text = binding.title.text.toString()
|
||||||
val categoryExists = categoryExists(text)
|
val categoryExists = categoryExists(text)
|
||||||
val category = this.category ?: Category.create(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
|
category.name = text
|
||||||
if (this.category == null) {
|
if (this.category == null) {
|
||||||
val categories = db.getCategories().executeAsBlocking()
|
val categories = db.getCategories().executeAsBlocking()
|
||||||
@ -87,19 +89,21 @@ class ManageCategoryDialog(bundle: Bundle? = null) :
|
|||||||
db.insertCategory(category).executeAsBlocking()
|
db.insertCategory(category).executeAsBlocking()
|
||||||
}
|
}
|
||||||
} else if (categoryExists) {
|
} 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
|
return false
|
||||||
} else if (text.isBlank()) {
|
} 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
|
return false
|
||||||
}
|
}
|
||||||
if (!updatePref(preferences.downloadNewCategories(), binding.downloadNew)) {
|
}
|
||||||
preferences.downloadNew().set(false)
|
when (updatePref(preferences.downloadNewCategories(), binding.downloadNew)) {
|
||||||
} else {
|
true -> preferences.downloadNew().set(true)
|
||||||
preferences.downloadNew().set(true)
|
false -> preferences.downloadNew().set(false)
|
||||||
}
|
}
|
||||||
if (preferences.libraryUpdateInterval().getOrDefault() > 0 &&
|
if (preferences.libraryUpdateInterval().getOrDefault() > 0 &&
|
||||||
!updatePref(preferences.libraryUpdateCategories(), binding.includeGlobal)
|
updatePref(preferences.libraryUpdateCategories(), binding.includeGlobal) == false
|
||||||
) {
|
) {
|
||||||
preferences.libraryUpdateInterval().set(0)
|
preferences.libraryUpdateInterval().set(0)
|
||||||
LibraryUpdateJob.setupTask(0)
|
LibraryUpdateJob.setupTask(0)
|
||||||
@ -119,10 +123,8 @@ class ManageCategoryDialog(bundle: Bundle? = null) :
|
|||||||
|
|
||||||
fun onViewCreated() {
|
fun onViewCreated() {
|
||||||
if (category?.id ?: 0 <= 0 && category != null) {
|
if (category?.id ?: 0 <= 0 && category != null) {
|
||||||
binding.title.isVisible = false
|
binding.categoryTextLayout.isVisible = false
|
||||||
binding.downloadNew.isVisible = false
|
binding.downloadNew.isVisible = false
|
||||||
binding.includeGlobal.isVisible = false
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
binding.editCategories.isVisible = category != null
|
binding.editCategories.isVisible = category != null
|
||||||
binding.editCategories.setOnClickListener {
|
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.hint = category?.name ?: binding.editCategories.context.getString(R.string.category)
|
||||||
binding.title.append(category?.name ?: "")
|
binding.title.append(category?.name ?: "")
|
||||||
|
if (binding.downloadNew.isVisible) {
|
||||||
val downloadNew = preferences.downloadNew().get()
|
val downloadNew = preferences.downloadNew().get()
|
||||||
setCheckbox(
|
setCheckbox(
|
||||||
binding.downloadNew,
|
binding.downloadNew,
|
||||||
@ -147,6 +150,7 @@ class ManageCategoryDialog(bundle: Bundle? = null) :
|
|||||||
}
|
}
|
||||||
binding.downloadNew.isChecked =
|
binding.downloadNew.isChecked =
|
||||||
preferences.downloadNew().get() && binding.downloadNew.isChecked
|
preferences.downloadNew().get() && binding.downloadNew.isChecked
|
||||||
|
}
|
||||||
setCheckbox(
|
setCheckbox(
|
||||||
binding.includeGlobal,
|
binding.includeGlobal,
|
||||||
preferences.libraryUpdateCategories(),
|
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 */
|
/** Update a pref based on checkbox, and return if the pref is not empty */
|
||||||
private fun updatePref(categories: Preference<Set<String>>, box: CompoundButton): Boolean {
|
private fun updatePref(categories: Preference<Set<String>>, box: CompoundButton): Boolean? {
|
||||||
val categoryId = category?.id ?: return true
|
val categoryId = category?.id ?: return null
|
||||||
|
if (!box.isVisible) return null
|
||||||
val updateCategories = categories.get().toMutableSet()
|
val updateCategories = categories.get().toMutableSet()
|
||||||
if (box.isChecked) {
|
if (box.isChecked) {
|
||||||
updateCategories.add(categoryId.toString())
|
updateCategories.add(categoryId.toString())
|
||||||
|
Loading…
Reference in New Issue
Block a user