From 8a0361ea5e3469247db52d11a799360d82b729e3 Mon Sep 17 00:00:00 2001 From: Oizaro <98434320+Oizaro@users.noreply.github.com> Date: Wed, 9 Feb 2022 22:17:39 +0100 Subject: [PATCH] Fix potential context crash + update deps --- gradle/wrapper/gradle-wrapper.properties | 4 ++-- .../ui/PushNotificationPreferencesFragment.kt | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 942d8725..7dadbcd5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Jan 26 02:00:21 CET 2022 +#Wed Feb 09 22:14:11 CET 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationPreferencesFragment.kt b/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationPreferencesFragment.kt index e9b4291f..79f6d575 100755 --- a/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationPreferencesFragment.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationPreferencesFragment.kt @@ -69,8 +69,9 @@ class PushNotificationPreferencesFragment : PreferenceFragmentCompat() { private fun updateStatus() { try { handler.postDelayed(updateRunnable, UPDATE_INTERVAL) + val appContext = requireContext().applicationContext lifecycleScope.launchWhenStarted { - val statusInfo = getGcmServiceInfo(requireContext()) + val statusInfo = getGcmServiceInfo(appContext) pushStatusCategory.isVisible = statusInfo.configuration.enabled pushStatus.summary = if (statusInfo.connected) { getString(R.string.gcm_network_state_connected, DateUtils.getRelativeTimeSpanString(statusInfo.startTimestamp, System.currentTimeMillis(), 0)) @@ -82,21 +83,22 @@ class PushNotificationPreferencesFragment : PreferenceFragmentCompat() { } private fun updateContent() { + val appContext = requireContext().applicationContext + val context = requireContext() lifecycleScope.launchWhenResumed { - val context = requireContext() val (apps, showAll) = withContext(Dispatchers.IO) { val apps = database.appList.sortedByDescending { it.lastMessageTimestamp } val res = apps.map { app -> - app to context.packageManager.getApplicationInfoIfExists(app.packageName) + app to appContext.packageManager.getApplicationInfoIfExists(app.packageName) }.mapNotNull { (app, info) -> if (info == null) null else app to info }.take(3).mapIndexed { idx, (app, applicationInfo) -> - val pref = AppIconPreference(context) + val pref = AppIconPreference(appContext) pref.order = idx - pref.title = applicationInfo.loadLabel(context.packageManager) - pref.icon = applicationInfo.loadIcon(context.packageManager) + pref.title = applicationInfo.loadLabel(appContext.packageManager) + pref.icon = applicationInfo.loadIcon(appContext.packageManager) pref.onPreferenceClickListener = Preference.OnPreferenceClickListener { - findNavController().navigate(requireContext(), R.id.openGcmAppDetails, bundleOf( + findNavController().navigate(context, R.id.openGcmAppDetails, bundleOf( "package" to app.packageName )) true