Add alert queue settings page

This commit is contained in:
ajp_anton
2026-08-18 01:35:07 +00:00
parent 6aab879dbd
commit 1b21ff6751
5 changed files with 122 additions and 0 deletions
@@ -0,0 +1,66 @@
package se.ajpanton.notificationsmaster
import android.os.Bundle
import android.view.View
import android.widget.ArrayAdapter
import androidx.fragment.app.Fragment
import se.ajpanton.notificationsmaster.alerts.AlertConfigurationStore
import se.ajpanton.notificationsmaster.alerts.AlertQueueOverflow
import se.ajpanton.notificationsmaster.alerts.AlertQueueSettings
import se.ajpanton.notificationsmaster.databinding.FragmentAlertsBinding
class AlertsFragment : Fragment(R.layout.fragment_alerts) {
private var binding: FragmentAlertsBinding? = null
private lateinit var store: AlertConfigurationStore
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
binding = FragmentAlertsBinding.bind(view)
store = AlertConfigurationStore(requireContext())
val configuration = store.load()
binding!!.enableAlerts.isChecked = configuration.enabled
binding!!.ignoreRoutineUpdates.isChecked = configuration.ignoreRoutineUpdates
binding!!.dropOldest.isChecked = configuration.queueSettings.overflow == AlertQueueOverflow.DROP_OLDEST
binding!!.queueLength.adapter = ArrayAdapter(
requireContext(),
android.R.layout.simple_spinner_dropdown_item,
(1..10).map(Int::toString),
)
binding!!.queueLength.setSelection(configuration.queueSettings.maximumLength - 1, false)
bindChanges()
}
override fun onDestroyView() {
binding = null
super.onDestroyView()
}
private fun bindChanges() {
binding!!.enableAlerts.setOnCheckedChangeListener { _, enabled ->
store.save(store.load().copy(enabled = enabled))
}
binding!!.ignoreRoutineUpdates.setOnCheckedChangeListener { _, ignore ->
store.save(store.load().copy(ignoreRoutineUpdates = ignore))
}
binding!!.dropOldest.setOnCheckedChangeListener { _, oldest ->
saveQueue(overflow = if (oldest) AlertQueueOverflow.DROP_OLDEST else AlertQueueOverflow.DROP_NEWEST)
}
binding!!.queueLength.onItemSelectedListener = object : android.widget.AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: android.widget.AdapterView<*>?) = Unit
override fun onItemSelected(parent: android.widget.AdapterView<*>?, view: View?, position: Int, id: Long) {
saveQueue(maximumLength = position + 1)
}
}
}
private fun saveQueue(maximumLength: Int? = null, overflow: AlertQueueOverflow? = null) {
val current = store.load().queueSettings
store.save(
store.load().copy(
queueSettings = AlertQueueSettings(
maximumLength ?: current.maximumLength,
overflow ?: current.overflow,
),
),
)
}
}
@@ -154,6 +154,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
when { when {
page == Page.VIEW_LOGS -> ViewLogsFragment() page == Page.VIEW_LOGS -> ViewLogsFragment()
page == Page.SETTINGS -> SettingsFragment() page == Page.SETTINGS -> SettingsFragment()
page == Page.ALERTS -> AlertsFragment()
page == Page.LOG_DISPLAY -> LogDisplayFragment() page == Page.LOG_DISPLAY -> LogDisplayFragment()
page == Page.FILTER_LOGGING -> FilterLoggingFragment() page == Page.FILTER_LOGGING -> FilterLoggingFragment()
page == Page.FILTER_APPS -> FilterAppsFragment.newInstance() page == Page.FILTER_APPS -> FilterAppsFragment.newInstance()
@@ -345,6 +346,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
) { ) {
VIEW_LOGS(R.id.nav_view_logs, R.string.page_view_logs), VIEW_LOGS(R.id.nav_view_logs, R.string.page_view_logs),
SETTINGS(R.id.nav_settings, R.string.page_settings), SETTINGS(R.id.nav_settings, R.string.page_settings),
ALERTS(R.id.nav_alerts, R.string.page_alerts),
LOG_DISPLAY(R.id.nav_log_display, R.string.page_log_display), LOG_DISPLAY(R.id.nav_log_display, R.string.page_log_display),
FILTER_LOGGING(R.id.nav_filter_logging, R.string.page_filter_logging), FILTER_LOGGING(R.id.nav_filter_logging, R.string.page_filter_logging),
FILTER_APPS(R.id.nav_filter_apps, R.string.page_filter_apps), FILTER_APPS(R.id.nav_filter_apps, R.string.page_filter_apps),
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/page_padding">
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/enable_alerts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enable custom alerts" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/ignore_routine_updates"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Ignore detected routine updates" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Queue" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Maximum queue length" />
<Spinner
android:id="@+id/queue_length"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/drop_oldest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Drop oldest alert when queue is full" />
</LinearLayout>
</ScrollView>
+3
View File
@@ -9,6 +9,9 @@
<item <item
android:id="@+id/nav_settings" android:id="@+id/nav_settings"
android:title="@string/navigation_settings_header" /> android:title="@string/navigation_settings_header" />
<item
android:id="@+id/nav_alerts"
android:title="@string/navigation_indented_alerts" />
<item <item
android:id="@+id/nav_log_display" android:id="@+id/nav_log_display"
android:title="@string/navigation_indented_log_display" /> android:title="@string/navigation_indented_log_display" />
+2
View File
@@ -7,10 +7,12 @@
<string name="navigation_settings_header">Settings</string> <string name="navigation_settings_header">Settings</string>
<string name="page_view_logs">View logs</string> <string name="page_view_logs">View logs</string>
<string name="page_settings">Settings</string> <string name="page_settings">Settings</string>
<string name="page_alerts">Alerts</string>
<string name="page_filter_apps">Filter apps</string> <string name="page_filter_apps">Filter apps</string>
<string name="page_log_display">Log display</string> <string name="page_log_display">Log display</string>
<string name="page_filter_logging">Filter logging</string> <string name="page_filter_logging">Filter logging</string>
<string name="navigation_indented_log_display">&#160;&#160;&#160;&#160;Log display</string> <string name="navigation_indented_log_display">&#160;&#160;&#160;&#160;Log display</string>
<string name="navigation_indented_alerts">&#160;&#160;&#160;&#160;Alerts</string>
<string name="navigation_indented_filter_logging">&#160;&#160;&#160;&#160;Filter logging</string> <string name="navigation_indented_filter_logging">&#160;&#160;&#160;&#160;Filter logging</string>
<string name="navigation_indented_filter_apps">&#160;&#160;&#160;&#160;Filter apps</string> <string name="navigation_indented_filter_apps">&#160;&#160;&#160;&#160;Filter apps</string>
</resources> </resources>