// 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)
+ }
+ }
}