mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-08-31 14:25:28 +00:00
app: lazily initialize hiltEntryPoint to make sure that activity is available before we use appContext
Signed-off-by: Aditya Wasan <adityawasan55@gmail.com>
This commit is contained in:
committed by
Harsh Shandilya
parent
1ae961e51c
commit
1583c4c600
@@ -42,13 +42,12 @@ import dev.msfjarvis.aps.util.settings.PreferenceKeys
|
|||||||
|
|
||||||
class RepositorySettings(private val activity: FragmentActivity) : SettingsProvider {
|
class RepositorySettings(private val activity: FragmentActivity) : SettingsProvider {
|
||||||
|
|
||||||
private val hiltEntryPoint =
|
private val hiltEntryPoint by lazy(LazyThreadSafetyMode.NONE) {
|
||||||
EntryPointAccessors.fromApplication(
|
EntryPointAccessors.fromApplication(
|
||||||
activity.applicationContext,
|
activity.applicationContext,
|
||||||
RepositorySettingsEntryPoint::class.java,
|
RepositorySettingsEntryPoint::class.java,
|
||||||
)
|
)
|
||||||
private val encryptedPreferences = hiltEntryPoint.encryptedPreferences()
|
}
|
||||||
private val gitSettings = hiltEntryPoint.gitSettings()
|
|
||||||
|
|
||||||
private fun <T : FragmentActivity> launchActivity(clazz: Class<T>) {
|
private fun <T : FragmentActivity> launchActivity(clazz: Class<T>) {
|
||||||
activity.startActivity(Intent(activity, clazz))
|
activity.startActivity(Intent(activity, clazz))
|
||||||
@@ -66,6 +65,9 @@ class RepositorySettings(private val activity: FragmentActivity) : SettingsProvi
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun provideSettings(builder: PreferenceScreen.Builder) {
|
override fun provideSettings(builder: PreferenceScreen.Builder) {
|
||||||
|
val encryptedPreferences = hiltEntryPoint.encryptedPreferences()
|
||||||
|
val gitSettings = hiltEntryPoint.gitSettings()
|
||||||
|
|
||||||
builder.apply {
|
builder.apply {
|
||||||
checkBox(PreferenceKeys.REBASE_ON_PULL) {
|
checkBox(PreferenceKeys.REBASE_ON_PULL) {
|
||||||
titleRes = R.string.pref_rebase_on_pull_title
|
titleRes = R.string.pref_rebase_on_pull_title
|
||||||
|
@@ -34,14 +34,14 @@ class GitCommandExecutor(
|
|||||||
private val operation: GitOperation,
|
private val operation: GitOperation,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val hiltEntryPoint =
|
private val hiltEntryPoint by lazy(LazyThreadSafetyMode.NONE) {
|
||||||
EntryPointAccessors.fromApplication(
|
EntryPointAccessors.fromApplication(
|
||||||
activity.applicationContext,
|
activity.applicationContext,
|
||||||
GitCommandExecutorEntryPoint::class.java
|
GitCommandExecutorEntryPoint::class.java
|
||||||
)
|
)
|
||||||
private val gitSettings = hiltEntryPoint.gitSettings()
|
}
|
||||||
|
|
||||||
suspend fun execute(): Result<Unit, Throwable> {
|
suspend fun execute(): Result<Unit, Throwable> {
|
||||||
|
val gitSettings = hiltEntryPoint.gitSettings()
|
||||||
val snackbar =
|
val snackbar =
|
||||||
activity.snackbar(
|
activity.snackbar(
|
||||||
message = activity.resources.getString(R.string.git_operation_running),
|
message = activity.resources.getString(R.string.git_operation_running),
|
||||||
@@ -126,6 +126,7 @@ class GitCommandExecutor(
|
|||||||
@EntryPoint
|
@EntryPoint
|
||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
interface GitCommandExecutorEntryPoint {
|
interface GitCommandExecutorEntryPoint {
|
||||||
|
|
||||||
fun gitSettings(): GitSettings
|
fun gitSettings(): GitSettings
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user