pull/32/head
kunfei 5 years ago
parent 39e3ffe5a3
commit b1d99da41b
  1. 3
      app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt
  2. 5
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt
  3. 12
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt
  4. 6
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt
  5. 2
      app/src/main/res/menu/replace_rule.xml

@ -38,6 +38,9 @@ interface ReplaceRuleDao {
@Query("update replace_rules set isEnabled = 0 where id in (:ids)")
fun disableSection(vararg ids: Long)
@Query("delete from replace_rules where id in (:ids)")
fun delSection(vararg ids: Long)
@Query(
"""SELECT * FROM replace_rules WHERE isEnabled = 1
AND (scope LIKE '%' || :scope || '%' or scope = null or scope = '')"""

@ -62,8 +62,9 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
GroupManageDialog().show(supportFragmentManager, "groupManage")
R.id.menu_select_all -> adapter.selectAll()
R.id.menu_revert_selection -> adapter.revertSelection()
R.id.menu_enable_selection -> viewModel.enableSelection(adapter.selectedIds)
R.id.menu_disable_selection -> viewModel.disableSelection(adapter.selectedIds)
R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelectionIds())
R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelectionIds())
R.id.menu_del_selection -> viewModel.disableSelection(adapter.getSelectionIds())
}
return super.onCompatOptionsItemSelected(item)
}

@ -17,7 +17,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
SimpleRecyclerAdapter<ReplaceRule>(context, R.layout.item_replace_rule),
ItemTouchCallback.OnItemTouchCallbackListener {
val selectedIds = linkedSetOf<Long>()
private val selectedIds = linkedSetOf<Long>()
fun selectAll() {
getItems().forEach {
@ -37,6 +37,16 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
notifyItemRangeChanged(0, itemCount, 1)
}
fun getSelectionIds(): LinkedHashSet<Long> {
val selection = linkedSetOf<Long>()
getItems().map {
if (selectedIds.contains(it.id)) {
selection.add(it.id)
}
}
return selection
}
override fun convert(holder: ItemViewHolder, item: ReplaceRule, payloads: MutableList<Any>) {
with(holder.itemView) {
if (payloads.isEmpty()) {

@ -51,6 +51,12 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
}
}
fun delSelection(ids: LinkedHashSet<Long>) {
execute {
App.db.replaceRuleDao().delSection(*ids.toLongArray())
}
}
fun addGroup(group: String) {
execute {
val sources = App.db.replaceRuleDao().noGroup

@ -33,7 +33,7 @@
app:showAsAction="never" />
<item
android:id="@+id/menu_del_select"
android:id="@+id/menu_del_selection"
android:title="@string/del_select"
app:showAsAction="never" />

Loading…
Cancel
Save