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