2026-06-09 16:27:40 +07:00
|
|
|
package com.longnh15.heimdall
|
|
|
|
|
|
|
|
|
|
import androidx.lifecycle.ViewModel
|
|
|
|
|
import androidx.lifecycle.viewModelScope
|
|
|
|
|
import com.longnh15.heimdall.data.preferences.PreferenceDataSource
|
2026-06-17 16:19:10 +07:00
|
|
|
import com.longnh15.heimdall.data.source.local.LocalDataSource
|
2026-06-09 16:27:40 +07:00
|
|
|
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 (
|
2026-06-17 16:19:10 +07:00
|
|
|
private val preferenceDataSource: PreferenceDataSource,
|
|
|
|
|
private val localDataSource: LocalDataSource
|
2026-06-09 16:27:40 +07:00
|
|
|
) : ViewModel() {
|
|
|
|
|
val isFirstLaunch: StateFlow<Boolean?> = preferenceDataSource.preferences
|
|
|
|
|
.map { it.isFirstLaunch }
|
|
|
|
|
.stateIn(
|
|
|
|
|
scope = viewModelScope,
|
|
|
|
|
started = SharingStarted.WhileSubscribed(5000),
|
|
|
|
|
initialValue = null
|
|
|
|
|
)
|
|
|
|
|
|
2026-06-17 16:19:10 +07:00
|
|
|
val token: StateFlow<String?> = localDataSource.token
|
|
|
|
|
.map { it.orEmpty() }
|
|
|
|
|
.stateIn(
|
|
|
|
|
scope = viewModelScope,
|
|
|
|
|
started = SharingStarted.WhileSubscribed(5000),
|
|
|
|
|
initialValue = null
|
|
|
|
|
)
|
|
|
|
|
|
2026-06-09 16:27:40 +07:00
|
|
|
fun onCompleteOnboarding() {
|
|
|
|
|
viewModelScope.launch {
|
|
|
|
|
preferenceDataSource.setFirstLaunchDone()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|