mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -20,6 +20,9 @@ interface DictRuleDao {
|
||||
@Query("select * from dictRules where enabled = 1 order by sortNumber")
|
||||
fun flowAll(): Flow<List<DictRule>>
|
||||
|
||||
@Query("select * from dictRules where name = :name")
|
||||
fun getByName(name: String): DictRule?
|
||||
|
||||
@Upsert
|
||||
fun upsert(vararg dictRule: DictRule)
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
|
||||
import io.legado.app.ui.widget.recycler.ItemTouchCallback
|
||||
import io.legado.app.ui.widget.recycler.VerticalDivider
|
||||
import io.legado.app.utils.setEdgeEffectColor
|
||||
import io.legado.app.utils.showDialogFragment
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@@ -77,7 +78,7 @@ class DictRuleActivity : VMBaseActivity<ActivityDictRuleBinding, DictRuleViewMod
|
||||
|
||||
override fun onContextItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.menu_create -> {}
|
||||
R.id.menu_create -> showDialogFragment<DictRuleEditDialog>()
|
||||
}
|
||||
return super.onContextItemSelected(item)
|
||||
}
|
||||
@@ -91,9 +92,9 @@ class DictRuleActivity : VMBaseActivity<ActivityDictRuleBinding, DictRuleViewMod
|
||||
|
||||
override fun selectAll(selectAll: Boolean) {
|
||||
if (selectAll) {
|
||||
adapter.revertSelection()
|
||||
} else {
|
||||
adapter.selectAll()
|
||||
} else {
|
||||
adapter.revertSelection()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +111,7 @@ class DictRuleActivity : VMBaseActivity<ActivityDictRuleBinding, DictRuleViewMod
|
||||
}
|
||||
|
||||
override fun edit(rule: DictRule) {
|
||||
|
||||
showDialogFragment(DictRuleEditDialog(rule.name))
|
||||
}
|
||||
|
||||
override fun upOrder() {
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package io.legado.app.ui.dict.rule
|
||||
|
||||
import android.app.Application
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
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.data.appDb
|
||||
import io.legado.app.data.entities.DictRule
|
||||
import io.legado.app.databinding.DialogDictRuleEditBinding
|
||||
import io.legado.app.lib.theme.primaryColor
|
||||
import io.legado.app.utils.setLayout
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
|
||||
class DictRuleEditDialog() : BaseDialogFragment(R.layout.dialog_dict_rule_edit, true) {
|
||||
|
||||
val viewModel by viewModels<DictRuleEditViewModel>()
|
||||
val binding by viewBinding(DialogDictRuleEditBinding::bind)
|
||||
|
||||
constructor(name: String) : this() {
|
||||
arguments = Bundle().apply {
|
||||
putString("name", name)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
viewModel.initData(arguments?.getString("name")) {
|
||||
binding.tvRuleName.setText(viewModel.dictRule?.name)
|
||||
binding.tvUrlRule.setText(viewModel.dictRule?.urlRule)
|
||||
binding.tvShowRule.setText(viewModel.dictRule?.showRule)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DictRuleEditViewModel(application: Application) : BaseViewModel(application) {
|
||||
|
||||
var dictRule: DictRule? = null
|
||||
|
||||
fun initData(name: String?, onFinally: () -> Unit) {
|
||||
execute {
|
||||
if (dictRule == null && name != null) {
|
||||
dictRule = appDb.dictRuleDao.getByName(name)
|
||||
}
|
||||
}.onFinally {
|
||||
onFinally.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
86
app/src/main/res/layout/dialog_dict_rule_edit.xml
Normal file
86
app/src/main/res/layout/dialog_dict_rule_edit.xml
Normal file
@@ -0,0 +1,86 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout 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"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="16dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:background="@drawable/shape_card_view"
|
||||
android:orientation="vertical"
|
||||
tools:ignore="UselessParent">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/tool_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/background_menu"
|
||||
android:elevation="5dp"
|
||||
android:theme="?attr/actionBarStyle"
|
||||
app:displayHomeAsUp="false"
|
||||
app:fitStatusBar="false"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay"
|
||||
app:title="@string/dict_rule"
|
||||
app:titleTextAppearance="@style/ToolbarTitle" />
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="6dp"
|
||||
android:overScrollMode="ifContentScrolls">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<io.legado.app.ui.widget.text.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/name">
|
||||
|
||||
<io.legado.app.lib.theme.view.ThemeEditText
|
||||
android:id="@+id/tv_rule_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
|
||||
|
||||
</io.legado.app.ui.widget.text.TextInputLayout>
|
||||
|
||||
<io.legado.app.ui.widget.text.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/url_rule">
|
||||
|
||||
<io.legado.app.lib.theme.view.ThemeEditText
|
||||
android:id="@+id/tv_url_rule"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
|
||||
|
||||
</io.legado.app.ui.widget.text.TextInputLayout>
|
||||
|
||||
<io.legado.app.ui.widget.text.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/show_rule">
|
||||
|
||||
<io.legado.app.lib.theme.view.ThemeEditText
|
||||
android:id="@+id/tv_show_rule"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
|
||||
|
||||
</io.legado.app.ui.widget.text.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
@@ -30,6 +30,7 @@
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="6dp"
|
||||
android:overScrollMode="ifContentScrolls">
|
||||
|
||||
<LinearLayout
|
||||
|
||||
@@ -1075,4 +1075,6 @@
|
||||
<string name="dict_rule">字典规则</string>
|
||||
<string name="config_dict_rule">配置字典规则</string>
|
||||
<string name="create">新建</string>
|
||||
<string name="url_rule">url规则(urlRule)</string>
|
||||
<string name="show_rule">显示规则(showRule)</string>
|
||||
</resources>
|
||||
|
||||
@@ -1078,4 +1078,6 @@
|
||||
<string name="dict_rule">字典规则</string>
|
||||
<string name="config_dict_rule">配置字典规则</string>
|
||||
<string name="create">新建</string>
|
||||
<string name="url_rule">url规则(urlRule)</string>
|
||||
<string name="show_rule">显示规则(showRule)</string>
|
||||
</resources>
|
||||
|
||||
@@ -1078,4 +1078,6 @@
|
||||
<string name="dict_rule">字典规则</string>
|
||||
<string name="config_dict_rule">配置字典规则</string>
|
||||
<string name="create">新建</string>
|
||||
<string name="url_rule">url规则(urlRule)</string>
|
||||
<string name="show_rule">显示规则(showRule)</string>
|
||||
</resources>
|
||||
|
||||
@@ -1075,4 +1075,6 @@
|
||||
<string name="dict_rule">字典规则</string>
|
||||
<string name="config_dict_rule">配置字典规则</string>
|
||||
<string name="create">新建</string>
|
||||
<string name="url_rule">url规则(urlRule)</string>
|
||||
<string name="show_rule">显示规则(showRule)</string>
|
||||
</resources>
|
||||
|
||||
@@ -1077,4 +1077,6 @@
|
||||
<string name="dict_rule">字典规则</string>
|
||||
<string name="config_dict_rule">配置字典规则</string>
|
||||
<string name="create">新建</string>
|
||||
<string name="url_rule">url规则(urlRule)</string>
|
||||
<string name="show_rule">显示规则(showRule)</string>
|
||||
</resources>
|
||||
|
||||
@@ -1077,4 +1077,6 @@
|
||||
<string name="dict_rule">字典规则</string>
|
||||
<string name="config_dict_rule">配置字典规则</string>
|
||||
<string name="create">新建</string>
|
||||
<string name="url_rule">url规则(urlRule)</string>
|
||||
<string name="show_rule">显示规则(showRule)</string>
|
||||
</resources>
|
||||
|
||||
@@ -1078,4 +1078,6 @@
|
||||
<string name="dict_rule">Dict rule</string>
|
||||
<string name="config_dict_rule">Config dict rule</string>
|
||||
<string name="create">新建</string>
|
||||
<string name="url_rule">url规则(urlRule)</string>
|
||||
<string name="show_rule">显示规则(showRule)</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user