diff --git a/app/src/main/java/se/ajpanton/notificationsmaster/AlertStatusFragment.kt b/app/src/main/java/se/ajpanton/notificationsmaster/AlertStatusFragment.kt new file mode 100644 index 0000000..11f4133 --- /dev/null +++ b/app/src/main/java/se/ajpanton/notificationsmaster/AlertStatusFragment.kt @@ -0,0 +1,38 @@ +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/MainActivity.kt b/app/src/main/java/se/ajpanton/notificationsmaster/MainActivity.kt index 6716c0c..c4a1a4f 100644 --- a/app/src/main/java/se/ajpanton/notificationsmaster/MainActivity.kt +++ b/app/src/main/java/se/ajpanton/notificationsmaster/MainActivity.kt @@ -155,6 +155,7 @@ 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() @@ -350,6 +351,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), + 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 new file mode 100644 index 0000000..9f88023 --- /dev/null +++ b/app/src/main/res/layout/fragment_alert_status.xml @@ -0,0 +1,31 @@ + + + + + + + +