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 a20f1a56a..e17328e05 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 @@ -6,10 +6,10 @@ import android.view.Menu import android.view.MenuItem import android.widget.EditText import androidx.activity.viewModels +import androidx.compose.runtime.mutableStateOf import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel import io.legado.app.R import io.legado.app.base.VMBaseActivity -import io.legado.app.constant.AppConst import io.legado.app.data.entities.RssSource import io.legado.app.databinding.ActivityRssSourceEditBinding import io.legado.app.help.config.LocalConfig @@ -20,6 +20,7 @@ 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.keyboard.KeyboardToolPop import io.legado.app.utils.* @@ -31,6 +32,7 @@ class RssSourceEditActivity : override val binding by viewBinding(ActivityRssSourceEditBinding::inflate) override val viewModel by viewModels() + private val urlOptionDialogState = mutableStateOf(false) private val softKeyboardTool by lazy { KeyboardToolPop(this, this, binding.root, this) } @@ -148,13 +150,11 @@ class RssSourceEditActivity : private fun initView() { binding.recyclerView.setEdgeEffectColor(primaryColor) binding.recyclerView.adapter = adapter -// binding.composeView.setContent { -// AppTheme { -// UrlOptionDialog { -// -// } -// } -// } + binding.composeView.setContent { + UrlOptionDialog(openState = urlOptionDialogState) { + + } + } } private fun upRecyclerView(source: RssSource? = viewModel.rssSource) { @@ -254,7 +254,7 @@ class RssSourceEditActivity : override fun onHelpActionSelect(action: String) { when (action) { - "urlOption" -> sendText(AppConst.urlOption) + "urlOption" -> urlOptionDialogState.value = true "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/UrlOptionDialog.kt index 7ef7fa167..d1227cadc 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,27 +1,46 @@ package io.legado.app.ui.widget +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding import androidx.compose.material.AlertDialog 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.ui.theme.AppTheme @Composable -fun UrlOptionDialog(confirm: (String) -> Unit) { - AlertDialog( - onDismissRequest = {}, - confirmButton = { - TextButton(onClick = { - confirm.invoke("") - }) { - Text(text = "OK") - } - }, - dismissButton = { - TextButton(onClick = {}) { Text(text = "Cancel") } - }, - title = { - Text(text = "url参数") +fun UrlOptionDialog(openState: MutableState, confirm: (String) -> Unit) { + AppTheme { + if (openState.value) { + AlertDialog( + onDismissRequest = { + openState.value = false + }, + confirmButton = { + TextButton(onClick = { + confirm.invoke("") + }) { + Text(text = "OK") + } + }, + dismissButton = { + TextButton(onClick = { + openState.value = false + }) { Text(text = "Cancel") } + }, + title = { + Text(text = "url参数") + }, + text = { + Column(Modifier.padding(12.dp)) { + + } + } + ) } - ) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/utils/ConvertExtensions.kt b/app/src/main/java/io/legado/app/utils/ConvertExtensions.kt index 9a7e63722..0453efcd6 100644 --- a/app/src/main/java/io/legado/app/utils/ConvertExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ConvertExtensions.kt @@ -1,3 +1,5 @@ +@file:Suppress("unused") + package io.legado.app.utils import android.content.res.Resources @@ -113,18 +115,21 @@ object ConvertUtils { } val Int.dp: Int - get() = android.util.TypedValue.applyDimension( - android.util.TypedValue.COMPLEX_UNIT_DIP, - this.toFloat(), - Resources.getSystem().displayMetrics - ).toInt() + get() = this.toFloat().dp.toInt() val Int.sp: Int - get() = android.util.TypedValue.applyDimension( - android.util.TypedValue.COMPLEX_UNIT_SP, - this.toFloat(), - Resources.getSystem().displayMetrics - ).toInt() + get() = this.toFloat().sp.toInt() val Int.hexString: String - get() = Integer.toHexString(this) \ No newline at end of file + get() = Integer.toHexString(this) + + +val Float.dp: Float + get() = android.util.TypedValue.applyDimension( + android.util.TypedValue.COMPLEX_UNIT_DIP, this, Resources.getSystem().displayMetrics + ) + +val Float.sp: Float + get() = android.util.TypedValue.applyDimension( + android.util.TypedValue.COMPLEX_UNIT_SP, this, Resources.getSystem().displayMetrics + ) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/utils/FloatExtensions.kt b/app/src/main/java/io/legado/app/utils/FloatExtensions.kt deleted file mode 100644 index ab5178cd6..000000000 --- a/app/src/main/java/io/legado/app/utils/FloatExtensions.kt +++ /dev/null @@ -1,16 +0,0 @@ -@file:Suppress("unused") - -package io.legado.app.utils - -import android.content.res.Resources - -val Float.dp: Float - get() = android.util.TypedValue.applyDimension( - android.util.TypedValue.COMPLEX_UNIT_DIP, this, Resources.getSystem().displayMetrics - ) - -val Float.sp: Float - get() = android.util.TypedValue.applyDimension( - android.util.TypedValue.COMPLEX_UNIT_SP, this, Resources.getSystem().displayMetrics - ) -