pull/1625/head
kunfei 3 years ago
parent 93d9e6009b
commit dc4d6734a4
  1. 44
      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. 42
      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))
@ -137,7 +145,7 @@ data class BookSource(
fun hasGroup(group: String): Boolean {
bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.toHashSet()?.let {
return it.indexOf(group) != -1
return it.indexOf(group) != -1
}
return false
}
@ -148,28 +156,28 @@ data class BookSource(
fun getInvalidGroupNames(): String {
return bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.toHashSet()?.filter {
"失效" in it
"失效" in it
}?.joinToString() ?: ""
}
fun equal(source: BookSource) =
equal(bookSourceName, source.bookSourceName)
&& equal(bookSourceUrl, source.bookSourceUrl)
&& equal(bookSourceGroup, source.bookSourceGroup)
&& bookSourceType == source.bookSourceType
&& equal(bookUrlPattern, source.bookUrlPattern)
&& equal(bookSourceComment, source.bookSourceComment)
&& enabled == source.enabled
&& enabledExplore == source.enabledExplore
&& equal(header, source.header)
&& loginUrl == source.loginUrl
&& equal(exploreUrl, source.exploreUrl)
&& equal(searchUrl, source.searchUrl)
&& getSearchRule() == source.getSearchRule()
&& getExploreRule() == source.getExploreRule()
&& getBookInfoRule() == source.getBookInfoRule()
&& getTocRule() == source.getTocRule()
&& getContentRule() == source.getContentRule()
&& equal(bookSourceUrl, source.bookSourceUrl)
&& equal(bookSourceGroup, source.bookSourceGroup)
&& bookSourceType == source.bookSourceType
&& equal(bookUrlPattern, source.bookUrlPattern)
&& equal(bookSourceComment, source.bookSourceComment)
&& enabled == source.enabled
&& enabledExplore == source.enabledExplore
&& equal(header, source.header)
&& loginUrl == source.loginUrl
&& equal(exploreUrl, source.exploreUrl)
&& equal(searchUrl, source.searchUrl)
&& getSearchRule() == source.getSearchRule()
&& getExploreRule() == source.getExploreRule()
&& getBookInfoRule() == source.getBookInfoRule()
&& getTocRule() == source.getTocRule()
&& getContentRule() == source.getContentRule()
private fun equal(a: String?, b: String?) = a == b || (a.isNullOrEmpty() && b.isNullOrEmpty())

@ -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] ?: ""

@ -44,27 +44,26 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
override fun areContentsTheSame(oldItem: RssSource, newItem: RssSource): Boolean {
return oldItem.sourceName == newItem.sourceName
&& oldItem.sourceGroup == newItem.sourceGroup
&& oldItem.enabled == newItem.enabled
&& oldItem.sourceGroup == newItem.sourceGroup
&& oldItem.enabled == newItem.enabled
}
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.enabled != newItem.enabled) {
payload.putBoolean("enabled", newItem.enabled)
}
if (payload.isEmpty) {
return null
}
return payload
override fun getChangePayload(oldItem: RssSource, newItem: RssSource): Any? {
val payload = Bundle()
if (oldItem.sourceName != newItem.sourceName
|| oldItem.sourceGroup != newItem.sourceGroup
) {
payload.putBoolean("upName", true)
}
if (oldItem.enabled != newItem.enabled) {
payload.putBoolean("enabled", newItem.enabled)
}
if (payload.isEmpty) {
return null
}
return payload
}
}
override fun getViewBinding(parent: ViewGroup): ItemRssSourceBinding {
return ItemRssSourceBinding.inflate(inflater, parent, false)
@ -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