优化
This commit is contained in:
@@ -280,6 +280,12 @@ interface BookSourceDao {
|
||||
@get:Query("select max(customOrder) from book_sources")
|
||||
val maxOrder: Int
|
||||
|
||||
@get:Query(
|
||||
"""select exists (select 1
|
||||
from book_sources group by customOrder having count(customOrder) > 1)"""
|
||||
)
|
||||
val hasDuplicateOrder: Boolean
|
||||
|
||||
@Query("update book_sources set enabled = :enable where bookSourceUrl = :bookSourceUrl")
|
||||
fun enable(bookSourceUrl: String, enable: Boolean)
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package io.legado.app.help.source
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.BaseSource
|
||||
import io.legado.app.data.entities.BookSource
|
||||
@@ -14,15 +12,14 @@ import splitties.init.appCtx
|
||||
|
||||
object SourceHelp {
|
||||
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private val list18Plus by lazy {
|
||||
try {
|
||||
return@lazy String(appCtx.assets.open("18PlusList.txt").readBytes())
|
||||
.splitNotBlank("\n").map {
|
||||
EncoderUtils.base64Decode(it)
|
||||
}.toHashSet()
|
||||
} catch (e: Exception) {
|
||||
return@lazy hashSetOf<String>()
|
||||
} catch (_: Exception) {
|
||||
return@lazy emptySet()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +34,7 @@ object SourceHelp {
|
||||
is18Plus(it.sourceUrl)
|
||||
}
|
||||
rssSourcesGroup[true]?.forEach {
|
||||
handler.post {
|
||||
appCtx.toastOnUi("${it.sourceName}是18+网址,禁止导入.")
|
||||
}
|
||||
appCtx.toastOnUi("${it.sourceName}是18+网址,禁止导入.")
|
||||
}
|
||||
rssSourcesGroup[false]?.let {
|
||||
appDb.rssSourceDao.insert(*it.toTypedArray())
|
||||
@@ -51,16 +46,18 @@ object SourceHelp {
|
||||
is18Plus(it.bookSourceUrl)
|
||||
}
|
||||
bookSourcesGroup[true]?.forEach {
|
||||
handler.post {
|
||||
appCtx.toastOnUi("${it.bookSourceName}是18+网址,禁止导入.")
|
||||
}
|
||||
appCtx.toastOnUi("${it.bookSourceName}是18+网址,禁止导入.")
|
||||
}
|
||||
bookSourcesGroup[false]?.let {
|
||||
appDb.bookSourceDao.insert(*it.toTypedArray())
|
||||
}
|
||||
adjustSortNumber()
|
||||
}
|
||||
|
||||
private fun is18Plus(url: String?): Boolean {
|
||||
if (list18Plus.isEmpty()) {
|
||||
return false
|
||||
}
|
||||
url ?: return false
|
||||
val baseUrl = NetworkUtils.getBaseUrl(url) ?: return false
|
||||
kotlin.runCatching {
|
||||
@@ -79,6 +76,7 @@ object SourceHelp {
|
||||
if (
|
||||
appDb.bookSourceDao.maxOrder > 99999
|
||||
|| appDb.bookSourceDao.minOrder < -99999
|
||||
|| appDb.bookSourceDao.hasDuplicateOrder
|
||||
) {
|
||||
val sources = appDb.bookSourceDao.allPart
|
||||
sources.forEachIndexed { index, bookSource ->
|
||||
|
||||
@@ -11,6 +11,7 @@ import io.legado.app.constant.AppLog
|
||||
import io.legado.app.constant.AppPattern
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.BookSource
|
||||
import io.legado.app.data.entities.BookSourcePart
|
||||
import io.legado.app.exception.NoStackTraceException
|
||||
import io.legado.app.help.book.ContentProcessor
|
||||
import io.legado.app.help.config.AppConfig
|
||||
@@ -36,7 +37,7 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
|
||||
val successLiveData = MutableLiveData<Int>()
|
||||
|
||||
val allSources = arrayListOf<BookSource>()
|
||||
val checkSources = arrayListOf<BookSource?>()
|
||||
val checkSources = arrayListOf<BookSourcePart?>()
|
||||
val selectStatus = arrayListOf<Boolean>()
|
||||
val newSourceStatus = arrayListOf<Boolean>()
|
||||
val updateSourceStatus = arrayListOf<Boolean>()
|
||||
@@ -207,7 +208,7 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
|
||||
private fun comparisonSource() {
|
||||
execute {
|
||||
allSources.forEach {
|
||||
val source = appDb.bookSourceDao.getBookSource(it.bookSourceUrl)
|
||||
val source = appDb.bookSourceDao.getBookSourcePart(it.bookSourceUrl)
|
||||
checkSources.add(source)
|
||||
selectStatus.add(source == null || source.lastUpdateTime < it.lastUpdateTime)
|
||||
newSourceStatus.add(source == null)
|
||||
|
||||
Reference in New Issue
Block a user