diff --git a/app/src/main/java/se/ajpanton/notificationsmaster/AlertsFragment.kt b/app/src/main/java/se/ajpanton/notificationsmaster/AlertsFragment.kt
new file mode 100644
index 0000000..4da7938
--- /dev/null
+++ b/app/src/main/java/se/ajpanton/notificationsmaster/AlertsFragment.kt
@@ -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,
+ ),
+ ),
+ )
+ }
+}
diff --git a/app/src/main/java/se/ajpanton/notificationsmaster/MainActivity.kt b/app/src/main/java/se/ajpanton/notificationsmaster/MainActivity.kt
index 455145b..aa0fb74 100644
--- a/app/src/main/java/se/ajpanton/notificationsmaster/MainActivity.kt
+++ b/app/src/main/java/se/ajpanton/notificationsmaster/MainActivity.kt
@@ -154,6 +154,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
when {
page == Page.VIEW_LOGS -> ViewLogsFragment()
page == Page.SETTINGS -> SettingsFragment()
+ page == Page.ALERTS -> AlertsFragment()
page == Page.LOG_DISPLAY -> LogDisplayFragment()
page == Page.FILTER_LOGGING -> FilterLoggingFragment()
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),
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),
FILTER_LOGGING(R.id.nav_filter_logging, R.string.page_filter_logging),
FILTER_APPS(R.id.nav_filter_apps, R.string.page_filter_apps),
diff --git a/app/src/main/res/layout/fragment_alerts.xml b/app/src/main/res/layout/fragment_alerts.xml
new file mode 100644
index 0000000..c833c5d
--- /dev/null
+++ b/app/src/main/res/layout/fragment_alerts.xml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/menu/drawer_menu.xml b/app/src/main/res/menu/drawer_menu.xml
index f280640..3604b0a 100644
--- a/app/src/main/res/menu/drawer_menu.xml
+++ b/app/src/main/res/menu/drawer_menu.xml
@@ -9,6 +9,9 @@
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index f0cea9b..88a2cf3 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -7,10 +7,12 @@
Settings
View logs
Settings
+ Alerts
Filter apps
Log display
Filter logging
Log display
+ Alerts
Filter logging
Filter apps