From 05d18bb8d26d74f24db6111516ae0de8618afc54 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Wed, 8 Dec 2021 11:03:11 +0100 Subject: [PATCH] Do not use application context when requesting resources Application context is not properly themed, resulting in ugly UI on some devices --- .../org/microg/gms/ui/PushNotificationAllAppsFragment.kt | 2 +- .../org/microg/gms/ui/PushNotificationAppFragment.kt | 6 +++--- .../src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt | 8 ++++---- .../nearby/core/ui/ExposureNotificationsAppFragment.kt | 6 +++--- .../core/ui/ExposureNotificationsPreferencesFragment.kt | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationAllAppsFragment.kt b/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationAllAppsFragment.kt index 91cac572..3be5ae4f 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationAllAppsFragment.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationAllAppsFragment.kt @@ -52,7 +52,7 @@ class PushNotificationAllAppsFragment : PreferenceFragmentCompat() { } private fun updateContent() { - val context = requireContext().applicationContext + val context = requireContext() lifecycleScope.launchWhenResumed { val apps = withContext(Dispatchers.IO) { val res = database.appList.map { app -> diff --git a/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationAppFragment.kt b/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationAppFragment.kt index 28cd3b55..6c654344 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationAppFragment.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationAppFragment.kt @@ -46,13 +46,13 @@ class PushNotificationAppFragment : Fragment(R.layout.push_notification_fragment override fun onResume() { super.onResume() - val appContext = requireContext().applicationContext + val context = requireContext() lifecycleScope.launchWhenResumed { - val pm = appContext.packageManager + val pm = context.packageManager val applicationInfo = pm.getApplicationInfoIfExists(packageName) binding.appName = applicationInfo?.loadLabel(pm)?.toString() ?: packageName binding.appIcon = applicationInfo?.loadIcon(pm) - ?: AppCompatResources.getDrawable(appContext, android.R.mipmap.sym_def_app_icon) + ?: AppCompatResources.getDrawable(context, android.R.mipmap.sym_def_app_icon) } } } diff --git a/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt b/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt index b05bcb16..cdeb2007 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt @@ -51,9 +51,9 @@ class SettingsFragment : ResourceSettingsFragment() { override fun onResume() { super.onResume() - val appContext = requireContext().applicationContext + val context = requireContext() lifecycleScope.launchWhenResumed { - updateDetails(appContext) + updateDetails(context) } } @@ -63,7 +63,7 @@ class SettingsFragment : ResourceSettingsFragment() { val database = GcmDatabase(context) val regCount = database.registrationList.size database.close() - findPreference(PREF_GCM)!!.summary = getString(R.string.service_status_enabled_short) + " - " + resources.getQuantityString(R.plurals.gcm_registered_apps_counter, regCount, regCount) + findPreference(PREF_GCM)!!.summary = context.getString(R.string.service_status_enabled_short) + " - " + context.resources.getQuantityString(R.plurals.gcm_registered_apps_counter, regCount, regCount) } else { findPreference(PREF_GCM)!!.setSummary(R.string.service_status_disabled_short) } @@ -72,7 +72,7 @@ class SettingsFragment : ResourceSettingsFragment() { findPreference(PREF_SNET)!!.setSummary(if (getSafetyNetServiceInfo(context).configuration.enabled) R.string.service_status_enabled_short else R.string.service_status_disabled_short) val backendCount = UnifiedLocationClient[context].getLocationBackends().size + UnifiedLocationClient[context].getGeocoderBackends().size - findPreference(PREF_UNIFIEDNLP)!!.summary = resources.getQuantityString(R.plurals.pref_unifiednlp_summary, backendCount, backendCount) + findPreference(PREF_UNIFIEDNLP)!!.summary = context.resources.getQuantityString(R.plurals.pref_unifiednlp_summary, backendCount, backendCount) findPreference(PREF_EXPOSURE)?.isVisible = NearbyPreferencesIntegration.isAvailable findPreference(PREF_EXPOSURE)?.icon = NearbyPreferencesIntegration.getIcon(context) diff --git a/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsAppFragment.kt b/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsAppFragment.kt index 15e95ad0..c2f1ce70 100644 --- a/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsAppFragment.kt +++ b/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsAppFragment.kt @@ -40,13 +40,13 @@ class ExposureNotificationsAppFragment : Fragment(R.layout.exposure_notification override fun onResume() { super.onResume() - val appContext = requireContext().applicationContext + val context = requireContext() lifecycleScope.launchWhenResumed { - val pm = appContext.packageManager + val pm = context.packageManager val applicationInfo = pm.getApplicationInfoIfExists(packageName) binding.appName = applicationInfo?.loadLabel(pm)?.toString() ?: packageName binding.appIcon = applicationInfo?.loadIcon(pm) - ?: AppCompatResources.getDrawable(appContext, android.R.mipmap.sym_def_app_icon) + ?: AppCompatResources.getDrawable(context, android.R.mipmap.sym_def_app_icon) } } } diff --git a/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsPreferencesFragment.kt b/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsPreferencesFragment.kt index df0731ff..ec89883c 100644 --- a/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsPreferencesFragment.kt +++ b/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsPreferencesFragment.kt @@ -120,7 +120,7 @@ class ExposureNotificationsPreferencesFragment : PreferenceFragmentCompat() { } private fun updateContent() { - val context = requireContext().applicationContext + val context = requireContext() lifecycleScope.launchWhenResumed { handler.postDelayed(updateContentRunnable, UPDATE_CONTENT_INTERVAL) val (apps, lastHourKeys, currentId) = ExposureDatabase.with(context) { database ->