From 0df04c2e82ffd6c225875fca0f9746abe640198c Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 17:27:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/entities/TxtTocRule.kt | 2 +- .../app/ui/book/read/config/TocRegexDialog.kt | 44 ++++++++++++++++++- .../io/legado/app/ui/widget/DetailSeekBar.kt | 4 +- .../main/res/layout/dialog_toc_regex_edit.xml | 31 +++++++++++++ app/src/main/res/layout/item_book_source.xml | 1 + app/src/main/res/layout/item_toc_regex.xml | 41 +++++++++++------ .../main/res/layout/view_detail_seek_bar.xml | 6 ++- .../res/layout/view_select_action_bar.xml | 4 +- app/src/main/res/values/strings.xml | 5 +++ 9 files changed, 117 insertions(+), 21 deletions(-) create mode 100644 app/src/main/res/layout/dialog_toc_regex_edit.xml diff --git a/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt b/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt index c9cd51d4d..cdfca7567 100644 --- a/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt @@ -9,6 +9,6 @@ data class TxtTocRule( @PrimaryKey var name: String = "", var rule: String = "", - var serialNumber: Int, + var serialNumber: Int = -1, var enable: Boolean = true ) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt index 74272fd01..10ca38a5b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.book.read.config +import android.annotation.SuppressLint import android.content.Context import android.os.Bundle import android.util.DisplayMetrics @@ -21,10 +22,16 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.constant.Theme import io.legado.app.data.entities.TxtTocRule import io.legado.app.help.ItemTouchCallback +import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.dialogs.cancelButton +import io.legado.app.lib.dialogs.customView +import io.legado.app.lib.dialogs.okButton import io.legado.app.model.localBook.AnalyzeTxtFile import io.legado.app.utils.applyTint import io.legado.app.utils.getVerticalDivider import kotlinx.android.synthetic.main.dialog_toc_regex.* +import kotlinx.android.synthetic.main.dialog_toc_regex_edit.* +import kotlinx.android.synthetic.main.dialog_toc_regex_edit.view.* import kotlinx.android.synthetic.main.item_toc_regex.view.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch @@ -114,8 +121,40 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { } } + @SuppressLint("InflateParams") private fun editRule(rule: TxtTocRule? = null) { + val tocRule = rule?.copy() ?: TxtTocRule() + requireContext().alert(titleResource = R.string.txt_toc_regex) { + var rootView: View? = null + customView { + LayoutInflater.from(requireContext()) + .inflate(R.layout.dialog_toc_regex_edit, null).apply { + rootView = this + tv_rule_name.setText(tocRule.name) + tv_rule_regex.setText(tocRule.rule) + } + } + okButton { + rootView?.let { + tocRule.name = tv_rule_name.text.toString() + tocRule.rule = tv_rule_regex.text.toString() + saveRule(rule, tocRule) + } + } + cancelButton() + }.show().applyTint() + } + private fun saveRule(oldRule: TxtTocRule?, rule: TxtTocRule) { + launch(IO) { + if (rule.serialNumber < 0) { + rule.serialNumber = adapter.getItems().lastOrNull()?.serialNumber ?: 0 + 1 + } + oldRule?.let { + App.db.txtTocRule().delete(oldRule) + } + App.db.txtTocRule().insert(rule) + } } inner class TocRegexAdapter(context: Context) : @@ -127,6 +166,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { if (payloads.isEmpty()) { rb_regex_name.text = item.name rb_regex_name.isChecked = item.name == selectedName + swt_enabled.isChecked = item.enable } else { rb_regex_name.isChecked = item.name == selectedName } @@ -141,10 +181,10 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { updateItems(0, itemCount - 1, true) } } - tv_edit.onClick { + iv_edit.onClick { editRule(getItem(holder.layoutPosition)) } - tv_del.onClick { + iv_delete.onClick { getItem(holder.layoutPosition)?.let { item -> launch(IO) { App.db.txtTocRule().delete(item) diff --git a/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt b/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt index a959ce515..504837afd 100644 --- a/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt @@ -34,11 +34,11 @@ class DetailSeekBar(context: Context, attrs: AttributeSet?) : FrameLayout(contex seek_bar.max = typedArray.getInteger(R.styleable.DetailSeekBar_max, 0) typedArray.recycle() - iv_seek_add.onClick { + iv_seek_plus.onClick { seek_bar.progressAdd(1) onChanged?.invoke(seek_bar.progress) } - iv_seek_remove.onClick { + iv_seek_reduce.onClick { seek_bar.progressAdd(-1) onChanged?.invoke(seek_bar.progress) } diff --git a/app/src/main/res/layout/dialog_toc_regex_edit.xml b/app/src/main/res/layout/dialog_toc_regex_edit.xml new file mode 100644 index 000000000..13abef871 --- /dev/null +++ b/app/src/main/res/layout/dialog_toc_regex_edit.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_book_source.xml b/app/src/main/res/layout/item_book_source.xml index ee1174355..3ae65e3b9 100644 --- a/app/src/main/res/layout/item_book_source.xml +++ b/app/src/main/res/layout/item_book_source.xml @@ -62,6 +62,7 @@ android:id="@+id/iv_explore" android:layout_width="8dp" android:layout_height="8dp" + android:contentDescription="@string/more_menu" android:src="@color/md_green_600" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> diff --git a/app/src/main/res/layout/item_toc_regex.xml b/app/src/main/res/layout/item_toc_regex.xml index 0434ac4dc..6872044c4 100644 --- a/app/src/main/res/layout/item_toc_regex.xml +++ b/app/src/main/res/layout/item_toc_regex.xml @@ -1,5 +1,6 @@ - + android:layout_height="wrap_content" /> - + + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_detail_seek_bar.xml b/app/src/main/res/layout/view_detail_seek_bar.xml index 57261a37a..af87a83bb 100644 --- a/app/src/main/res/layout/view_detail_seek_bar.xml +++ b/app/src/main/res/layout/view_detail_seek_bar.xml @@ -15,9 +15,10 @@ tools:ignore="HardcodedText" /> @@ -31,9 +32,10 @@ android:max="10" /> diff --git a/app/src/main/res/layout/view_select_action_bar.xml b/app/src/main/res/layout/view_select_action_bar.xml index 97d775dc3..e725a57b7 100644 --- a/app/src/main/res/layout/view_select_action_bar.xml +++ b/app/src/main/res/layout/view_select_action_bar.xml @@ -46,10 +46,12 @@ android:layout_width="36dp" android:layout_height="36dp" android:background="?attr/selectableItemBackgroundBorderless" + android:contentDescription="@string/more_menu" + android:tooltipText="@string/more_menu" android:padding="6dp" android:src="@drawable/ic_more_vert" android:tint="@color/tv_text_default" android:visibility="gone" - tools:ignore="RtlHardcoded" /> + tools:ignore="RtlHardcoded,UnusedAttribute" /> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0efb23246..c456ce6ab 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -621,4 +621,9 @@ 标题居中 浏览器 导入默认规则 + 名称 + 正则 + 更多菜单 + +