|
|
@@ -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 ->
|