From 9f474507677b15138a2141d940a99be5406d4980 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 13 Mar 2022 12:06:27 +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 --- .../io/legado/app/help/ContentProcessor.kt | 5 +- .../rss/source/edit/RssSourceEditActivity.kt | 2 +- .../legado/app/ui/widget/UrlOptionDialog.kt | 45 +++++++++++------ .../ui/widget/checkbox/LabelledCheckBox.kt | 48 +++++++++++++++++++ 4 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/widget/checkbox/LabelledCheckBox.kt diff --git a/app/src/main/java/io/legado/app/help/ContentProcessor.kt b/app/src/main/java/io/legado/app/help/ContentProcessor.kt index 429292862..9b1c50472 100644 --- a/app/src/main/java/io/legado/app/help/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/ContentProcessor.kt @@ -107,7 +107,10 @@ class ContentProcessor private constructor( } if (includeTitle) { //重新添加标题 - mContent = chapter.getDisplayTitle(getTitleReplaceRules()) + "\n" + mContent + mContent = chapter.getDisplayTitle( + getTitleReplaceRules(), + useReplace = useReplace && book.getUseReplaceRule() + ) + "\n" + mContent } val contents = arrayListOf() mContent.split("\n").forEach { str -> diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index e17328e05..32184bf52 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -152,7 +152,7 @@ class RssSourceEditActivity : binding.recyclerView.adapter = adapter binding.composeView.setContent { UrlOptionDialog(openState = urlOptionDialogState) { - + sendText(it) } } } 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 e48338de7..21adab806 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 @@ -4,15 +4,20 @@ 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.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp +import io.legado.app.R import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.ui.theme.AppTheme +import io.legado.app.ui.widget.checkbox.LabelledCheckBox +import io.legado.app.utils.GSON +import splitties.init.appCtx @Composable @@ -26,32 +31,44 @@ fun UrlOptionDialog(openState: MutableState, confirm: (String) -> Unit) }, confirmButton = { TextButton(onClick = { - confirm.invoke("") + openState.value = false + confirm.invoke(GSON.toJson(urlOption)) }) { - Text(text = "OK") + Text(text = appCtx.getString(R.string.ok)) } }, dismissButton = { TextButton(onClick = { openState.value = false - }) { Text(text = "Cancel") } + }) { Text(text = appCtx.getString(R.string.cancel)) } }, title = { Text(text = "url参数") }, text = { - Column(Modifier.padding(12.dp)) { - Row(Modifier.padding(3.dp)) { - Checkbox( - checked = urlOption.useWebView(), - onCheckedChange = { - urlOption.webView = it - } - ) - } - } + UrlOptionView(urlOption = urlOption) } ) } } +} + +@Composable +fun UrlOptionView(urlOption: AnalyzeUrl.UrlOption) { + val useWebView = remember { + mutableStateOf(urlOption.useWebView()) + } + urlOption.webView = useWebView.value + Column(Modifier.padding(6.dp)) { + Row(Modifier.padding(3.dp)) { + LabelledCheckBox( + checked = useWebView.value, + onCheckedChange = { + useWebView.value = it + }, + label = "useWebView" + ) + } + + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/checkbox/LabelledCheckBox.kt b/app/src/main/java/io/legado/app/ui/widget/checkbox/LabelledCheckBox.kt new file mode 100644 index 000000000..50ed867b2 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/checkbox/LabelledCheckBox.kt @@ -0,0 +1,48 @@ +package io.legado.app.ui.widget.checkbox + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.* +import androidx.compose.material.ButtonDefaults +import androidx.compose.material.Checkbox +import androidx.compose.material.MaterialTheme +import androidx.compose.material.Text +import androidx.compose.material.ripple.rememberRipple +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.unit.dp + +@Composable +fun LabelledCheckBox( + checked: Boolean, + onCheckedChange: ((Boolean) -> Unit), + label: String, + modifier: Modifier = Modifier +) { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = modifier + .clip(MaterialTheme.shapes.small) + .clickable( + indication = rememberRipple(color = MaterialTheme.colors.primary), + interactionSource = remember { MutableInteractionSource() }, + onClick = { onCheckedChange(!checked) } + ) + .requiredHeight(ButtonDefaults.MinHeight) + .padding(4.dp) + ) { + Checkbox( + checked = checked, + onCheckedChange = null + ) + + Spacer(Modifier.size(6.dp)) + + Text( + text = label, + ) + } +} \ No newline at end of file