From a7c9a2a22fc85c1a82bc0ea0163e1126f9436751 Mon Sep 17 00:00:00 2001 From: ajp_anton Date: Mon, 31 Aug 2026 01:14:34 +0000 Subject: [PATCH] Improve alert setup and access guidance --- .../AlertStatusFragment.kt | 38 -------------- .../notificationsmaster/AlertsFragment.kt | 26 ++++++++++ .../notificationsmaster/MainActivity.kt | 2 - .../main/res/layout/fragment_alert_status.xml | 32 ------------ app/src/main/res/layout/fragment_alerts.xml | 51 ++++++++++++++++++- app/src/main/res/menu/drawer_menu.xml | 3 -- app/src/main/res/values/colors.xml | 2 + app/src/main/res/values/strings.xml | 2 - 8 files changed, 78 insertions(+), 78 deletions(-) delete mode 100644 app/src/main/java/se/ajpanton/notificationsmaster/AlertStatusFragment.kt delete mode 100644 app/src/main/res/layout/fragment_alert_status.xml diff --git a/app/src/main/java/se/ajpanton/notificationsmaster/AlertStatusFragment.kt b/app/src/main/java/se/ajpanton/notificationsmaster/AlertStatusFragment.kt deleted file mode 100644 index 11f4133..0000000 --- a/app/src/main/java/se/ajpanton/notificationsmaster/AlertStatusFragment.kt +++ /dev/null @@ -1,38 +0,0 @@ -package se.ajpanton.notificationsmaster - -import android.content.ComponentName -import android.content.Intent -import android.os.Bundle -import android.provider.Settings -import android.view.View -import androidx.fragment.app.Fragment -import se.ajpanton.notificationsmaster.alerts.AlertConfigurationStore -import se.ajpanton.notificationsmaster.capture.NotificationCaptureService -import se.ajpanton.notificationsmaster.databinding.FragmentAlertStatusBinding - -class AlertStatusFragment : Fragment(R.layout.fragment_alert_status) { - private var binding: FragmentAlertStatusBinding? = null - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - binding = FragmentAlertStatusBinding.bind(view) - binding!!.notificationAccess.setOnClickListener { startActivity(Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)) } - } - - override fun onResume() { - super.onResume() - val context = requireContext() - val config = AlertConfigurationStore(context).load() - val access = context.getSystemService(android.app.NotificationManager::class.java) - .isNotificationListenerAccessGranted(ComponentName(context, NotificationCaptureService::class.java)) - binding?.status?.text = buildString { - append(if (access) "Notification access is enabled." else "Notification access is disabled.") - append("\n\nCustom alerts are ") - append(if (config.enabled) "enabled" else "disabled") - append(" with ${config.rules.count { it.enabled }} active rule") - append(if (config.rules.count { it.enabled } == 1) "." else "s.") - } - binding?.notificationAccess?.text = if (access) "Notification access enabled" else "Enable notification access" - } - - override fun onDestroyView() { binding = null; super.onDestroyView() } -} diff --git a/app/src/main/java/se/ajpanton/notificationsmaster/AlertsFragment.kt b/app/src/main/java/se/ajpanton/notificationsmaster/AlertsFragment.kt index 4da7938..975ce84 100644 --- a/app/src/main/java/se/ajpanton/notificationsmaster/AlertsFragment.kt +++ b/app/src/main/java/se/ajpanton/notificationsmaster/AlertsFragment.kt @@ -1,12 +1,19 @@ package se.ajpanton.notificationsmaster +import android.app.NotificationManager +import android.content.ComponentName +import android.content.Intent +import android.content.res.ColorStateList import android.os.Bundle +import android.provider.Settings import android.view.View import android.widget.ArrayAdapter +import androidx.core.content.ContextCompat 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.capture.NotificationCaptureService import se.ajpanton.notificationsmaster.databinding.FragmentAlertsBinding class AlertsFragment : Fragment(R.layout.fragment_alerts) { @@ -26,9 +33,28 @@ class AlertsFragment : Fragment(R.layout.fragment_alerts) { (1..10).map(Int::toString), ) binding!!.queueLength.setSelection(configuration.queueSettings.maximumLength - 1, false) + binding!!.notificationAccess.setOnClickListener { + startActivity(Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)) + } bindChanges() } + override fun onResume() { + super.onResume() + val context = requireContext() + val access = context.getSystemService(NotificationManager::class.java) + .isNotificationListenerAccessGranted(ComponentName(context, NotificationCaptureService::class.java)) + binding?.notificationAccess?.apply { + text = if (access) "Notification access enabled" else "Enable notification access" + backgroundTintList = ColorStateList.valueOf( + ContextCompat.getColor( + context, + if (access) R.color.notification_access_granted else R.color.notification_access_missing, + ), + ) + } + } + override fun onDestroyView() { binding = null super.onDestroyView() diff --git a/app/src/main/java/se/ajpanton/notificationsmaster/MainActivity.kt b/app/src/main/java/se/ajpanton/notificationsmaster/MainActivity.kt index 8e60b09..4b3df88 100644 --- a/app/src/main/java/se/ajpanton/notificationsmaster/MainActivity.kt +++ b/app/src/main/java/se/ajpanton/notificationsmaster/MainActivity.kt @@ -163,7 +163,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte page == Page.VIEW_LOGS -> ViewLogsFragment() page == Page.SETTINGS -> SettingsFragment() page == Page.ALERTS -> AlertsFragment() - page == Page.ALERT_STATUS -> AlertStatusFragment() page == Page.PROFILES -> ProfilesFragment() page == Page.RULES -> RulesFragment() page == Page.APPS -> AppsFragment() @@ -371,7 +370,6 @@ 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), - ALERT_STATUS(R.id.nav_alert_status, R.string.page_alert_status), PROFILES(R.id.nav_profiles, R.string.page_profiles), RULES(R.id.nav_rules, R.string.page_rules), APPS(R.id.nav_apps, R.string.page_apps), diff --git a/app/src/main/res/layout/fragment_alert_status.xml b/app/src/main/res/layout/fragment_alert_status.xml deleted file mode 100644 index 3d4a949..0000000 --- a/app/src/main/res/layout/fragment_alert_status.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - -