pull/32/head
kunfei 5 years ago
parent 6a71f87c6f
commit bc31589bdf
  1. 11
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt
  2. 26
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt

@ -23,7 +23,6 @@ import io.legado.app.utils.getViewModel
import io.legado.app.utils.splitNotBlank import io.legado.app.utils.splitNotBlank
import kotlinx.android.synthetic.main.activity_replace_rule.* import kotlinx.android.synthetic.main.activity_replace_rule.*
import kotlinx.android.synthetic.main.view_search.* import kotlinx.android.synthetic.main.view_search.*
import org.jetbrains.anko.doAsync
class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activity_replace_rule), class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activity_replace_rule),
@ -33,7 +32,6 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
get() = getViewModel(ReplaceRuleViewModel::class.java) get() = getViewModel(ReplaceRuleViewModel::class.java)
private lateinit var adapter: ReplaceRuleAdapter private lateinit var adapter: ReplaceRuleAdapter
private var allEnabled = false
private var groups = hashSetOf<String>() private var groups = hashSetOf<String>()
private var groupMenu: SubMenu? = null private var groupMenu: SubMenu? = null
private var replaceRuleLiveData: LiveData<List<ReplaceRule>>? = null private var replaceRuleLiveData: LiveData<List<ReplaceRule>>? = null
@ -62,6 +60,7 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
ReplaceEditDialog().show(supportFragmentManager, "replaceNew") ReplaceEditDialog().show(supportFragmentManager, "replaceNew")
R.id.menu_group_manage -> R.id.menu_group_manage ->
GroupManageDialog().show(supportFragmentManager, "groupManage") GroupManageDialog().show(supportFragmentManager, "groupManage")
R.id.menu_select_all -> adapter.selectAll()
} }
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
} }
@ -100,6 +99,7 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
} }
replaceRuleLiveData?.observe(this, Observer { replaceRuleLiveData?.observe(this, Observer {
val diffResult = DiffUtil.calculateDiff(DiffCallBack(adapter.getItems(), it)) val diffResult = DiffUtil.calculateDiff(DiffCallBack(adapter.getItems(), it))
adapter.selectedIds.clear()
adapter.setItemsNoNotify(it) adapter.setItemsNoNotify(it)
diffResult.dispatchUpdatesTo(adapter) diffResult.dispatchUpdatesTo(adapter)
}) })
@ -122,13 +122,6 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
} }
} }
private fun updateEnableAll() {
doAsync {
App.db.replaceRuleDao().summary.let {
allEnabled = it == 0
}
}
}
override fun onQueryTextChange(newText: String?): Boolean { override fun onQueryTextChange(newText: String?): Boolean {
observeReplaceRuleData("%$newText%") observeReplaceRuleData("%$newText%")

@ -17,8 +17,21 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
SimpleRecyclerAdapter<ReplaceRule>(context, R.layout.item_replace_rule), SimpleRecyclerAdapter<ReplaceRule>(context, R.layout.item_replace_rule),
ItemTouchCallback.OnItemTouchCallbackListener { ItemTouchCallback.OnItemTouchCallbackListener {
val selectedIds = linkedSetOf<Long>()
fun selectAll() {
if (selectedIds.size == itemCount) {
selectedIds.clear()
notifyItemRangeChanged(0, itemCount, 1)
} else {
getItems().forEach { selectedIds.add(it.id) }
notifyItemRangeChanged(0, itemCount, 1)
}
}
override fun convert(holder: ItemViewHolder, item: ReplaceRule, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: ReplaceRule, payloads: MutableList<Any>) {
with(holder.itemView) { with(holder.itemView) {
if (payloads.isEmpty()) {
this.setBackgroundColor(context.backgroundColor) this.setBackgroundColor(context.backgroundColor)
cb_name.text = item.name cb_name.text = item.name
swt_enabled.isChecked = item.isEnabled swt_enabled.isChecked = item.isEnabled
@ -42,6 +55,19 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
} }
popupMenu.show() popupMenu.show()
} }
cb_name.onClick {
if (cb_name.isChecked) {
selectedIds.add(item.id)
} else {
selectedIds.remove(item.id)
}
}
cb_name.isChecked = selectedIds.contains(item.id)
} else {
when (payloads[0]) {
1 -> cb_name.isChecked = selectedIds.contains(item.id)
}
}
} }
} }

Loading…
Cancel
Save