public class MainViewModel extends AndroidViewModel { | |
private LiveData<List<StarWarsMovie>> moviesLiveData; | |
@Inject AppDatabase mDb; | |
public MainViewModel(Application application) { | |
super(application); | |
((StarWarsApplication) getApplication()).getAppComponent().inject(this); | |
requestDataUpdates(); | |
subscribeToDbChanges(); | |
} | |
private void requestDataUpdates() { | |
Intent serviceIntent = new Intent(this.getApplication(), StarWarsService.class); | |
getApplication().startService(serviceIntent); | |
} | |
private void subscribeToDbChanges() { | |
moviesLiveData = mDb.starWarsMovieModel().loadMovies(); | |
} | |
public LiveData<List<StarWarsMovie>> getMoviesLiveData() { | |
return moviesLiveData; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment