diff --git a/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt b/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt index 119daa651..c63133164 100644 --- a/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt @@ -1,11 +1,15 @@ package io.legado.app.data.dao +import androidx.lifecycle.LiveData import androidx.room.* import io.legado.app.data.entities.TxtTocRule @Dao interface TxtTocRuleDao { + @Query("select * from txtTocRules order by serialNumber") + fun observeAll(): LiveData> + @get:Query("select * from txtTocRules order by serialNumber") val all: List 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 f0cd6b31a..4359b15d5 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 @@ -9,6 +9,10 @@ import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.Toolbar import androidx.fragment.app.FragmentManager +import androidx.lifecycle.LiveData +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseDialogFragment import io.legado.app.base.adapter.ItemViewHolder @@ -16,20 +20,15 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.constant.Theme import io.legado.app.data.entities.TxtTocRule 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.item_toc_regex.view.* class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { - companion object { - fun show(fragmentManager: FragmentManager, tocRegex: String? = null) { - val dialog = TocRegexDialog() - val bundle = Bundle() - bundle.putString("tocRegex", tocRegex) - dialog.arguments = bundle - dialog.show(fragmentManager, "tocRegexDialog") - } - } + private lateinit var adapter: TocRegexAdapter + private var tocRegexLiveData: LiveData>? = null override fun onStart() { super.onStart() @@ -53,10 +52,22 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { tool_bar.menu.applyTint(requireContext(), Theme.getTheme()) tool_bar.setOnMenuItemClickListener(this) initView() + initData() } private fun initView() { + adapter = TocRegexAdapter(requireContext()) + recycler_view.layoutManager = LinearLayoutManager(requireContext()) + recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) + recycler_view.adapter = adapter + } + private fun initData() { + tocRegexLiveData?.removeObservers(viewLifecycleOwner) + tocRegexLiveData = App.db.txtTocRule().observeAll() + tocRegexLiveData?.observe(viewLifecycleOwner, Observer { + adapter.setItems(it) + }) } override fun onMenuItemClick(item: MenuItem?): Boolean { @@ -65,15 +76,29 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { } - inner class TocRegexDialog(context: Context) : + inner class TocRegexAdapter(context: Context) : SimpleRecyclerAdapter(context, R.layout.item_toc_regex) { override fun convert(holder: ItemViewHolder, item: TxtTocRule, payloads: MutableList) { - + holder.itemView.apply { + rb_regex_name.text = item.name + } } override fun registerListener(holder: ItemViewHolder) { } } + + + companion object { + fun show(fragmentManager: FragmentManager, tocRegex: String? = null) { + val dialog = TocRegexDialog() + val bundle = Bundle() + bundle.putString("tocRegex", tocRegex) + dialog.arguments = bundle + dialog.show(fragmentManager, "tocRegexDialog") + } + } + } \ No newline at end of file diff --git a/app/src/main/res/layout/item_group_manage.xml b/app/src/main/res/layout/item_group_manage.xml index d7d85630a..763a19acd 100644 --- a/app/src/main/res/layout/item_group_manage.xml +++ b/app/src/main/res/layout/item_group_manage.xml @@ -4,6 +4,7 @@ android:layout_height="wrap_content" android:background="@color/background" android:padding="8dp" + android:gravity="center_vertical" android:orientation="horizontal"> + android:layout_weight="1" + android:maxLines="1" />