From 1583c4c60002cb44d863fa7ebe792c68dd153901 Mon Sep 17 00:00:00 2001 From: Aditya Wasan Date: Sat, 22 May 2021 18:23:14 +0530 Subject: app: lazily initialize hiltEntryPoint to make sure that activity is available before we use appContext Signed-off-by: Aditya Wasan --- .../main/java/dev/msfjarvis/aps/ui/settings/RepositorySettings.kt | 8 +++++--- .../main/java/dev/msfjarvis/aps/util/git/GitCommandExecutor.kt | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/settings/RepositorySettings.kt b/app/src/main/java/dev/msfjarvis/aps/ui/settings/RepositorySettings.kt index 86b57533..d571d962 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/settings/RepositorySettings.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/settings/RepositorySettings.kt @@ -42,13 +42,12 @@ import dev.msfjarvis.aps.util.settings.PreferenceKeys class RepositorySettings(private val activity: FragmentActivity) : SettingsProvider { - private val hiltEntryPoint = + private val hiltEntryPoint by lazy(LazyThreadSafetyMode.NONE) { EntryPointAccessors.fromApplication( activity.applicationContext, RepositorySettingsEntryPoint::class.java, ) - private val encryptedPreferences = hiltEntryPoint.encryptedPreferences() - private val gitSettings = hiltEntryPoint.gitSettings() + } private fun launchActivity(clazz: Class) { activity.startActivity(Intent(activity, clazz)) @@ -66,6 +65,9 @@ class RepositorySettings(private val activity: FragmentActivity) : SettingsProvi } override fun provideSettings(builder: PreferenceScreen.Builder) { + val encryptedPreferences = hiltEntryPoint.encryptedPreferences() + val gitSettings = hiltEntryPoint.gitSettings() + builder.apply { checkBox(PreferenceKeys.REBASE_ON_PULL) { titleRes = R.string.pref_rebase_on_pull_title diff --git a/app/src/main/java/dev/msfjarvis/aps/util/git/GitCommandExecutor.kt b/app/src/main/java/dev/msfjarvis/aps/util/git/GitCommandExecutor.kt index be0527a2..54e1e2e5 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/git/GitCommandExecutor.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/git/GitCommandExecutor.kt @@ -34,14 +34,14 @@ class GitCommandExecutor( private val operation: GitOperation, ) { - private val hiltEntryPoint = + private val hiltEntryPoint by lazy(LazyThreadSafetyMode.NONE) { EntryPointAccessors.fromApplication( activity.applicationContext, GitCommandExecutorEntryPoint::class.java ) - private val gitSettings = hiltEntryPoint.gitSettings() - + } suspend fun execute(): Result { + val gitSettings = hiltEntryPoint.gitSettings() val snackbar = activity.snackbar( message = activity.resources.getString(R.string.git_operation_running), @@ -126,6 +126,7 @@ class GitCommandExecutor( @EntryPoint @InstallIn(SingletonComponent::class) interface GitCommandExecutorEntryPoint { + fun gitSettings(): GitSettings } } -- cgit v1.2.3