From 23b8390fef6093c0de246fa338943039adfd3682 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 13 Mar 2022 21:38:22 +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 | 22 +++---- .../legado/app/ui/widget/UrlOptionDialog.kt | 57 ++++++++++++++++--- 2 files changed, 61 insertions(+), 18 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 b839c7913..575e1957d 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 @@ -172,7 +172,7 @@ class AnalyzeUrl( option.getMethod()?.let { if (it.equals("POST", true)) method = RequestMethod.POST } - option.getHeaders()?.forEach { entry -> + option.getHeaderMap()?.forEach { entry -> headerMap[entry.key.toString()] = entry.value.toString() } option.getBody()?.let { @@ -558,8 +558,8 @@ class AnalyzeUrl( private var charset: String? = null, private var headers: Any? = null, private var body: Any? = null, - private var type: String? = null, private var retry: Int? = null, + private var type: String? = null, private var webView: Any? = null, private var webJs: String? = null, private var js: String? = null, @@ -580,20 +580,20 @@ class AnalyzeUrl( return charset } - fun setType(value: String?) { - type = if (value.isNullOrBlank()) null else value + fun setRetry(value: String?) { + retry = if (value.isNullOrEmpty()) null else value.toIntOrNull() } - fun getType(): String? { - return type + fun getRetry(): Int { + return retry ?: 0 } - fun setRetry(value: Int?) { - retry = if (value == null || value <= 0) null else value + fun setType(value: String?) { + type = if (value.isNullOrBlank()) null else value } - fun getRetry(): Int { - return retry ?: 0 + fun getType(): String? { + return type } fun useWebView(): Boolean { @@ -615,7 +615,7 @@ class AnalyzeUrl( } } - fun getHeaders(): Map<*, *>? { + fun getHeaderMap(): Map<*, *>? { return when (val value = headers) { is Map<*, *> -> value is String -> GSON.fromJsonObject>(value).getOrNull() 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 4d94f331a..1e991dae8 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 @@ -2,7 +2,7 @@ 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.foundation.text.KeyboardOptions import androidx.compose.material.AlertDialog import androidx.compose.material.Text import androidx.compose.material.TextButton @@ -11,8 +11,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember -import androidx.compose.ui.Modifier -import androidx.compose.ui.unit.dp +import androidx.compose.ui.text.input.KeyboardType import io.legado.app.R import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.ui.theme.AppTheme @@ -61,11 +60,27 @@ fun UrlOptionView(urlOption: AnalyzeUrl.UrlOption) { } urlOption.useWebView(useWebView.value) val method = remember { - mutableStateOf(urlOption.getMethod() ?: "") + mutableStateOf("") } urlOption.setMethod(method.value) - Column(Modifier.padding(6.dp)) { - Row(Modifier.padding(3.dp)) { + val charset = remember { + mutableStateOf("") + } + urlOption.setCharset(charset.value) + val headers = remember { + mutableStateOf("") + } + urlOption.setHeaders(headers.value) + val body = remember { + mutableStateOf("") + } + urlOption.setBody(body.value) + val retry = remember { + mutableStateOf("") + } + urlOption.setRetry(retry.value) + Column { + Row { LabelledCheckBox( checked = useWebView.value, onCheckedChange = { @@ -80,8 +95,36 @@ fun UrlOptionView(urlOption: AnalyzeUrl.UrlOption) { method.value = it }, label = { - Text(text = "Method") + Text(text = "method") + } + ) + TextField( + value = method.value, + onValueChange = { + charset.value = it + }, + label = { + Text(text = "charset") } ) + TextField( + value = headers.value, + onValueChange = { + charset.value = it + }, + label = { + Text(text = "headers") + } + ) + TextField( + value = retry.value, + onValueChange = { + retry.value = it + }, + label = { + Text(text = "retry") + }, + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number) + ) } } \ No newline at end of file