This commit is contained in:
Horis
2024-07-09 12:52:40 +08:00
parent ca3b467834
commit f56896669f
12 changed files with 122 additions and 98 deletions
@@ -53,9 +53,8 @@ class ChangeBookSourceAdapter(
item: SearchBook, item: SearchBook,
payloads: MutableList<Any> payloads: MutableList<Any>
) { ) {
val bundle = payloads.getOrNull(0) as? Bundle
binding.apply { binding.apply {
if (bundle == null) { if (payloads.isEmpty()) {
tvOrigin.text = item.originName tvOrigin.text = item.originName
tvAuthor.text = item.author tvAuthor.text = item.author
tvLast.text = item.getDisplayLastChapterTitle() tvLast.text = item.getDisplayLastChapterTitle()
@@ -67,6 +66,8 @@ class ChangeBookSourceAdapter(
ivChecked.invisible() ivChecked.invisible()
} }
} else { } else {
for (i in payloads.indices) {
val bundle = payloads[i] as Bundle
bundle.keySet().map { bundle.keySet().map {
when (it) { when (it) {
"name" -> tvOrigin.text = item.originName "name" -> tvOrigin.text = item.originName
@@ -79,6 +80,7 @@ class ChangeBookSourceAdapter(
} }
} }
} }
}
val score = callBack.getBookScore(item) val score = callBack.getBookScore(item)
if (score > 0) { if (score > 0) {
binding.ivBad.gone() binding.ivBad.gone()
@@ -50,9 +50,8 @@ class ChangeChapterSourceAdapter(
item: SearchBook, item: SearchBook,
payloads: MutableList<Any> payloads: MutableList<Any>
) { ) {
val bundle = payloads.getOrNull(0) as? Bundle
binding.apply { binding.apply {
if (bundle == null) { if (payloads.isEmpty()) {
tvOrigin.text = item.originName tvOrigin.text = item.originName
tvAuthor.text = item.author tvAuthor.text = item.author
tvLast.text = item.getDisplayLastChapterTitle() tvLast.text = item.getDisplayLastChapterTitle()
@@ -64,6 +63,8 @@ class ChangeChapterSourceAdapter(
ivChecked.invisible() ivChecked.invisible()
} }
} else { } else {
for (i in payloads.indices) {
val bundle = payloads[i] as Bundle
bundle.keySet().map { bundle.keySet().map {
when (it) { when (it) {
"name" -> tvOrigin.text = item.originName "name" -> tvOrigin.text = item.originName
@@ -76,6 +77,7 @@ class ChangeChapterSourceAdapter(
} }
} }
} }
}
val score = callBack.getBookScore(item) val score = callBack.getBookScore(item)
if (score > 0) { if (score > 0) {
binding.ivBad.gone() binding.ivBad.gone()
@@ -28,12 +28,14 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) :
item: SearchBook, item: SearchBook,
payloads: MutableList<Any> payloads: MutableList<Any>
) { ) {
val bundle = payloads.getOrNull(0) as? Bundle if (payloads.isEmpty()) {
if (bundle == null) {
bind(binding, item) bind(binding, item)
} else { } else {
for (i in payloads.indices) {
val bundle = payloads[i] as Bundle
bindChange(binding, item, bundle) bindChange(binding, item, bundle)
} }
}
} }
@@ -59,13 +59,15 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
item: SearchBook, item: SearchBook,
payloads: MutableList<Any> payloads: MutableList<Any>
) { ) {
val bundle = payloads.getOrNull(0) as? Bundle if (payloads.isEmpty()) {
if (bundle == null) {
bind(binding, item) bind(binding, item)
} else { } else {
for (i in payloads.indices) {
val bundle = payloads[i] as Bundle
bindChange(binding, item, bundle) bindChange(binding, item, bundle)
} }
} }
}
override fun registerListener(holder: ItemViewHolder, binding: ItemSearchBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemSearchBinding) {
binding.root.setOnClickListener { binding.root.setOnClickListener {
@@ -89,8 +89,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
payloads: MutableList<Any> payloads: MutableList<Any>
) { ) {
binding.run { binding.run {
val payload = payloads.getOrNull(0) as? Bundle if (payloads.isEmpty()) {
if (payload == null) {
root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f)) root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f))
cbBookSource.text = item.getDisPlayNameGroup() cbBookSource.text = item.getDisPlayNameGroup()
swtEnabled.isChecked = item.enabled swtEnabled.isChecked = item.enabled
@@ -98,9 +97,11 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
upCheckSourceMessage(binding, item) upCheckSourceMessage(binding, item)
upShowExplore(ivExplore, item) upShowExplore(ivExplore, item)
} else { } else {
payload.keySet().map { for (i in payloads.indices) {
val bundle = payloads[i] as Bundle
bundle.keySet().map {
when (it) { when (it) {
"enabled" -> swtEnabled.isChecked = payload.getBoolean("enabled") "enabled" -> swtEnabled.isChecked = bundle.getBoolean("enabled")
"upName" -> cbBookSource.text = item.getDisPlayNameGroup() "upName" -> cbBookSource.text = item.getDisPlayNameGroup()
"upExplore" -> upShowExplore(ivExplore, item) "upExplore" -> upShowExplore(ivExplore, item)
"selected" -> cbBookSource.isChecked = selected.contains(item) "selected" -> cbBookSource.isChecked = selected.contains(item)
@@ -110,6 +111,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
} }
} }
} }
}
override fun registerListener(holder: ItemViewHolder, binding: ItemBookSourceBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemBookSourceBinding) {
binding.apply { binding.apply {
@@ -77,14 +77,15 @@ class TxtTocRuleAdapter(context: Context, private val callBack: CallBack) :
payloads: MutableList<Any> payloads: MutableList<Any>
) { ) {
binding.run { binding.run {
val bundle = payloads.getOrNull(0) as? Bundle if (payloads.isEmpty()) {
if (bundle == null) {
root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f)) root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f))
cbSource.text = item.name cbSource.text = item.name
swtEnabled.isChecked = item.enable swtEnabled.isChecked = item.enable
cbSource.isChecked = selected.contains(item) cbSource.isChecked = selected.contains(item)
titleExample.text = item.example titleExample.text = item.example
} else { } else {
for (i in payloads.indices) {
val bundle = payloads[i] as Bundle
bundle.keySet().map { bundle.keySet().map {
when (it) { when (it) {
"selected" -> cbSource.isChecked = selected.contains(item) "selected" -> cbSource.isChecked = selected.contains(item)
@@ -96,6 +97,7 @@ class TxtTocRuleAdapter(context: Context, private val callBack: CallBack) :
} }
} }
} }
}
override fun registerListener(holder: ItemViewHolder, binding: ItemTxtTocRuleBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemTxtTocRuleBinding) {
binding.cbSource.setOnCheckedChangeListener { buttonView, isChecked -> binding.cbSource.setOnCheckedChangeListener { buttonView, isChecked ->
@@ -249,14 +249,15 @@ class TxtTocRuleDialog() : BaseDialogFragment(R.layout.dialog_toc_regex),
payloads: MutableList<Any> payloads: MutableList<Any>
) { ) {
binding.apply { binding.apply {
val bundle = payloads.getOrNull(0) as? Bundle if (payloads.isEmpty()) {
if (bundle == null) {
root.setBackgroundColor(context.backgroundColor) root.setBackgroundColor(context.backgroundColor)
rbRegexName.text = item.name rbRegexName.text = item.name
titleExample.text = item.example titleExample.text = item.example
rbRegexName.isChecked = item.name == selectedName rbRegexName.isChecked = item.name == selectedName
swtEnabled.isChecked = item.enable swtEnabled.isChecked = item.enable
} else { } else {
for (i in payloads.indices) {
val bundle = payloads[i] as Bundle
bundle.keySet().map { bundle.keySet().map {
when (it) { when (it) {
"upName" -> rbRegexName.text = item.name "upName" -> rbRegexName.text = item.name
@@ -268,6 +269,7 @@ class TxtTocRuleDialog() : BaseDialogFragment(R.layout.dialog_toc_regex),
} }
} }
} }
}
override fun registerListener(holder: ItemViewHolder, binding: ItemTocRegexBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemTocRegexBinding) {
binding.apply { binding.apply {
@@ -95,13 +95,14 @@ class DictRuleAdapter(context: Context, var callBack: CallBack) :
payloads: MutableList<Any> payloads: MutableList<Any>
) { ) {
binding.run { binding.run {
val bundle = payloads.getOrNull(0) as? Bundle if (payloads.isEmpty()) {
if (bundle == null) {
root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f)) root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f))
cbName.text = item.name cbName.text = item.name
swtEnabled.isChecked = item.enabled swtEnabled.isChecked = item.enabled
cbName.isChecked = selected.contains(item) cbName.isChecked = selected.contains(item)
} else { } else {
for (i in payloads.indices) {
val bundle = payloads[i] as Bundle
bundle.keySet().map { bundle.keySet().map {
when (it) { when (it) {
"selected" -> cbName.isChecked = selected.contains(item) "selected" -> cbName.isChecked = selected.contains(item)
@@ -112,6 +113,7 @@ class DictRuleAdapter(context: Context, var callBack: CallBack) :
} }
} }
} }
}
override fun registerListener(holder: ItemViewHolder, binding: ItemDictRuleBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemDictRuleBinding) {
binding.apply { binding.apply {
@@ -24,12 +24,13 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) :
item: Book, item: Book,
payloads: MutableList<Any> payloads: MutableList<Any>
) = binding.run { ) = binding.run {
val bundle = payloads.getOrNull(0) as? Bundle if (payloads.isEmpty()) {
if (bundle == null) {
tvName.text = item.name tvName.text = item.name
ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin) ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin)
upRefresh(binding, item) upRefresh(binding, item)
} else { } else {
for (i in payloads.indices) {
val bundle = payloads[i] as Bundle
bundle.keySet().forEach { bundle.keySet().forEach {
when (it) { when (it) {
"name" -> tvName.text = item.name "name" -> tvName.text = item.name
@@ -39,6 +40,7 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) :
} }
} }
} }
}
private fun upRefresh(binding: ItemBookshelfGridBinding, item: Book) { private fun upRefresh(binding: ItemBookshelfGridBinding, item: Book) {
if (!item.isLocal && callBack.isUpdate(item.bookUrl)) { if (!item.isLocal && callBack.isUpdate(item.bookUrl)) {
@@ -30,8 +30,7 @@ class BooksAdapterList(
item: Book, item: Book,
payloads: MutableList<Any> payloads: MutableList<Any>
) = binding.run { ) = binding.run {
val bundle = payloads.getOrNull(0) as? Bundle if (payloads.isEmpty()) {
if (bundle == null) {
tvName.text = item.name tvName.text = item.name
tvAuthor.text = item.author tvAuthor.text = item.author
tvRead.text = item.durChapterTitle tvRead.text = item.durChapterTitle
@@ -40,6 +39,8 @@ class BooksAdapterList(
upRefresh(binding, item) upRefresh(binding, item)
upLastUpdateTime(binding, item) upLastUpdateTime(binding, item)
} else { } else {
for (i in payloads.indices) {
val bundle = payloads[i] as Bundle
bundle.keySet().forEach { bundle.keySet().forEach {
when (it) { when (it) {
"name" -> tvName.text = item.name "name" -> tvName.text = item.name
@@ -61,6 +62,7 @@ class BooksAdapterList(
} }
} }
} }
}
private fun upRefresh(binding: ItemBookshelfListBinding, item: Book) { private fun upRefresh(binding: ItemBookshelfListBinding, item: Book) {
if (!item.isLocal && callBack.isUpdate(item.bookUrl)) { if (!item.isLocal && callBack.isUpdate(item.bookUrl)) {
@@ -103,13 +103,14 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
payloads: MutableList<Any> payloads: MutableList<Any>
) { ) {
binding.run { binding.run {
val bundle = payloads.getOrNull(0) as? Bundle if (payloads.isEmpty()) {
if (bundle == null) {
root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f)) root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f))
cbName.text = item.getDisplayNameGroup() cbName.text = item.getDisplayNameGroup()
swtEnabled.isChecked = item.isEnabled swtEnabled.isChecked = item.isEnabled
cbName.isChecked = selected.contains(item) cbName.isChecked = selected.contains(item)
} else { } else {
for (i in payloads.indices) {
val bundle = payloads[i] as Bundle
bundle.keySet().map { bundle.keySet().map {
when (it) { when (it) {
"selected" -> cbName.isChecked = selected.contains(item) "selected" -> cbName.isChecked = selected.contains(item)
@@ -120,6 +121,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
} }
} }
} }
}
override fun registerListener(holder: ItemViewHolder, binding: ItemReplaceRuleBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemReplaceRuleBinding) {
binding.apply { binding.apply {
@@ -17,7 +17,7 @@ import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.utils.ColorUtils import io.legado.app.utils.ColorUtils
import java.util.* import java.util.Collections
class RssSourceAdapter(context: Context, val callBack: CallBack) : class RssSourceAdapter(context: Context, val callBack: CallBack) :
@@ -73,13 +73,14 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
payloads: MutableList<Any> payloads: MutableList<Any>
) { ) {
binding.run { binding.run {
val bundle = payloads.getOrNull(0) as? Bundle if (payloads.isEmpty()) {
if (bundle == null) {
root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f)) root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f))
cbSource.text = item.getDisplayNameGroup() cbSource.text = item.getDisplayNameGroup()
swtEnabled.isChecked = item.enabled swtEnabled.isChecked = item.enabled
cbSource.isChecked = selected.contains(item) cbSource.isChecked = selected.contains(item)
} else { } else {
for (i in payloads.indices) {
val bundle = payloads[i] as Bundle
bundle.keySet().map { bundle.keySet().map {
when (it) { when (it) {
"upName" -> cbSource.text = item.getDisplayNameGroup() "upName" -> cbSource.text = item.getDisplayNameGroup()
@@ -90,6 +91,7 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
} }
} }
} }
}
override fun registerListener(holder: ItemViewHolder, binding: ItemRssSourceBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemRssSourceBinding) {
binding.apply { binding.apply {