diff --git a/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt b/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt index 6a2482d43..5940272af 100644 --- a/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt @@ -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 = '')""" diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt index b043f4af7..966891a9c 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt @@ -62,8 +62,9 @@ class ReplaceRuleActivity : VMBaseActivity(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) } diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt index 00af7e1ac..e6a43ba79 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt @@ -17,7 +17,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_replace_rule), ItemTouchCallback.OnItemTouchCallbackListener { - val selectedIds = linkedSetOf() + private val selectedIds = linkedSetOf() fun selectAll() { getItems().forEach { @@ -37,6 +37,16 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : notifyItemRangeChanged(0, itemCount, 1) } + fun getSelectionIds(): LinkedHashSet { + val selection = linkedSetOf() + getItems().map { + if (selectedIds.contains(it.id)) { + selection.add(it.id) + } + } + return selection + } + override fun convert(holder: ItemViewHolder, item: ReplaceRule, payloads: MutableList) { with(holder.itemView) { if (payloads.isEmpty()) { diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt index 0311b58a9..c820749ef 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt @@ -51,6 +51,12 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application } } + fun delSelection(ids: LinkedHashSet) { + execute { + App.db.replaceRuleDao().delSection(*ids.toLongArray()) + } + } + fun addGroup(group: String) { execute { val sources = App.db.replaceRuleDao().noGroup diff --git a/app/src/main/res/menu/replace_rule.xml b/app/src/main/res/menu/replace_rule.xml index 29b21845d..eec4b7abd 100644 --- a/app/src/main/res/menu/replace_rule.xml +++ b/app/src/main/res/menu/replace_rule.xml @@ -33,7 +33,7 @@ app:showAsAction="never" />