pull/1705/head
kunfei 3 years ago
parent 64d0e60cf9
commit 54e311ac81
  1. 18
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  2. 25
      app/src/main/java/io/legado/app/ui/widget/UrlOptionDialog.kt
  3. 25
      app/src/main/java/io/legado/app/utils/ConvertExtensions.kt
  4. 16
      app/src/main/java/io/legado/app/utils/FloatExtensions.kt

@ -6,10 +6,10 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.widget.EditText import android.widget.EditText
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.compose.runtime.mutableStateOf
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.databinding.ActivityRssSourceEditBinding import io.legado.app.databinding.ActivityRssSourceEditBinding
import io.legado.app.help.config.LocalConfig 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.login.SourceLoginActivity
import io.legado.app.ui.qrcode.QrCodeResult import io.legado.app.ui.qrcode.QrCodeResult
import io.legado.app.ui.rss.source.debug.RssSourceDebugActivity 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.TextDialog
import io.legado.app.ui.widget.keyboard.KeyboardToolPop import io.legado.app.ui.widget.keyboard.KeyboardToolPop
import io.legado.app.utils.* import io.legado.app.utils.*
@ -31,6 +32,7 @@ class RssSourceEditActivity :
override val binding by viewBinding(ActivityRssSourceEditBinding::inflate) override val binding by viewBinding(ActivityRssSourceEditBinding::inflate)
override val viewModel by viewModels<RssSourceEditViewModel>() override val viewModel by viewModels<RssSourceEditViewModel>()
private val urlOptionDialogState = mutableStateOf(false)
private val softKeyboardTool by lazy { private val softKeyboardTool by lazy {
KeyboardToolPop(this, this, binding.root, this) KeyboardToolPop(this, this, binding.root, this)
} }
@ -148,13 +150,11 @@ class RssSourceEditActivity :
private fun initView() { private fun initView() {
binding.recyclerView.setEdgeEffectColor(primaryColor) binding.recyclerView.setEdgeEffectColor(primaryColor)
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
// binding.composeView.setContent { binding.composeView.setContent {
// AppTheme { UrlOptionDialog(openState = urlOptionDialogState) {
// UrlOptionDialog {
// }
// } }
// }
// }
} }
private fun upRecyclerView(source: RssSource? = viewModel.rssSource) { private fun upRecyclerView(source: RssSource? = viewModel.rssSource) {
@ -254,7 +254,7 @@ class RssSourceEditActivity :
override fun onHelpActionSelect(action: String) { override fun onHelpActionSelect(action: String) {
when (action) { when (action) {
"urlOption" -> sendText(AppConst.urlOption) "urlOption" -> urlOptionDialogState.value = true
"ruleHelp" -> showHelp("ruleHelp") "ruleHelp" -> showHelp("ruleHelp")
"jsHelp" -> showHelp("jsHelp") "jsHelp" -> showHelp("jsHelp")
"regexHelp" -> showHelp("regexHelp") "regexHelp" -> showHelp("regexHelp")

@ -1,15 +1,25 @@
package io.legado.app.ui.widget 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.AlertDialog
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.material.TextButton import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable 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 @Composable
fun UrlOptionDialog(confirm: (String) -> Unit) { fun UrlOptionDialog(openState: MutableState<Boolean>, confirm: (String) -> Unit) {
AppTheme {
if (openState.value) {
AlertDialog( AlertDialog(
onDismissRequest = {}, onDismissRequest = {
openState.value = false
},
confirmButton = { confirmButton = {
TextButton(onClick = { TextButton(onClick = {
confirm.invoke("") confirm.invoke("")
@ -18,10 +28,19 @@ fun UrlOptionDialog(confirm: (String) -> Unit) {
} }
}, },
dismissButton = { dismissButton = {
TextButton(onClick = {}) { Text(text = "Cancel") } TextButton(onClick = {
openState.value = false
}) { Text(text = "Cancel") }
}, },
title = { title = {
Text(text = "url参数") Text(text = "url参数")
},
text = {
Column(Modifier.padding(12.dp)) {
}
} }
) )
} }
}
}

@ -1,3 +1,5 @@
@file:Suppress("unused")
package io.legado.app.utils package io.legado.app.utils
import android.content.res.Resources import android.content.res.Resources
@ -113,18 +115,21 @@ object ConvertUtils {
} }
val Int.dp: Int val Int.dp: Int
get() = android.util.TypedValue.applyDimension( get() = this.toFloat().dp.toInt()
android.util.TypedValue.COMPLEX_UNIT_DIP,
this.toFloat(),
Resources.getSystem().displayMetrics
).toInt()
val Int.sp: Int val Int.sp: Int
get() = android.util.TypedValue.applyDimension( get() = this.toFloat().sp.toInt()
android.util.TypedValue.COMPLEX_UNIT_SP,
this.toFloat(),
Resources.getSystem().displayMetrics
).toInt()
val Int.hexString: String val Int.hexString: String
get() = Integer.toHexString(this) 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
)

@ -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
)
Loading…
Cancel
Save