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 32184bf52..1b49a70c1 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 @@ -20,8 +20,8 @@ import io.legado.app.ui.document.HandleFileContract import io.legado.app.ui.login.SourceLoginActivity import io.legado.app.ui.qrcode.QrCodeResult import io.legado.app.ui.rss.source.debug.RssSourceDebugActivity -import io.legado.app.ui.widget.UrlOptionDialog import io.legado.app.ui.widget.dialog.TextDialog +import io.legado.app.ui.widget.dialog.UrlOptionDialog import io.legado.app.ui.widget.keyboard.KeyboardToolPop import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding @@ -254,7 +254,7 @@ class RssSourceEditActivity : override fun onHelpActionSelect(action: String) { when (action) { - "urlOption" -> urlOptionDialogState.value = true + "urlOption" -> UrlOptionDialog(this).show() "ruleHelp" -> showHelp("ruleHelp") "jsHelp" -> showHelp("jsHelp") "regexHelp" -> showHelp("regexHelp") diff --git a/app/src/main/java/io/legado/app/ui/widget/UrlOptionDialog.kt b/app/src/main/java/io/legado/app/ui/widget/dialog/UrlOptionDialog.kt similarity index 86% rename from app/src/main/java/io/legado/app/ui/widget/UrlOptionDialog.kt rename to app/src/main/java/io/legado/app/ui/widget/dialog/UrlOptionDialog.kt index 5b4097e3c..b0753e035 100644 --- a/app/src/main/java/io/legado/app/ui/widget/UrlOptionDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/dialog/UrlOptionDialog.kt @@ -1,9 +1,11 @@ -package io.legado.app.ui.widget +package io.legado.app.ui.widget.dialog +import android.content.Context +import android.os.Bundle +import android.view.ViewGroup +import androidx.appcompat.app.AlertDialog import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.verticalScroll @@ -12,17 +14,37 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.tooling.preview.Preview import io.legado.app.R +import io.legado.app.databinding.DialogUrlOptionEditBinding 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 io.legado.app.utils.setLayout import splitties.init.appCtx +class UrlOptionDialog(context: Context) : AlertDialog(context) { + + val binding = DialogUrlOptionEditBinding.inflate(layoutInflater) + + override fun onStart() { + super.onStart() + setLayout(1f, ViewGroup.LayoutParams.WRAP_CONTENT) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(binding.root) + binding.tvOk.setOnClickListener { + dismiss() + } + } + +} + @Composable fun UrlOptionDialog(openState: MutableState, confirm: (String) -> Unit) { @@ -50,12 +72,7 @@ fun UrlOptionDialog(openState: MutableState, confirm: (String) -> Unit) Text(text = "url参数") }, text = { - Surface( - modifier = Modifier - .fillMaxSize() - .wrapContentSize(align = Alignment.Center), - color = MaterialTheme.colors.background - ) { + Surface() { UrlOptionView(urlOption = urlOption) } } diff --git a/app/src/main/java/io/legado/app/utils/DialogExtensions.kt b/app/src/main/java/io/legado/app/utils/DialogExtensions.kt index 8f2f5346a..941b57088 100644 --- a/app/src/main/java/io/legado/app/utils/DialogExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/DialogExtensions.kt @@ -1,11 +1,13 @@ package io.legado.app.utils +import android.app.Dialog import android.view.WindowManager import androidx.appcompat.app.AlertDialog import androidx.fragment.app.DialogFragment import io.legado.app.lib.theme.Selector import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.filletBackground +import splitties.systemservices.windowManager fun AlertDialog.applyTint(): AlertDialog { window?.setBackgroundDrawable(context.filletBackground) @@ -30,29 +32,45 @@ fun AlertDialog.requestInputMethod() { } fun DialogFragment.setLayout(widthMix: Float, heightMix: Float) { - val dm = requireActivity().windowManager.windowSize - dialog?.window?.setLayout( + dialog?.setLayout(widthMix, heightMix) +} + +fun Dialog.setLayout(widthMix: Float, heightMix: Float) { + val dm = context.windowManager.windowSize + window?.setLayout( (dm.widthPixels * widthMix).toInt(), (dm.heightPixels * heightMix).toInt() ) } fun DialogFragment.setLayout(width: Int, heightMix: Float) { - val dm = requireActivity().windowManager.windowSize - dialog?.window?.setLayout( + dialog?.setLayout(width, heightMix) +} + +fun Dialog.setLayout(width: Int, heightMix: Float) { + val dm = context.windowManager.windowSize + window?.setLayout( width, (dm.heightPixels * heightMix).toInt() ) } fun DialogFragment.setLayout(widthMix: Float, height: Int) { - val dm = requireActivity().windowManager.windowSize - dialog?.window?.setLayout( + dialog?.setLayout(widthMix, height) +} + +fun Dialog.setLayout(widthMix: Float, height: Int) { + val dm = context.windowManager.windowSize + window?.setLayout( (dm.widthPixels * widthMix).toInt(), height ) } fun DialogFragment.setLayout(width: Int, height: Int) { - dialog?.window?.setLayout(width, height) + dialog?.setLayout(width, height) +} + +fun Dialog.setLayout(width: Int, height: Int) { + window?.setLayout(width, height) } \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_url_option_edit.xml b/app/src/main/res/layout/dialog_url_option_edit.xml new file mode 100644 index 000000000..fe806dde4 --- /dev/null +++ b/app/src/main/res/layout/dialog_url_option_edit.xml @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file