|
|
|
@ -1,22 +1,47 @@ |
|
|
|
|
package io.legado.app.ui.web |
|
|
|
|
|
|
|
|
|
import android.app.Application |
|
|
|
|
import android.content.Intent |
|
|
|
|
import android.net.Uri |
|
|
|
|
import android.util.Base64 |
|
|
|
|
import android.webkit.URLUtil |
|
|
|
|
import androidx.documentfile.provider.DocumentFile |
|
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
|
import io.legado.app.constant.AppConst |
|
|
|
|
import io.legado.app.help.IntentData |
|
|
|
|
import io.legado.app.help.http.newCall |
|
|
|
|
import io.legado.app.help.http.okHttpClient |
|
|
|
|
import io.legado.app.model.NoStackTraceException |
|
|
|
|
import io.legado.app.model.analyzeRule.AnalyzeUrl |
|
|
|
|
import io.legado.app.utils.* |
|
|
|
|
import java.io.File |
|
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
class WebViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
var baseUrl: String = "" |
|
|
|
|
var html: String? = null |
|
|
|
|
val headerMap: HashMap<String, String> = hashMapOf() |
|
|
|
|
|
|
|
|
|
fun initData(url: String, header: Map<String, String>?) { |
|
|
|
|
|
|
|
|
|
fun initData( |
|
|
|
|
intent: Intent, |
|
|
|
|
success: () -> Unit |
|
|
|
|
) { |
|
|
|
|
execute { |
|
|
|
|
val url = intent.getStringExtra("url") |
|
|
|
|
?: throw NoStackTraceException("url不能为空") |
|
|
|
|
val headerMapF = IntentData.get<Map<String, String>>(url) |
|
|
|
|
val analyzeUrl = AnalyzeUrl(url, headerMapF = headerMapF) |
|
|
|
|
baseUrl = analyzeUrl.url |
|
|
|
|
headerMap.putAll(analyzeUrl.headerMap) |
|
|
|
|
if (analyzeUrl.isPost()) { |
|
|
|
|
html = analyzeUrl.getStrResponse(useWebView = false).body |
|
|
|
|
} |
|
|
|
|
}.onSuccess { |
|
|
|
|
success.invoke() |
|
|
|
|
}.onError { |
|
|
|
|
context.toastOnUi("error\n${it.localizedMessage}") |
|
|
|
|
it.printOnDebug() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun saveImage(webPic: String?, path: String) { |
|
|
|
|