Created
June 22, 2021 09:27
-
-
Save abos3d/aaacde5b7d7650aa8178792272947f57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.cleanarchitectkotlinflowhiltsimplestway.presentation.splash | |
import androidx.lifecycle.ViewModel | |
import com.cleanarchitectkotlinflowhiltsimplestway.domain.SampleUseCase | |
import com.cleanarchitectkotlinflowhiltsimplestway.presentation.State | |
import com.cleanarchitectkotlinflowhiltsimplestway.utils.Utils | |
import dagger.hilt.android.lifecycle.HiltViewModel | |
import kotlinx.coroutines.delay | |
import kotlinx.coroutines.flow.flow | |
import javax.inject.Inject | |
@HiltViewModel | |
class SplashActivityViewModel @Inject constructor(private val sampleUseCase: SampleUseCase) : | |
ViewModel() { | |
fun getSampleResponse() = flow { | |
emit(State.LoadingState) | |
try { | |
delay(1000) | |
emit(State.DataState(sampleUseCase())) | |
} catch (e: Exception) { | |
e.printStackTrace() | |
emit(Utils.resolveError(e)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment