Fix potential context crash + update deps

This commit is contained in:
Oizaro 2022-02-09 22:17:39 +01:00
parent d3092c4579
commit 8a0361ea5e
2 changed files with 11 additions and 9 deletions

View File

@ -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

View File

@ -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() {
lifecycleScope.launchWhenResumed {
val appContext = requireContext().applicationContext
val context = requireContext()
lifecycleScope.launchWhenResumed {
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