Created
May 12, 2017 10:30
-
-
Save parahall/f17e95680b7261500c484a7a4eac3185 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
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