Skip to content

Commit 358ee16

Browse files
ovitrifclaude
andcommitted
refactor: restore ToastQueue provider for testability
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 24658f2 commit 358ee16

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ 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.ToastQueue
810
import javax.inject.Singleton
911

1012
@Module
1113
@InstallIn(SingletonComponent::class)
1214
object ViewModelModule {
1315
@Singleton
1416
@Provides
15-
fun provideFirebaseMessaging(): FirebaseMessaging {
16-
return FirebaseMessaging.getInstance()
17-
}
17+
fun provideFirebaseMessaging(): FirebaseMessaging = FirebaseMessaging.getInstance()
18+
19+
@Provides
20+
fun provideToastQueueProvider(): (CoroutineScope) -> ToastQueue = { ToastQueue(it) }
1821
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class AppViewModel @Inject constructor(
127127
connectivityRepo: ConnectivityRepo,
128128
healthRepo: HealthRepo,
129129
timedSheetManagerProvider: @JvmSuppressWildcards (CoroutineScope) -> TimedSheetManager,
130+
toastQueueProvider: @JvmSuppressWildcards (CoroutineScope) -> ToastQueue,
130131
private val toaster: Toaster,
131132
@ApplicationContext private val context: Context,
132133
@BgDispatcher private val bgDispatcher: CoroutineDispatcher,
@@ -1780,7 +1781,7 @@ class AppViewModel @Inject constructor(
17801781
// endregion
17811782

17821783
// region Toasts
1783-
private val toastQueue = ToastQueue(viewModelScope)
1784+
private val toastQueue = toastQueueProvider(viewModelScope)
17841785
val currentToast: StateFlow<Toast?> = toastQueue.currentToast
17851786

17861787
fun hideToast() = toastQueue.dismissCurrentToast()

0 commit comments

Comments
 (0)