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)
// 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() {
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()
}
}
}
// Re-register the shared preference listener.
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener)
+
+ // Update the realtime monitoring preference summary.
+ updateRealtimeMonitoringSummary()
}
private fun getSharedPreferenceChangeListener(): OnSharedPreferenceChangeListener {
// 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)
+ }
+ }
}
// 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())
// 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())
// 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())
// 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())
<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="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="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="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="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="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="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="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="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="notification_permission">Разрешение на уведомления</string>
+ <string name="notification_permission_text">Privacy Cell требуется разрешение на отправку уведомлений для отображения уведомлений мониторинга в реальном времени.</string>
<string name="ok">OK</string>
<!-- Dialogs. -->
<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="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>
<SwitchPreferenceCompat
app:key="@string/realtime_monitoring_key"
app:title="@string/realtime_monitoring"
- app:summary="@string/realtime_monitoring_summary"
app:defaultValue="false" />
<Preference