Coverage Summary for Class: UserSelectedSounds (com.vsevolodganin.clicktrack.soundlibrary)

Class Method, % Branch, % Line, % Instruction, %
UserSelectedSounds 0% (0/3) 0% (0/2) 0% (0/12) 0% (0/42)
UserSelectedSounds$soundsById$$inlined$map$1 0% (0/2)
UserSelectedSounds$soundsById$$inlined$map$1$2 0% (0/1)
UserSelectedSounds$soundsById$$inlined$map$1$2$1
UserSelectedSounds$special$$inlined$flatMapLatest$1 0% (0/1)
Total 0% (0/7) 0% (0/2) 0% (0/12) 0% (0/42)


 package com.vsevolodganin.clicktrack.soundlibrary
 
 import com.vsevolodganin.clicktrack.di.component.ApplicationScope
 import com.vsevolodganin.clicktrack.model.ClickSounds
 import com.vsevolodganin.clicktrack.model.ClickSoundsId
 import com.vsevolodganin.clicktrack.storage.ClickSoundsRepository
 import com.vsevolodganin.clicktrack.storage.UserPreferencesRepository
 import kotlinx.coroutines.DelicateCoroutinesApi
 import kotlinx.coroutines.ExperimentalCoroutinesApi
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.SharingStarted
 import kotlinx.coroutines.flow.StateFlow
 import kotlinx.coroutines.flow.flatMapLatest
 import kotlinx.coroutines.flow.flowOf
 import kotlinx.coroutines.flow.map
 import kotlinx.coroutines.flow.stateIn
 import me.tatarka.inject.annotations.Inject
 
 @ApplicationScope
 @Inject
 class UserSelectedSounds(
     userPreferencesRepository: UserPreferencesRepository,
     private val clickSoundsRepository: ClickSoundsRepository,
 ) {
     @OptIn(ExperimentalCoroutinesApi::class, DelicateCoroutinesApi::class)
     private val cached = userPreferencesRepository.selectedSoundsId.flow
         .flatMapLatest(::soundsById)
         .stateIn(
             scope = GlobalScope,
             started = SharingStarted.Eagerly,
             initialValue = null,
         )
 
     fun get(): StateFlow<ClickSounds?> = cached
 
     private fun soundsById(soundsId: ClickSoundsId): Flow<ClickSounds?> {
         return when (soundsId) {
             is ClickSoundsId.Builtin -> flowOf(soundsId.value.sounds)
             is ClickSoundsId.Database -> clickSoundsRepository.getById(soundsId).map { it?.value }
         }
     }
 }