Add alert queue settings page
This commit is contained in:
@@ -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 {
|
||||
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),
|
||||
|
||||
Reference in New Issue
Block a user