Skip to content

Instantly share code, notes, and snippets.

@abos3d
Created June 22, 2021 09:27
Show Gist options
  • Save abos3d/aaacde5b7d7650aa8178792272947f57 to your computer and use it in GitHub Desktop.
Save abos3d/aaacde5b7d7650aa8178792272947f57 to your computer and use it in GitHub Desktop.
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