I have a view with three states:
sealed class MainState(val movieList: List<Movie>) {
class Loading(movies: List<Movie> = emptyList()) : MainState(movies)
class Success(movies: List<Movie>) : MainState(movies)
class Error(val throwable: Throwable, movies: List<Movie> = emptyList()) : MainState(movies)
}
These states are wrapped in a MutableLiveData
and managed by a ViewModel
:
class MovieListViewModel(private val movieRepo: MovieRepository) : ViewModel() {
val stateLiveData = MutableLiveData<MainState>()
.
.
}
I want to integrate the query liveData to my state liveDate so that when query liveData is updated to movieList, state liveData updates to Success(movieList)
. How can I acheive that?
Here's how my live query looks like:
@Dao
interface MovieDAO {
@Query("SELECT * FROM Movie")
fun getAllMovies(): LiveData<List<Movie>>
}