mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
优化
This commit is contained in:
parent
f7449f30df
commit
1a6d59389d
@ -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)
|
||||
|
||||
}
|
||||
|
||||
}
|
13
app/src/main/res/menu/code_edit.xml
Normal file
13
app/src/main/res/menu/code_edit.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:ignore="AlwaysShowAction">
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_save"
|
||||
android:icon="@drawable/ic_save"
|
||||
android:title="@string/action_save"
|
||||
app:showAsAction="always" />
|
||||
|
||||
</menu>
|
Loading…
Reference in New Issue
Block a user