|
|
@@ -9,10 +9,12 @@ import android.webkit.WebView
|
|
|
import androidx.documentfile.provider.DocumentFile
|
|
|
import io.legado.app.base.BaseViewModel
|
|
|
import io.legado.app.constant.AppConst
|
|
|
+import io.legado.app.constant.SourceType
|
|
|
import io.legado.app.data.appDb
|
|
|
import io.legado.app.exception.NoStackTraceException
|
|
|
import io.legado.app.help.http.newCallResponseBody
|
|
|
import io.legado.app.help.http.okHttpClient
|
|
|
+import io.legado.app.help.source.SourceHelp
|
|
|
import io.legado.app.help.source.SourceVerificationHelp
|
|
|
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
|
|
import io.legado.app.utils.DocumentUtils
|
|
|
@@ -34,6 +36,7 @@ class WebViewModel(application: Application) : BaseViewModel(application) {
|
|
|
var refetchAfterSuccess: Boolean = true
|
|
|
var sourceName: String = ""
|
|
|
var sourceOrigin: String = ""
|
|
|
+ var sourceType = SourceType.book
|
|
|
|
|
|
fun initData(
|
|
|
intent: Intent,
|
|
|
@@ -45,9 +48,10 @@ class WebViewModel(application: Application) : BaseViewModel(application) {
|
|
|
?: throw NoStackTraceException("url不能为空")
|
|
|
sourceName = intent.getStringExtra("sourceName") ?: ""
|
|
|
sourceOrigin = intent.getStringExtra("sourceOrigin") ?: ""
|
|
|
+ sourceType = intent.getIntExtra("sourceType", SourceType.book)
|
|
|
sourceVerificationEnable = intent.getBooleanExtra("sourceVerificationEnable", false)
|
|
|
refetchAfterSuccess = intent.getBooleanExtra("refetchAfterSuccess", true)
|
|
|
- val source = appDb.bookSourceDao.getBookSource(sourceOrigin)
|
|
|
+ val source = SourceHelp.getSource(sourceOrigin, sourceType)
|
|
|
val analyzeUrl = AnalyzeUrl(url, source = source, coroutineContext = coroutineContext)
|
|
|
baseUrl = analyzeUrl.url
|
|
|
headerMap.putAll(analyzeUrl.headerMap)
|
|
|
@@ -127,7 +131,7 @@ class WebViewModel(application: Application) : BaseViewModel(application) {
|
|
|
|
|
|
fun disableSource(block: () -> Unit) {
|
|
|
execute {
|
|
|
- appDb.bookSourceDao.enable(sourceOrigin, false)
|
|
|
+ SourceHelp.enableSource(sourceOrigin, sourceType, false)
|
|
|
}.onSuccess {
|
|
|
block.invoke()
|
|
|
}
|
|
|
@@ -135,7 +139,7 @@ class WebViewModel(application: Application) : BaseViewModel(application) {
|
|
|
|
|
|
fun deleteSource(block: () -> Unit) {
|
|
|
execute {
|
|
|
- appDb.bookSourceDao.delete(sourceOrigin)
|
|
|
+ SourceHelp.deleteSource(sourceOrigin, sourceType)
|
|
|
}.onSuccess {
|
|
|
block.invoke()
|
|
|
}
|