Skip to content

Instantly share code, notes, and snippets.

Last active November 19, 2016 06:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Concrete implementation to load tasks from data source to the cache
import android.database.Cursor;
* Concrete implementation to load tasks from data source to the cache
public class ChallengesRepo implements ChallengesDataStore {
private static ChallengesRepo instance = null;
private final ChallengesRemoteDataSource mChallengesRemoteDataSource;
private final ChallengesLocalDataStore mChallengesLocalDataStore;
// prevent direct instantiation
private ChallengesRepo(@NonNull ChallengesRemoteDataSource challengesRemoteDataSource,
ChallengesLocalDataStore challengesLocalDataStore) {
this.mChallengesRemoteDataSource = challengesRemoteDataSource;
this.mChallengesLocalDataStore = challengesLocalDataStore;
public static ChallengesRepo getInstance(ChallengesRemoteDataSource challengesDataStore,
ChallengesLocalDataStore challengesLocalDataStore) {
if (instance == null) {
instance = new ChallengesRepo(challengesDataStore, challengesLocalDataStore);
return instance;
public void getChallenges(@NonNull final GetChallengesCallback getChallengesCallback) {
mChallengesRemoteDataSource.getChallenges(new GetChallengesCallback() {
public void onChallengesLoaded(List<Challenge> challenges) {
public void onError(Exception exception) {
public void onDataNotAvailable() {
public void saveChallenges(@NonNull Challenge challenge) {
public void deleteAllChallenges() {
public interface LoadDataCallback {
void onDataLoaded(Cursor cursor);
void onDataNotAvailable();
void onDataReset();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment