30 lines
935 B
Kotlin
30 lines
935 B
Kotlin
|
|
package com.longnh15.heimdall
|
||
|
|
|
||
|
|
import androidx.lifecycle.ViewModel
|
||
|
|
import androidx.lifecycle.viewModelScope
|
||
|
|
import com.longnh15.heimdall.data.preferences.PreferenceDataSource
|
||
|
|
import kotlinx.coroutines.flow.SharingStarted
|
||
|
|
import kotlinx.coroutines.flow.StateFlow
|
||
|
|
import kotlinx.coroutines.flow.map
|
||
|
|
import kotlinx.coroutines.flow.stateIn
|
||
|
|
import kotlinx.coroutines.launch
|
||
|
|
import org.koin.core.annotation.KoinViewModel
|
||
|
|
|
||
|
|
@KoinViewModel
|
||
|
|
class MainViewModel (
|
||
|
|
private val preferenceDataSource: PreferenceDataSource
|
||
|
|
) : ViewModel() {
|
||
|
|
val isFirstLaunch: StateFlow<Boolean?> = preferenceDataSource.preferences
|
||
|
|
.map { it.isFirstLaunch }
|
||
|
|
.stateIn(
|
||
|
|
scope = viewModelScope,
|
||
|
|
started = SharingStarted.WhileSubscribed(5000),
|
||
|
|
initialValue = null
|
||
|
|
)
|
||
|
|
|
||
|
|
fun onCompleteOnboarding() {
|
||
|
|
viewModelScope.launch {
|
||
|
|
preferenceDataSource.setFirstLaunchDone()
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|