输入url参数对话框

pull/1705/head
kunfei 3 years ago
parent 5c4d041007
commit 23b8390fef
  1. 22
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  2. 57
      app/src/main/java/io/legado/app/ui/widget/UrlOptionDialog.kt

@ -172,7 +172,7 @@ class AnalyzeUrl(
option.getMethod()?.let { option.getMethod()?.let {
if (it.equals("POST", true)) method = RequestMethod.POST if (it.equals("POST", true)) method = RequestMethod.POST
} }
option.getHeaders()?.forEach { entry -> option.getHeaderMap()?.forEach { entry ->
headerMap[entry.key.toString()] = entry.value.toString() headerMap[entry.key.toString()] = entry.value.toString()
} }
option.getBody()?.let { option.getBody()?.let {
@ -558,8 +558,8 @@ class AnalyzeUrl(
private var charset: String? = null, private var charset: String? = null,
private var headers: Any? = null, private var headers: Any? = null,
private var body: Any? = null, private var body: Any? = null,
private var type: String? = null,
private var retry: Int? = null, private var retry: Int? = null,
private var type: String? = null,
private var webView: Any? = null, private var webView: Any? = null,
private var webJs: String? = null, private var webJs: String? = null,
private var js: String? = null, private var js: String? = null,
@ -580,20 +580,20 @@ class AnalyzeUrl(
return charset return charset
} }
fun setType(value: String?) { fun setRetry(value: String?) {
type = if (value.isNullOrBlank()) null else value retry = if (value.isNullOrEmpty()) null else value.toIntOrNull()
} }
fun getType(): String? { fun getRetry(): Int {
return type return retry ?: 0
} }
fun setRetry(value: Int?) { fun setType(value: String?) {
retry = if (value == null || value <= 0) null else value type = if (value.isNullOrBlank()) null else value
} }
fun getRetry(): Int { fun getType(): String? {
return retry ?: 0 return type
} }
fun useWebView(): Boolean { fun useWebView(): Boolean {
@ -615,7 +615,7 @@ class AnalyzeUrl(
} }
} }
fun getHeaders(): Map<*, *>? { fun getHeaderMap(): Map<*, *>? {
return when (val value = headers) { return when (val value = headers) {
is Map<*, *> -> value is Map<*, *> -> value
is String -> GSON.fromJsonObject<Map<String, Any>>(value).getOrNull() is String -> GSON.fromJsonObject<Map<String, Any>>(value).getOrNull()

@ -2,7 +2,7 @@ package io.legado.app.ui.widget
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row 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.AlertDialog
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.material.TextButton import androidx.compose.material.TextButton
@ -11,8 +11,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import io.legado.app.R import io.legado.app.R
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.ui.theme.AppTheme import io.legado.app.ui.theme.AppTheme
@ -61,11 +60,27 @@ fun UrlOptionView(urlOption: AnalyzeUrl.UrlOption) {
} }
urlOption.useWebView(useWebView.value) urlOption.useWebView(useWebView.value)
val method = remember { val method = remember {
mutableStateOf(urlOption.getMethod() ?: "") mutableStateOf("")
} }
urlOption.setMethod(method.value) urlOption.setMethod(method.value)
Column(Modifier.padding(6.dp)) { val charset = remember {
Row(Modifier.padding(3.dp)) { 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( LabelledCheckBox(
checked = useWebView.value, checked = useWebView.value,
onCheckedChange = { onCheckedChange = {
@ -80,8 +95,36 @@ fun UrlOptionView(urlOption: AnalyzeUrl.UrlOption) {
method.value = it method.value = it
}, },
label = { 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)
)
} }
} }
Loading…
Cancel
Save