diff options
author | Aditya Wasan <adityawasan55@gmail.com> | 2021-05-22 18:23:14 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2021-05-22 20:05:55 +0530 |
commit | 1583c4c60002cb44d863fa7ebe792c68dd153901 (patch) | |
tree | 0bc9ccb5a51ff07c328a7ea90c3945aec7a1148f /app/src | |
parent | 1ae961e51c3c6ac37126ede89fd1dccce9f2e0a2 (diff) |
app: lazily initialize hiltEntryPoint to make sure that activity is available before we use appContext
Signed-off-by: Aditya Wasan <adityawasan55@gmail.com>
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/dev/msfjarvis/aps/ui/settings/RepositorySettings.kt | 8 | ||||
-rw-r--r-- | app/src/main/java/dev/msfjarvis/aps/util/git/GitCommandExecutor.kt | 7 |
2 files changed, 9 insertions, 6 deletions
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 <T : FragmentActivity> launchActivity(clazz: Class<T>) { 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<Unit, Throwable> { + 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 } } |