Explain rootless alert status
This commit is contained in:
@@ -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() }
|
||||
}
|
||||
Reference in New Issue
Block a user