From 1a6d59389d0296ae4031d7457057d2b2dc29c190 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 6 Oct 2021 23:57:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/widget/dialog/CodeDialog.kt | 30 +++++++++++++++++-- app/src/main/res/menu/code_edit.xml | 13 ++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/menu/code_edit.xml diff --git a/app/src/main/java/io/legado/app/ui/widget/dialog/CodeDialog.kt b/app/src/main/java/io/legado/app/ui/widget/dialog/CodeDialog.kt index 6a6c08536..5ff8ab53b 100644 --- a/app/src/main/java/io/legado/app/ui/widget/dialog/CodeDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/dialog/CodeDialog.kt @@ -9,14 +9,15 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.widget.code.addJsPattern import io.legado.app.ui.widget.code.addJsonPattern import io.legado.app.ui.widget.code.addLegadoPattern +import io.legado.app.utils.disableEdit import io.legado.app.utils.setLayout import io.legado.app.utils.viewbindingdelegate.viewBinding class CodeDialog() : BaseDialogFragment(R.layout.dialog_code_view) { - constructor(code: String) : this() { + constructor(code: String, disableEdit: Boolean = true) : this() { arguments = Bundle().apply { - + putBoolean("disableEdit", disableEdit) putString("code", code) } } @@ -30,6 +31,11 @@ class CodeDialog() : BaseDialogFragment(R.layout.dialog_code_view) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { binding.toolBar.setBackgroundColor(primaryColor) + if (arguments?.getBoolean("disableEdit") == true) { + binding.codeView.disableEdit() + } else { + initMenu() + } binding.codeView.addLegadoPattern() binding.codeView.addJsonPattern() binding.codeView.addJsPattern() @@ -38,4 +44,24 @@ class CodeDialog() : BaseDialogFragment(R.layout.dialog_code_view) { } } + private fun initMenu() { + binding.toolBar.inflateMenu(R.menu.code_edit) + binding.toolBar.setOnMenuItemClickListener { + when (it.itemId) { + R.id.menu_save -> binding.codeView.text?.toString()?.let { code -> + (parentFragment as? Callback)?.saveCode(code) + ?: (activity as? Callback)?.saveCode(code) + } + } + return@setOnMenuItemClickListener true + } + } + + + interface Callback { + + fun saveCode(code: String) + + } + } \ No newline at end of file diff --git a/app/src/main/res/menu/code_edit.xml b/app/src/main/res/menu/code_edit.xml new file mode 100644 index 000000000..05397ae61 --- /dev/null +++ b/app/src/main/res/menu/code_edit.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file