Skip to content

Commit 2944047

Browse files
committed
refactor: dependency injection
1 parent 6797a63 commit 2944047

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

app/src/main/java/to/bitkit/di/ViewModelModule.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import dagger.Module
55
import dagger.Provides
66
import dagger.hilt.InstallIn
77
import dagger.hilt.components.SingletonComponent
8+
import kotlinx.coroutines.CoroutineScope
9+
import to.bitkit.ui.shared.toast.ToastQueueManager
810
import javax.inject.Singleton
911

1012
@Module
@@ -15,4 +17,9 @@ object ViewModelModule {
1517
fun provideFirebaseMessaging(): FirebaseMessaging {
1618
return FirebaseMessaging.getInstance()
1719
}
20+
21+
@Provides
22+
fun provideToastManagerProvider(): (CoroutineScope) -> ToastQueueManager {
23+
return ::ToastQueueManager
24+
}
1825
}

app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class AppViewModel @Inject constructor(
126126
private val appUpdaterService: AppUpdaterService,
127127
private val notifyPaymentReceivedHandler: NotifyPaymentReceivedHandler,
128128
private val cacheStore: CacheStore,
129+
private val toastManagerProvider: @JvmSuppressWildcards (CoroutineScope) -> ToastQueueManager,
129130
) : ViewModel() {
130131
val healthState = healthRepo.healthState
131132

@@ -1522,7 +1523,7 @@ class AppViewModel @Inject constructor(
15221523
// endregion
15231524

15241525
// region Toasts
1525-
private val toastManager = ToastQueueManager(viewModelScope)
1526+
private val toastManager = toastManagerProvider(viewModelScope)
15261527
val currentToast: StateFlow<Toast?> = toastManager.currentToast
15271528

15281529
fun toast(

0 commit comments

Comments
 (0)