自动隐藏键盘
This commit is contained in:
@@ -44,6 +44,7 @@ import io.legado.app.ui.book.toc.TocActivityResult
|
||||
import io.legado.app.ui.document.HandleFileContract
|
||||
import io.legado.app.ui.login.SourceLoginActivity
|
||||
import io.legado.app.ui.widget.dialog.PhotoDialog
|
||||
import io.legado.app.ui.widget.dialog.VariableDialog
|
||||
import io.legado.app.ui.widget.dialog.WaitDialog
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
@@ -419,22 +420,8 @@ class BookInfoActivity :
|
||||
toastOnUi("书源不存在")
|
||||
return@launch
|
||||
}
|
||||
val variable = withContext(IO) { source.getVariable() }
|
||||
alert(R.string.set_source_variable) {
|
||||
setMessage(source.getDisplayVariableComment("源变量可在js中通过source.getVariable()获取"))
|
||||
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
|
||||
editView.hint = "source variable"
|
||||
editView.setText(variable)
|
||||
}
|
||||
customView { alertBinding.root }
|
||||
okButton {
|
||||
viewModel.bookSource?.setVariable(alertBinding.editView.text?.toString())
|
||||
}
|
||||
cancelButton()
|
||||
neutralButton(R.string.delete) {
|
||||
viewModel.bookSource?.setVariable(null)
|
||||
}
|
||||
}
|
||||
val comment = source.getDisplayVariableComment("源变量可在js中通过source.getVariable()获取")
|
||||
showDialogFragment(VariableDialog(source.getKey(), comment))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.BookSource
|
||||
import io.legado.app.data.entities.rule.*
|
||||
import io.legado.app.databinding.ActivityBookSourceEditBinding
|
||||
import io.legado.app.databinding.DialogEditTextBinding
|
||||
import io.legado.app.help.config.LocalConfig
|
||||
import io.legado.app.lib.dialogs.SelectItem
|
||||
import io.legado.app.lib.dialogs.alert
|
||||
@@ -31,6 +30,7 @@ import io.legado.app.ui.login.SourceLoginActivity
|
||||
import io.legado.app.ui.qrcode.QrCodeResult
|
||||
import io.legado.app.ui.widget.dialog.TextDialog
|
||||
import io.legado.app.ui.widget.dialog.UrlOptionDialog
|
||||
import io.legado.app.ui.widget.dialog.VariableDialog
|
||||
import io.legado.app.ui.widget.keyboard.KeyboardToolPop
|
||||
import io.legado.app.ui.widget.text.EditEntity
|
||||
import io.legado.app.utils.*
|
||||
@@ -593,29 +593,13 @@ class BookSourceEditActivity :
|
||||
}
|
||||
|
||||
private fun setSourceVariable() {
|
||||
launch {
|
||||
val source = viewModel.bookSource
|
||||
if (source == null) {
|
||||
toastOnUi("先保存书源")
|
||||
return@launch
|
||||
}
|
||||
val variable = withContext(IO) { source.getVariable() }
|
||||
alert(R.string.set_source_variable) {
|
||||
setMessage(source.getDisplayVariableComment("源变量可在js中通过source.getVariable()获取"))
|
||||
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
|
||||
editView.hint = "source variable"
|
||||
editView.setText(variable)
|
||||
}
|
||||
customView { alertBinding.root }
|
||||
okButton {
|
||||
viewModel.bookSource?.setVariable(alertBinding.editView.text?.toString())
|
||||
}
|
||||
cancelButton()
|
||||
neutralButton(R.string.delete) {
|
||||
viewModel.bookSource?.setVariable(null)
|
||||
}
|
||||
}
|
||||
val source = viewModel.bookSource
|
||||
if (source == null) {
|
||||
toastOnUi("先保存书源")
|
||||
return
|
||||
}
|
||||
val comment = source.getDisplayVariableComment("源变量可在js中通过source.getVariable()获取")
|
||||
showDialogFragment(VariableDialog(source.getKey(), comment))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,17 +12,14 @@ import androidx.fragment.app.FragmentStatePagerAdapter
|
||||
import io.legado.app.R
|
||||
import io.legado.app.base.VMBaseActivity
|
||||
import io.legado.app.databinding.ActivityRssArtivlesBinding
|
||||
import io.legado.app.databinding.DialogEditTextBinding
|
||||
import io.legado.app.help.source.sortUrls
|
||||
import io.legado.app.lib.dialogs.alert
|
||||
import io.legado.app.lib.theme.accentColor
|
||||
import io.legado.app.ui.login.SourceLoginActivity
|
||||
import io.legado.app.ui.rss.source.edit.RssSourceEditActivity
|
||||
import io.legado.app.ui.widget.dialog.VariableDialog
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewModel>() {
|
||||
|
||||
@@ -106,29 +103,13 @@ class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewMo
|
||||
}
|
||||
|
||||
private fun setSourceVariable() {
|
||||
launch {
|
||||
val source = viewModel.rssSource
|
||||
if (source == null) {
|
||||
toastOnUi("源不存在")
|
||||
return@launch
|
||||
}
|
||||
val variable = withContext(Dispatchers.IO) { source.getVariable() }
|
||||
alert(R.string.set_source_variable) {
|
||||
setMessage(source.getDisplayVariableComment("源变量可在js中通过source.getVariable()获取"))
|
||||
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
|
||||
editView.hint = "source variable"
|
||||
editView.setText(variable)
|
||||
}
|
||||
customView { alertBinding.root }
|
||||
okButton {
|
||||
viewModel.rssSource?.setVariable(alertBinding.editView.text?.toString())
|
||||
}
|
||||
cancelButton()
|
||||
neutralButton(R.string.delete) {
|
||||
viewModel.rssSource?.setVariable(null)
|
||||
}
|
||||
}
|
||||
val source = viewModel.rssSource
|
||||
if (source == null) {
|
||||
toastOnUi("源不存在")
|
||||
return
|
||||
}
|
||||
val comment = source.getDisplayVariableComment("源变量可在js中通过source.getVariable()获取")
|
||||
showDialogFragment(VariableDialog(source.getKey(), comment))
|
||||
}
|
||||
|
||||
private inner class TabFragmentPageAdapter :
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package io.legado.app.ui.widget.dialog
|
||||
|
||||
import android.app.Application
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.fragment.app.viewModels
|
||||
import io.legado.app.R
|
||||
import io.legado.app.base.BaseDialogFragment
|
||||
import io.legado.app.base.BaseViewModel
|
||||
import io.legado.app.databinding.DialogVariableBinding
|
||||
import io.legado.app.help.CacheManager
|
||||
import io.legado.app.lib.theme.primaryColor
|
||||
import io.legado.app.utils.applyTint
|
||||
import io.legado.app.utils.setLayout
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
|
||||
class VariableDialog() : BaseDialogFragment(R.layout.dialog_variable, true),
|
||||
Toolbar.OnMenuItemClickListener {
|
||||
|
||||
private val binding by viewBinding(DialogVariableBinding::bind)
|
||||
private val viewModel by viewModels<ViewModel>()
|
||||
|
||||
constructor(key: String, comment: String) : this() {
|
||||
arguments = Bundle().apply {
|
||||
putString("key", key)
|
||||
putString("comment", comment)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
|
||||
}
|
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||
binding.toolBar.setBackgroundColor(primaryColor)
|
||||
arguments?.let {
|
||||
viewModel.init(it) {
|
||||
binding.tvComment.text = viewModel.comment
|
||||
binding.tvVariable.setText(viewModel.mVariable)
|
||||
}
|
||||
}
|
||||
binding.toolBar.inflateMenu(R.menu.save)
|
||||
binding.toolBar.menu.applyTint(requireContext())
|
||||
binding.toolBar.setOnMenuItemClickListener(this)
|
||||
}
|
||||
|
||||
override fun onMenuItemClick(item: MenuItem?): Boolean {
|
||||
when (item?.itemId) {
|
||||
R.id.menu_save -> viewModel.save(binding.tvVariable.text?.toString()) {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
class ViewModel(application: Application) : BaseViewModel(application) {
|
||||
|
||||
var key: String? = null
|
||||
var comment: String? = null
|
||||
var mVariable: String? = null
|
||||
|
||||
fun init(arguments: Bundle, onFinally: () -> Unit) {
|
||||
if (key != null) return
|
||||
execute {
|
||||
key = arguments.getString("key")
|
||||
comment = arguments.getString("comment")
|
||||
mVariable = CacheManager.get("sourceVariable_${key}")
|
||||
}.onFinally {
|
||||
onFinally.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
fun save(variable: String?, onFinally: () -> Unit) {
|
||||
execute {
|
||||
if (variable == null) {
|
||||
CacheManager.delete("sourceVariable_${key}")
|
||||
} else {
|
||||
CacheManager.put("sourceVariable_${key}", variable)
|
||||
}
|
||||
}.onFinally {
|
||||
onFinally.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user