pull/1625/head
kunfei 3 years ago
parent 93d9e6009b
commit dc4d6734a4
  1. 8
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  2. 8
      app/src/main/java/io/legado/app/data/entities/RssSource.kt
  3. 37
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  4. 18
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt

@ -118,6 +118,14 @@ data class BookSource(
fun getContentRule() = ruleContent ?: ContentRule()
fun getDisPlayNameGroup(): String {
return if (bookSourceGroup.isNullOrBlank()) {
bookSourceName
} else {
String.format("%s (%s)", bookSourceName, bookSourceGroup)
}
}
fun addGroup(groups: String): BookSource {
bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.toHashSet()?.let {
it.addAll(groups.splitNotBlank(AppPattern.splitGroupRegex))

@ -85,6 +85,14 @@ data class RssSource(
return a == b || (a.isNullOrEmpty() && b.isNullOrEmpty())
}
fun getDisplayNameGroup(): String {
return if (sourceGroup.isNullOrBlank()) {
sourceName
} else {
String.format("%s (%s)", sourceName, sourceGroup)
}
}
fun sortUrls(): List<Pair<String, String>> = arrayListOf<Pair<String, String>>().apply {
kotlin.runCatching {
var a = sortUrl

@ -51,7 +51,32 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
}
override fun areContentsTheSame(oldItem: BookSource, newItem: BookSource): Boolean {
return false
return oldItem.bookSourceName == newItem.bookSourceName
&& oldItem.bookSourceGroup == newItem.bookSourceGroup
&& oldItem.enabled == newItem.enabled
&& oldItem.enabledExplore == newItem.enabledExplore
&& oldItem.exploreUrl == newItem.exploreUrl
}
override fun getChangePayload(oldItem: BookSource, newItem: BookSource): Any? {
val payload = Bundle()
if (oldItem.bookSourceName != newItem.bookSourceName
|| oldItem.bookSourceGroup != newItem.bookSourceGroup
) {
payload.putBoolean("upName", true)
}
if (oldItem.enabled != newItem.enabled) {
payload.putBoolean("enabled", newItem.enabled)
}
if (oldItem.enabledExplore != newItem.enabledExplore ||
oldItem.exploreUrl != newItem.exploreUrl
) {
payload.putBoolean("upExplore", true)
}
if (payload.isEmpty) {
return null
}
return payload
}
}
@ -70,12 +95,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
val payload = payloads.getOrNull(0) as? Bundle
if (payload == null) {
root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f))
if (item.bookSourceGroup.isNullOrEmpty()) {
cbBookSource.text = item.bookSourceName
} else {
cbBookSource.text =
String.format("%s (%s)", item.bookSourceName, item.bookSourceGroup)
}
cbBookSource.text = item.getDisPlayNameGroup()
swtEnabled.isChecked = item.enabled
cbBookSource.isChecked = selected.contains(item)
ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: ""
@ -85,6 +105,9 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
} else {
payload.keySet().map {
when (it) {
"enabled" -> swtEnabled.isChecked = payload.getBoolean("enabled")
"upName" -> cbBookSource.text = item.getDisPlayNameGroup()
"upExplore" -> upShowExplore(ivExplore, item)
"selected" -> cbBookSource.isChecked = selected.contains(item)
"checkSourceMessage" -> {
ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: ""

@ -50,11 +50,10 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
override fun getChangePayload(oldItem: RssSource, newItem: RssSource): Any? {
val payload = Bundle()
if (oldItem.sourceName != newItem.sourceName) {
payload.putString("name", newItem.sourceName)
}
if (oldItem.sourceGroup != newItem.sourceGroup) {
payload.putString("group", newItem.sourceGroup)
if (oldItem.sourceName != newItem.sourceName
|| oldItem.sourceGroup != newItem.sourceGroup
) {
payload.putBoolean("upName", true)
}
if (oldItem.enabled != newItem.enabled) {
payload.putBoolean("enabled", newItem.enabled)
@ -80,17 +79,14 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
val bundle = payloads.getOrNull(0) as? Bundle
if (bundle == null) {
root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f))
if (item.sourceGroup.isNullOrEmpty()) {
cbSource.text = item.sourceName
} else {
cbSource.text =
String.format("%s (%s)", item.sourceName, item.sourceGroup)
}
cbSource.text = item.getDisplayNameGroup()
swtEnabled.isChecked = item.enabled
cbSource.isChecked = selected.contains(item)
} else {
bundle.keySet().map {
when (it) {
"upName" -> cbSource.text = item.getDisplayNameGroup()
"enabled" -> swtEnabled.isChecked = bundle.getBoolean("enabled")
"selected" -> cbSource.isChecked = selected.contains(item)
}
}

Loading…
Cancel
Save