Add per-app multiple match option

This commit is contained in:
ajp_anton
2026-08-18 01:53:19 +00:00
parent ce49f21739
commit 7f61f11cbf
2 changed files with 18 additions and 0 deletions
@@ -8,6 +8,7 @@ import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import se.ajpanton.notificationsmaster.alerts.AlertConfigurationStore
import se.ajpanton.notificationsmaster.alerts.AlertAppSettings
import se.ajpanton.notificationsmaster.alerts.AlertRule
import se.ajpanton.notificationsmaster.alerts.AlertRuleEditor
import se.ajpanton.notificationsmaster.databinding.FragmentAppRulesBinding
@@ -28,6 +29,8 @@ class AppRulesFragment : Fragment(R.layout.fragment_app_rules) {
store = AlertConfigurationStore(requireContext())
binding!!.rules.adapter = adapter
binding!!.addRule.setOnClickListener { edit(null) }
binding!!.allowMultipleMatches.isChecked = store.load().appSettings.firstOrNull { it.packageName == packageName }?.allowMultipleMatches == true
binding!!.allowMultipleMatches.setOnCheckedChangeListener { _, enabled -> setAllowMultipleMatches(enabled) }
ItemTouchHelper(object : ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP or ItemTouchHelper.DOWN, 0) {
override fun onMove(recyclerView: RecyclerView, holder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
adapter.move(holder.bindingAdapterPosition, target.bindingAdapterPosition)
@@ -64,6 +67,14 @@ class AppRulesFragment : Fragment(R.layout.fragment_app_rules) {
store.save(AlertRuleEditor.reorderForApp(store.load(), packageName, adapter.items.map { it.id }))
}
private fun setAllowMultipleMatches(enabled: Boolean) {
val configuration = store.load()
val old = configuration.appSettings.firstOrNull { it.packageName == packageName }
val setting = (old ?: AlertAppSettings(packageName)).copy(allowMultipleMatches = enabled)
store.save(configuration.copy(appSettings = configuration.appSettings.filterNot { it.packageName == packageName } +
if (enabled || setting.directAlertControl) listOf(setting) else emptyList()))
}
private class RuleAdapter(private val onClick: (AlertRule) -> Unit) : RecyclerView.Adapter<RuleAdapter.Holder>() {
var items = emptyList<AlertRule>(); private set
fun submit(rules: List<AlertRule>) { items = rules; notifyDataSetChanged() }
@@ -18,6 +18,13 @@
android:text="Drag rules to set their priority. The first matching rule is used."
android:textSize="12sp" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/allow_multiple_matches"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Allow multiple matching rules" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rules"
android:layout_width="match_parent"