]> gitweb.stoutner.com Git - PrivacyCell.git/commitdiff
Disable swiping to dismiss realtime notifications. https://redmine.stoutner.com/issue...
authorSoren Stoutner <soren@stoutner.com>
Tue, 29 Nov 2022 20:48:57 +0000 (13:48 -0700)
committerSoren Stoutner <soren@stoutner.com>
Tue, 29 Nov 2022 20:48:57 +0000 (13:48 -0700)
app/src/main/java/com/stoutner/privacycell/activities/SettingsActivity.kt
app/src/main/java/com/stoutner/privacycell/fragments/SettingsFragment.kt
app/src/main/java/com/stoutner/privacycell/services/RealtimeMonitoringService.kt
app/src/main/res/values-de/strings.xml
app/src/main/res/values-es/strings.xml
app/src/main/res/values-fr/strings.xml
app/src/main/res/values-it/strings.xml
app/src/main/res/values-ru/strings.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/preferences.xml

index 098f45f8c54d8940429dc739e85a1ccb563aa844..f1923b3b4d1a10ae8f85bf7bf0415edfbda78a2b 100644 (file)
@@ -37,6 +37,9 @@ import com.stoutner.privacycell.fragments.SettingsFragment
 import com.stoutner.privacycell.services.RealtimeMonitoringService
 
 class SettingsActivity : AppCompatActivity(), NotificationPermissionDialogListener {
 import com.stoutner.privacycell.services.RealtimeMonitoringService
 
 class SettingsActivity : AppCompatActivity(), NotificationPermissionDialogListener {
+    // Declare the class variables.
+    private lateinit var settingsFragment: SettingsFragment
+
     override fun onCreate(savedInstanceState: Bundle?) {
         // Run the default commands.
         super.onCreate(savedInstanceState)
     override fun onCreate(savedInstanceState: Bundle?) {
         // Run the default commands.
         super.onCreate(savedInstanceState)
@@ -66,8 +69,11 @@ class SettingsActivity : AppCompatActivity(), NotificationPermissionDialogListen
         // Display the home arrow on the action bar.
         actionBar.setDisplayHomeAsUpEnabled(true)
 
         // Display the home arrow on the action bar.
         actionBar.setDisplayHomeAsUpEnabled(true)
 
-        // Load the preferences fragment.
-        supportFragmentManager.beginTransaction().replace(R.id.preferences_framelayout, SettingsFragment()).commit()
+        // Instantiate the settings fragment.
+        settingsFragment = SettingsFragment()
+
+        // Load the settings fragment.
+        supportFragmentManager.beginTransaction().replace(R.id.preferences_framelayout, settingsFragment).commitNow()
     }
 
     override fun onCloseNotificationPermissionDialog() {
     }
 
     override fun onCloseNotificationPermissionDialog() {
@@ -96,6 +102,9 @@ class SettingsActivity : AppCompatActivity(), NotificationPermissionDialogListen
             if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {  // The notification permission was granted.
                 // Start the realtime monitoring service.
                 startService(Intent(this, RealtimeMonitoringService::class.java))
             if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {  // The notification permission was granted.
                 // Start the realtime monitoring service.
                 startService(Intent(this, RealtimeMonitoringService::class.java))
+
+                // Update the realtime monitoring preference summary.
+                settingsFragment.updateRealtimeMonitoringSummary()
             }
         }
     }
             }
         }
     }
index b5acce90fb45e06283ca471915c044a74f364b9f..9adae226fc76d8e34ae1016da741c705b01af433 100644 (file)
@@ -155,6 +155,9 @@ class SettingsFragment : PreferenceFragmentCompat() {
 
         // Re-register the shared preference listener.
         sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener)
 
         // Re-register the shared preference listener.
         sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener)
+
+        // Update the realtime monitoring preference summary.
+        updateRealtimeMonitoringSummary()
     }
 
     private fun getSharedPreferenceChangeListener(): OnSharedPreferenceChangeListener {
     }
 
     private fun getSharedPreferenceChangeListener(): OnSharedPreferenceChangeListener {
@@ -260,4 +263,18 @@ class SettingsFragment : PreferenceFragmentCompat() {
         // Restart the activity after 400 milliseconds, so that the app has enough time to save the change to the preference.
         restartHandler.postDelayed(restartRunnable, 400)
     }
         // Restart the activity after 400 milliseconds, so that the app has enough time to save the change to the preference.
         restartHandler.postDelayed(restartRunnable, 400)
     }
+
+    fun updateRealtimeMonitoringSummary() {
+        // Update the summary according to the API.
+        if (Build.VERSION.SDK_INT >= 33) {  // The API >= 33.
+            // Set the summary according to the notification permission status.
+            if (ActivityCompat.checkSelfPermission(requireContext(), Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED)
+                realtimeMonitoringPreference.summary = getString(R.string.realtime_monitoring_summary)
+            else
+                realtimeMonitoringPreference.summary = (getString(R.string.realtime_monitoring_summary) + " " + getString(R.string.notification_permission_denied))
+        } else {  // The API is < 33.
+            // Set the realtime monitoring summary.
+            realtimeMonitoringPreference.summary = getString(R.string.realtime_monitoring_summary)
+        }
+    }
 }
 }
index 11af7b7fc357718638e46ee3cb4a976d07993361..19e1a3e2cede164c571b6dbc4558801bd5108979 100644 (file)
@@ -148,6 +148,9 @@ class RealtimeMonitoringService : Service() {
             // Set the color.
             notificationBuilder.setColor(getColor(R.color.red_notification_icon))
 
             // Set the color.
             notificationBuilder.setColor(getColor(R.color.red_notification_icon))
 
+            // Prevent swiping to dismiss the notification.
+            notificationBuilder.setOngoing(true)
+
             // Start the foreground notification.
             startForeground(NOTIFICATION_ID, notificationBuilder.build())
 
             // Start the foreground notification.
             startForeground(NOTIFICATION_ID, notificationBuilder.build())
 
@@ -251,6 +254,9 @@ class RealtimeMonitoringService : Service() {
                 // Set the color.
                 antiquatedNetworkNotificationBuilder.setColor(getColor(R.color.red_notification_icon))
 
                 // Set the color.
                 antiquatedNetworkNotificationBuilder.setColor(getColor(R.color.red_notification_icon))
 
+                // Prevent swiping to dismiss the notification.
+                antiquatedNetworkNotificationBuilder.setOngoing(true)
+
                 // Update the notification.
                 notificationManager.notify(NOTIFICATION_ID, antiquatedNetworkNotificationBuilder.build())
 
                 // Update the notification.
                 notificationManager.notify(NOTIFICATION_ID, antiquatedNetworkNotificationBuilder.build())
 
@@ -275,6 +281,9 @@ class RealtimeMonitoringService : Service() {
                 // Set the color.
                 insecureNetworkNotificationBuilder.setColor(getColor(R.color.yellow_notification_icon))
 
                 // Set the color.
                 insecureNetworkNotificationBuilder.setColor(getColor(R.color.yellow_notification_icon))
 
+                // Prevent swiping to dismiss the notification.
+                insecureNetworkNotificationBuilder.setOngoing(true)
+
                 // Update the notification.
                 notificationManager.notify(NOTIFICATION_ID, insecureNetworkNotificationBuilder.build())
 
                 // Update the notification.
                 notificationManager.notify(NOTIFICATION_ID, insecureNetworkNotificationBuilder.build())
 
@@ -299,6 +308,9 @@ class RealtimeMonitoringService : Service() {
                 // Set the color.
                 secureNetworkNotificationBuilder.setColor(getColor(R.color.blue_icon))
 
                 // Set the color.
                 secureNetworkNotificationBuilder.setColor(getColor(R.color.blue_icon))
 
+                // Prevent swiping to dismiss the notification.
+                secureNetworkNotificationBuilder.setOngoing(true)
+
                 // Update the notification.
                 notificationManager.notify(NOTIFICATION_ID, secureNetworkNotificationBuilder.build())
 
                 // Update the notification.
                 notificationManager.notify(NOTIFICATION_ID, secureNetworkNotificationBuilder.build())
 
index 77a6ce584edf535c30e355191f44572052000693..ed21f7e00395c221e4b85b468f61003b1fa291d3 100644 (file)
     <string name="nr_advanced">NR Advanced – 5G</string>
     <string name="nr_advanced_detail">New Radio Advanced</string>
 
     <string name="nr_advanced">NR Advanced – 5G</string>
     <string name="nr_advanced_detail">New Radio Advanced</string>
 
-    <!-- Phone permission dialog. -->
+    <!-- Permission dialogs. -->
     <string name="phone_permission">Telefon-Berechtigung</string>
     <string name="phone_permission_text">Privacy Cell benötigt lesenden Zugriff auf den Status Ihres Telefons, um das Sicherheits-Niveau Ihrer Mobilfunk-Verbindung zu ermitteln.</string>
     <string name="phone_permission">Telefon-Berechtigung</string>
     <string name="phone_permission_text">Privacy Cell benötigt lesenden Zugriff auf den Status Ihres Telefons, um das Sicherheits-Niveau Ihrer Mobilfunk-Verbindung zu ermitteln.</string>
+    <string name="notification_permission">Benachrichtigungs-Berechtigung</string>
+    <string name="notification_permission_text">Privacy Cell benötigt die Benachrichtigungs-Berechtigung, um Benachrichtigungen des Echtzeit-Monitorings anzeigen zu können.</string>
     <string name="ok">OK</string>
 
     <!-- Dialogs. -->
     <string name="ok">OK</string>
 
     <!-- Dialogs. -->
index 2f38a439858032862700ec80ac4956961493c874..7ff040c63b6fcfeb3abdeabae4aa96468735d465 100644 (file)
     <string name="nr_advanced">NR Avanzado – 5G</string>
     <string name="nr_advanced_detail">Nueva Radio Avanzada</string>
 
     <string name="nr_advanced">NR Avanzado – 5G</string>
     <string name="nr_advanced_detail">Nueva Radio Avanzada</string>
 
-    <!-- Phone permission dialog. -->
+    <!-- Permission dialogs. -->
     <string name="phone_permission">Permiso telefónico</string>
     <string name="phone_permission_text">Privacy Cell necesita el permiso del teléfono "Leer estado del teléfono" para determinar el nivel de seguridad de su conexión celular.</string>
     <string name="phone_permission">Permiso telefónico</string>
     <string name="phone_permission_text">Privacy Cell necesita el permiso del teléfono "Leer estado del teléfono" para determinar el nivel de seguridad de su conexión celular.</string>
+    <string name="notification_permission">Permiso de notificación</string>
+    <string name="notification_permission_text">Privacy Cell necesita el permiso Post Notification para mostrar las notificaciones de monitoreo en tiempo real.</string>
     <string name="ok">OK</string>
 
     <!-- Dialogs. -->
     <string name="ok">OK</string>
 
     <!-- Dialogs. -->
index c7b481f72c685bbf2b7614108c66b5737431880f..c10878e99df8f2a2db7ff0d0d82a364fe3b78f0e 100644 (file)
     <string name="nr_advanced">NR Advanced – 5G</string>
     <string name="nr_advanced_detail">New Radio Advanced</string>
 
     <string name="nr_advanced">NR Advanced – 5G</string>
     <string name="nr_advanced_detail">New Radio Advanced</string>
 
-    <!-- Phone permission dialog. -->
+    <!-- Permission dialogs. -->
     <string name="phone_permission">Autorisations</string>
     <string name="phone_permission_text">Privacy Cell a besoin de l\'autorisation READ PHONE STATE pour déterminer le niveau de sécurité de votre connexion cellulaire.</string>
     <string name="phone_permission">Autorisations</string>
     <string name="phone_permission_text">Privacy Cell a besoin de l\'autorisation READ PHONE STATE pour déterminer le niveau de sécurité de votre connexion cellulaire.</string>
+    <string name="notification_permission">Autorisation de notification</string>
+    <string name="notification_permission_text">Privacy Cell a besoin de l\'autorisation Post Notification pour afficher les notifications de surveillance en temps réel.</string>
     <string name="ok">OK</string>
 
     <!-- Dialogs. -->
     <string name="ok">OK</string>
 
     <!-- Dialogs. -->
index b4e0347f86f64bbf168a5027a235d3a8f0e429b2..cea32cee47d6cbf4e247ef31a0b7ee7957911acd 100644 (file)
     <string name="nr_advanced">NR Advanced – 5G</string>
     <string name="nr_advanced_detail">New Radio Advanced</string>
 
     <string name="nr_advanced">NR Advanced – 5G</string>
     <string name="nr_advanced_detail">New Radio Advanced</string>
 
-    <!-- Phone permission dialog. -->
+    <!-- Permission dialogs. -->
     <string name="phone_permission">Autorizzazioni sul dispositivo</string>
     <string name="phone_permission_text">Privacy Cell ha bisogno dell\'autorizzazione di lettura dello stato del telefono per poter determinare il livello si sicurezza della connessione.</string>
     <string name="phone_permission">Autorizzazioni sul dispositivo</string>
     <string name="phone_permission_text">Privacy Cell ha bisogno dell\'autorizzazione di lettura dello stato del telefono per poter determinare il livello si sicurezza della connessione.</string>
+    <string name="notification_permission">Autorizzazione per le notifiche</string>
+    <string name="notification_permission_text">Privacy Cell ha bisogno dell\'autorizzazione "Post Notification" per mostrare le notifiche del monitoraggio in tempo reale.</string>
     <string name="ok">OK</string>
 
     <!-- Dialogs. -->
     <string name="ok">OK</string>
 
     <!-- Dialogs. -->
index b073e5e7c095ce7bcebdbb8ff86e28031683964a..97855a8e9aa0cda25c9be702bcb3aa96389b4031 100644 (file)
     <string name="nr_advanced">NR усовершенствованное – 5G</string>
     <string name="nr_advanced_detail">Новое радио усовершенствованное</string>
 
     <string name="nr_advanced">NR усовершенствованное – 5G</string>
     <string name="nr_advanced_detail">Новое радио усовершенствованное</string>
 
-    <!-- Phone permission dialog. -->
+    <!-- Permission dialogs. -->
     <string name="phone_permission">Разрешение телефона</string>
     <string name="phone_permission_text">Privacy Cell необходимо разрешение на чтение состояния телефона для определения степени безопасности вашего мобильного подключения.</string>
     <string name="phone_permission">Разрешение телефона</string>
     <string name="phone_permission_text">Privacy Cell необходимо разрешение на чтение состояния телефона для определения степени безопасности вашего мобильного подключения.</string>
+    <string name="notification_permission">Разрешение на уведомления</string>
+    <string name="notification_permission_text">Privacy Cell требуется разрешение на отправку уведомлений для отображения уведомлений мониторинга в реальном времени.</string>
     <string name="ok">OK</string>
 
     <!-- Dialogs. -->
     <string name="ok">OK</string>
 
     <!-- Dialogs. -->
index 22281a1230229f1cc82ab5996bc5476710aaeebc..2b47728db771cf408b11f27fbb907c568d2d81f4 100644 (file)
     <string name="nr_advanced">NR Advanced – 5G</string>
     <string name="nr_advanced_detail">New Radio Advanced</string>
 
     <string name="nr_advanced">NR Advanced – 5G</string>
     <string name="nr_advanced_detail">New Radio Advanced</string>
 
-    <!-- Permission dialog. -->
+    <!-- Permission dialogs. -->
     <string name="phone_permission">Phone Permission</string>
     <string name="phone_permission_text">Privacy Cell needs the Read Phone State permission to determine the safety level of your cell connection.</string>
     <string name="notification_permission">Notification Permission</string>
     <string name="phone_permission">Phone Permission</string>
     <string name="phone_permission_text">Privacy Cell needs the Read Phone State permission to determine the safety level of your cell connection.</string>
     <string name="notification_permission">Notification Permission</string>
     <string name="monitoring">Monitoring</string>
     <string name="realtime_monitoring">Realtime monitoring</string>
     <string name="realtime_monitoring_summary">Place an icon in the status bar that monitors the cell network.</string>
     <string name="monitoring">Monitoring</string>
     <string name="realtime_monitoring">Realtime monitoring</string>
     <string name="realtime_monitoring_summary">Place an icon in the status bar that monitors the cell network.</string>
+        <string name="notification_permission_denied">The Post Notification permission is currently denied, so no notifications will be displayed.</string>
     <string name="secure_network_notification">Secure network notification</string>
     <string name="insecure_network_notification">Insecure network notification</string>
     <string name="antiquated_network_notification">Antiquated network notification</string>
     <string name="secure_network_notification">Secure network notification</string>
     <string name="insecure_network_notification">Insecure network notification</string>
     <string name="antiquated_network_notification">Antiquated network notification</string>
index 95d0515bec31ebaf2ea8740e3479b3656f1e3f38..d49d9b65b22de88d7305100fbff73b75b1a0ea8f 100644 (file)
@@ -28,7 +28,6 @@
         <SwitchPreferenceCompat
             app:key="@string/realtime_monitoring_key"
             app:title="@string/realtime_monitoring"
         <SwitchPreferenceCompat
             app:key="@string/realtime_monitoring_key"
             app:title="@string/realtime_monitoring"
-            app:summary="@string/realtime_monitoring_summary"
             app:defaultValue="false" />
 
         <Preference
             app:defaultValue="false" />
 
         <Preference