From 347d6a1eccc405f88023303e5986446efbab31e1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 13 Mar 2022 11:04:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BE=93=E5=85=A5url=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/model/analyzeRule/AnalyzeUrl.kt | 31 ++++++++++++------- .../legado/app/ui/widget/UrlOptionDialog.kt | 13 +++++++- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index 16ac7017a..b30a42b80 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -188,7 +188,7 @@ class AnalyzeUrl( type = option.type charset = option.charset retry = option.retry - useWebView = option.webView?.toString()?.isNotBlank() == true + useWebView = option.useWebView() webJs = option.webJs option.js?.let { jsStr -> evalJS(jsStr, url)?.toString()?.let { @@ -561,16 +561,25 @@ class AnalyzeUrl( } data class UrlOption( - val method: String?, - val charset: String?, - val headers: Any?, - val body: Any?, - val type: String?, - val js: String?, - val retry: Int = 0, - val webView: Any?, - val webJs: String?, - ) + var method: String? = null, + var charset: String? = null, + var headers: Any? = null, + var body: Any? = null, + var type: String? = null, + var js: String? = null, + var retry: Int = 0, + var webView: Any? = null, + var webJs: String? = null, + ) { + + fun useWebView(): Boolean { + return when (webView) { + null, "", false, "false" -> false + else -> true + } + } + + } data class ConcurrentRecord( val concurrent: Boolean, diff --git a/app/src/main/java/io/legado/app/ui/widget/UrlOptionDialog.kt b/app/src/main/java/io/legado/app/ui/widget/UrlOptionDialog.kt index d1227cadc..e48338de7 100644 --- a/app/src/main/java/io/legado/app/ui/widget/UrlOptionDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/UrlOptionDialog.kt @@ -1,14 +1,17 @@ package io.legado.app.ui.widget import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.padding import androidx.compose.material.AlertDialog +import androidx.compose.material.Checkbox import androidx.compose.material.Text import androidx.compose.material.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp +import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.ui.theme.AppTheme @@ -16,6 +19,7 @@ import io.legado.app.ui.theme.AppTheme fun UrlOptionDialog(openState: MutableState, confirm: (String) -> Unit) { AppTheme { if (openState.value) { + val urlOption = AnalyzeUrl.UrlOption() AlertDialog( onDismissRequest = { openState.value = false @@ -37,7 +41,14 @@ fun UrlOptionDialog(openState: MutableState, confirm: (String) -> Unit) }, text = { Column(Modifier.padding(12.dp)) { - + Row(Modifier.padding(3.dp)) { + Checkbox( + checked = urlOption.useWebView(), + onCheckedChange = { + urlOption.webView = it + } + ) + } } } )