From f3b11d0e81caf1b7691a08b15e1b21ba0ff3bfa1 Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Thu, 10 Oct 2024 15:14:51 +0200 Subject: [PATCH] refactor: Lazy load preferences to prevent crash (#993) Without this the values are loaded from sharedPreferencesRepository before the variable is initialised. --- .../java/app/pachli/components/account/AccountActivity.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/app/pachli/components/account/AccountActivity.kt b/app/src/main/java/app/pachli/components/account/AccountActivity.kt index 61c7abb9d..cee99f73a 100644 --- a/app/src/main/java/app/pachli/components/account/AccountActivity.kt +++ b/app/src/main/java/app/pachli/components/account/AccountActivity.kt @@ -66,6 +66,7 @@ import app.pachli.core.common.extensions.hide import app.pachli.core.common.extensions.show import app.pachli.core.common.extensions.viewBinding import app.pachli.core.common.extensions.visible +import app.pachli.core.common.util.unsafeLazy import app.pachli.core.database.model.AccountEntity import app.pachli.core.designsystem.R as DR import app.pachli.core.navigation.AccountActivityIntent @@ -151,8 +152,8 @@ class AccountActivity : private var subscribing: Boolean = false private var loadedAccount: Account? = null - private var animateAvatar: Boolean = sharedPreferencesRepository.animateAvatars - private var animateEmojis: Boolean = sharedPreferencesRepository.animateEmojis + private val animateAvatar by unsafeLazy { sharedPreferencesRepository.animateAvatars } + private val animateEmojis by unsafeLazy { sharedPreferencesRepository.animateEmojis } // fields for scroll animation private var hideFab: Boolean = false