优化
This commit is contained in:
@@ -118,6 +118,14 @@ data class BookSource(
|
|||||||
|
|
||||||
fun getContentRule() = ruleContent ?: ContentRule()
|
fun getContentRule() = ruleContent ?: ContentRule()
|
||||||
|
|
||||||
|
fun getDisPlayNameGroup(): String {
|
||||||
|
return if (bookSourceGroup.isNullOrBlank()) {
|
||||||
|
bookSourceName
|
||||||
|
} else {
|
||||||
|
String.format("%s (%s)", bookSourceName, bookSourceGroup)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun addGroup(groups: String): BookSource {
|
fun addGroup(groups: String): BookSource {
|
||||||
bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.toHashSet()?.let {
|
bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.toHashSet()?.let {
|
||||||
it.addAll(groups.splitNotBlank(AppPattern.splitGroupRegex))
|
it.addAll(groups.splitNotBlank(AppPattern.splitGroupRegex))
|
||||||
@@ -137,7 +145,7 @@ data class BookSource(
|
|||||||
|
|
||||||
fun hasGroup(group: String): Boolean {
|
fun hasGroup(group: String): Boolean {
|
||||||
bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.toHashSet()?.let {
|
bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.toHashSet()?.let {
|
||||||
return it.indexOf(group) != -1
|
return it.indexOf(group) != -1
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -148,28 +156,28 @@ data class BookSource(
|
|||||||
|
|
||||||
fun getInvalidGroupNames(): String {
|
fun getInvalidGroupNames(): String {
|
||||||
return bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.toHashSet()?.filter {
|
return bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.toHashSet()?.filter {
|
||||||
"失效" in it
|
"失效" in it
|
||||||
}?.joinToString() ?: ""
|
}?.joinToString() ?: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
fun equal(source: BookSource) =
|
fun equal(source: BookSource) =
|
||||||
equal(bookSourceName, source.bookSourceName)
|
equal(bookSourceName, source.bookSourceName)
|
||||||
&& equal(bookSourceUrl, source.bookSourceUrl)
|
&& equal(bookSourceUrl, source.bookSourceUrl)
|
||||||
&& equal(bookSourceGroup, source.bookSourceGroup)
|
&& equal(bookSourceGroup, source.bookSourceGroup)
|
||||||
&& bookSourceType == source.bookSourceType
|
&& bookSourceType == source.bookSourceType
|
||||||
&& equal(bookUrlPattern, source.bookUrlPattern)
|
&& equal(bookUrlPattern, source.bookUrlPattern)
|
||||||
&& equal(bookSourceComment, source.bookSourceComment)
|
&& equal(bookSourceComment, source.bookSourceComment)
|
||||||
&& enabled == source.enabled
|
&& enabled == source.enabled
|
||||||
&& enabledExplore == source.enabledExplore
|
&& enabledExplore == source.enabledExplore
|
||||||
&& equal(header, source.header)
|
&& equal(header, source.header)
|
||||||
&& loginUrl == source.loginUrl
|
&& loginUrl == source.loginUrl
|
||||||
&& equal(exploreUrl, source.exploreUrl)
|
&& equal(exploreUrl, source.exploreUrl)
|
||||||
&& equal(searchUrl, source.searchUrl)
|
&& equal(searchUrl, source.searchUrl)
|
||||||
&& getSearchRule() == source.getSearchRule()
|
&& getSearchRule() == source.getSearchRule()
|
||||||
&& getExploreRule() == source.getExploreRule()
|
&& getExploreRule() == source.getExploreRule()
|
||||||
&& getBookInfoRule() == source.getBookInfoRule()
|
&& getBookInfoRule() == source.getBookInfoRule()
|
||||||
&& getTocRule() == source.getTocRule()
|
&& getTocRule() == source.getTocRule()
|
||||||
&& getContentRule() == source.getContentRule()
|
&& getContentRule() == source.getContentRule()
|
||||||
|
|
||||||
private fun equal(a: String?, b: String?) = a == b || (a.isNullOrEmpty() && b.isNullOrEmpty())
|
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())
|
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 {
|
fun sortUrls(): List<Pair<String, String>> = arrayListOf<Pair<String, String>>().apply {
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
var a = sortUrl
|
var a = sortUrl
|
||||||
|
|||||||
@@ -51,7 +51,32 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun areContentsTheSame(oldItem: BookSource, newItem: BookSource): Boolean {
|
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
|
val payload = payloads.getOrNull(0) as? Bundle
|
||||||
if (payload == null) {
|
if (payload == null) {
|
||||||
root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f))
|
root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f))
|
||||||
if (item.bookSourceGroup.isNullOrEmpty()) {
|
cbBookSource.text = item.getDisPlayNameGroup()
|
||||||
cbBookSource.text = item.bookSourceName
|
|
||||||
} else {
|
|
||||||
cbBookSource.text =
|
|
||||||
String.format("%s (%s)", item.bookSourceName, item.bookSourceGroup)
|
|
||||||
}
|
|
||||||
swtEnabled.isChecked = item.enabled
|
swtEnabled.isChecked = item.enabled
|
||||||
cbBookSource.isChecked = selected.contains(item)
|
cbBookSource.isChecked = selected.contains(item)
|
||||||
ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: ""
|
ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: ""
|
||||||
@@ -85,6 +105,9 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
|
|||||||
} else {
|
} else {
|
||||||
payload.keySet().map {
|
payload.keySet().map {
|
||||||
when (it) {
|
when (it) {
|
||||||
|
"enabled" -> swtEnabled.isChecked = payload.getBoolean("enabled")
|
||||||
|
"upName" -> cbBookSource.text = item.getDisPlayNameGroup()
|
||||||
|
"upExplore" -> upShowExplore(ivExplore, item)
|
||||||
"selected" -> cbBookSource.isChecked = selected.contains(item)
|
"selected" -> cbBookSource.isChecked = selected.contains(item)
|
||||||
"checkSourceMessage" -> {
|
"checkSourceMessage" -> {
|
||||||
ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: ""
|
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 {
|
override fun areContentsTheSame(oldItem: RssSource, newItem: RssSource): Boolean {
|
||||||
return oldItem.sourceName == newItem.sourceName
|
return oldItem.sourceName == newItem.sourceName
|
||||||
&& oldItem.sourceGroup == newItem.sourceGroup
|
&& oldItem.sourceGroup == newItem.sourceGroup
|
||||||
&& oldItem.enabled == newItem.enabled
|
&& oldItem.enabled == newItem.enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getChangePayload(oldItem: RssSource, newItem: RssSource): Any? {
|
override fun getChangePayload(oldItem: RssSource, newItem: RssSource): Any? {
|
||||||
val payload = Bundle()
|
val payload = Bundle()
|
||||||
if (oldItem.sourceName != newItem.sourceName) {
|
if (oldItem.sourceName != newItem.sourceName
|
||||||
payload.putString("name", newItem.sourceName)
|
|| oldItem.sourceGroup != newItem.sourceGroup
|
||||||
}
|
) {
|
||||||
if (oldItem.sourceGroup != newItem.sourceGroup) {
|
payload.putBoolean("upName", true)
|
||||||
payload.putString("group", newItem.sourceGroup)
|
|
||||||
}
|
|
||||||
if (oldItem.enabled != newItem.enabled) {
|
|
||||||
payload.putBoolean("enabled", newItem.enabled)
|
|
||||||
}
|
|
||||||
if (payload.isEmpty) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
return payload
|
|
||||||
}
|
}
|
||||||
|
if (oldItem.enabled != newItem.enabled) {
|
||||||
|
payload.putBoolean("enabled", newItem.enabled)
|
||||||
|
}
|
||||||
|
if (payload.isEmpty) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return payload
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun getViewBinding(parent: ViewGroup): ItemRssSourceBinding {
|
override fun getViewBinding(parent: ViewGroup): ItemRssSourceBinding {
|
||||||
return ItemRssSourceBinding.inflate(inflater, parent, false)
|
return ItemRssSourceBinding.inflate(inflater, parent, false)
|
||||||
@@ -80,17 +79,14 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
|
|||||||
val bundle = payloads.getOrNull(0) as? Bundle
|
val bundle = payloads.getOrNull(0) as? Bundle
|
||||||
if (bundle == null) {
|
if (bundle == null) {
|
||||||
root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f))
|
root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f))
|
||||||
if (item.sourceGroup.isNullOrEmpty()) {
|
cbSource.text = item.getDisplayNameGroup()
|
||||||
cbSource.text = item.sourceName
|
|
||||||
} else {
|
|
||||||
cbSource.text =
|
|
||||||
String.format("%s (%s)", item.sourceName, item.sourceGroup)
|
|
||||||
}
|
|
||||||
swtEnabled.isChecked = item.enabled
|
swtEnabled.isChecked = item.enabled
|
||||||
cbSource.isChecked = selected.contains(item)
|
cbSource.isChecked = selected.contains(item)
|
||||||
} else {
|
} else {
|
||||||
bundle.keySet().map {
|
bundle.keySet().map {
|
||||||
when (it) {
|
when (it) {
|
||||||
|
"upName" -> cbSource.text = item.getDisplayNameGroup()
|
||||||
|
"enabled" -> swtEnabled.isChecked = bundle.getBoolean("enabled")
|
||||||
"selected" -> cbSource.isChecked = selected.contains(item)
|
"selected" -> cbSource.isChecked = selected.contains(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user