40 lines
1.3 KiB
Kotlin
40 lines
1.3 KiB
Kotlin
package com.longnh15.heimdall
|
|
|
|
import androidx.lifecycle.ViewModel
|
|
import androidx.lifecycle.viewModelScope
|
|
import com.longnh15.heimdall.data.preferences.PreferenceDataSource
|
|
import com.longnh15.heimdall.data.source.local.LocalDataSource
|
|
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,
|
|
private val localDataSource: LocalDataSource
|
|
) : ViewModel() {
|
|
val isFirstLaunch: StateFlow<Boolean?> = preferenceDataSource.preferences
|
|
.map { it.isFirstLaunch }
|
|
.stateIn(
|
|
scope = viewModelScope,
|
|
started = SharingStarted.WhileSubscribed(5000),
|
|
initialValue = null
|
|
)
|
|
|
|
val token: StateFlow<String?> = localDataSource.token
|
|
.map { it.orEmpty() }
|
|
.stateIn(
|
|
scope = viewModelScope,
|
|
started = SharingStarted.WhileSubscribed(5000),
|
|
initialValue = null
|
|
)
|
|
|
|
fun onCompleteOnboarding() {
|
|
viewModelScope.launch {
|
|
preferenceDataSource.setFirstLaunchDone()
|
|
}
|
|
}
|
|
} |