pull/282/head
gedoor 4 years ago
parent 8737c89780
commit 65e926c7de
  1. 13
      app/src/main/java/io/legado/app/help/SourceHelp.kt
  2. 7
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt

@ -3,6 +3,7 @@ package io.legado.app.help
import android.os.Handler
import android.os.Looper
import io.legado.app.App
import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.RssSource
import io.legado.app.utils.EncoderUtils
import io.legado.app.utils.NetworkUtils
@ -33,6 +34,18 @@ object SourceHelp {
}
}
fun insertBookSource(vararg bookSources: BookSource) {
bookSources.forEach { bookSource ->
if (is18Plus(bookSource.bookSourceUrl)) {
handler.post {
App.INSTANCE.toast("${bookSource.bookSourceName}是18+网址,禁止导入.")
}
} else {
App.db.bookSourceDao().insert(bookSource)
}
}
}
private fun is18Plus(url: String?): Boolean {
url ?: return false
if (AppConfig.isGooglePlay) return false

@ -8,6 +8,7 @@ import com.jayway.jsonpath.JsonPath
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.BookSource
import io.legado.app.help.SourceHelp
import io.legado.app.help.http.HttpHelper
import io.legado.app.help.storage.OldRule
import io.legado.app.help.storage.Restore.jsonPath
@ -205,7 +206,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
}
} else {
OldRule.jsonToBookSource(text1)?.let {
App.db.bookSourceDao().insert(it)
SourceHelp.insertBookSource(it)
count = 1
}
}
@ -220,7 +221,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
bookSources.add(it)
}
}
App.db.bookSourceDao().insert(*bookSources.toTypedArray())
SourceHelp.insertBookSource(*bookSources.toTypedArray())
"导入${bookSources.size}"
}
text1.isAbsUrl() -> {
@ -251,7 +252,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
bookSources.add(source)
}
}
App.db.bookSourceDao().insert(*bookSources.toTypedArray())
SourceHelp.insertBookSource(*bookSources.toTypedArray())
return bookSources.size
}
}

Loading…
Cancel
Save