feat: 优化代码

pull/115/head
kunfei 5 years ago
parent 8158da607c
commit 1a5c9bfacf
  1. 4
      app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt
  2. 47
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt
  3. 1
      app/src/main/res/layout/item_group_manage.xml
  4. 1
      app/src/main/res/layout/item_group_select.xml
  5. 4
      app/src/main/res/layout/item_toc_regex.xml

@ -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<List<TxtTocRule>>
@get:Query("select * from txtTocRules order by serialNumber")
val all: List<TxtTocRule>

@ -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<List<TxtTocRule>>? = 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<TxtTocRule>(context, R.layout.item_toc_regex) {
override fun convert(holder: ItemViewHolder, item: TxtTocRule, payloads: MutableList<Any>) {
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")
}
}
}

@ -4,6 +4,7 @@
android:layout_height="wrap_content"
android:background="@color/background"
android:padding="8dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView

@ -4,6 +4,7 @@
android:layout_height="wrap_content"
android:background="@color/background"
android:padding="8dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<io.legado.app.lib.theme.view.ATECheckBox

@ -4,13 +4,15 @@
android:layout_height="wrap_content"
android:background="@color/background"
android:padding="8dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<io.legado.app.lib.theme.view.ATERadioButton
android:id="@+id/rb_regex_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
android:layout_weight="1"
android:maxLines="1" />
<TextView
android:id="@+id/tv_edit"

Loading…
Cancel
Save