use of com.bluestacks.bugzy.data.remote.model.Response in project bugzy by cpunq.
the class Repository method getMilestones.
public LiveData<Resource<List<Milestone>>> getMilestones(boolean mustFetch) {
if (mFetchMilestonesLiveData != null) {
if (mFetchMilestonesLiveData.getValue().status == Status.LOADING && !mustFetch) {
// If the content is in loading state and the request doesn't require us to fetch again
return mMilestonesPublicLiveData;
}
mMilestonesPublicLiveData.removeSource(mFetchMilestonesLiveData);
mFetchMilestonesLiveData = null;
}
mFetchMilestonesLiveData = new NetworkBoundResource<List<Milestone>, Response<ListMilestonesData>>(mAppExecutors) {
@Override
protected void saveCallResult(@NonNull Response<ListMilestonesData> item) {
mSsRespository.updateMilestoneSearchSuggestion(item.getData().getMilestones());
db.beginTransaction();
try {
mMiscDao.insertMilestones(item.getData().getMilestones());
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
@Override
protected boolean shouldFetch(@Nullable List<Milestone> data) {
if (data == null || data.size() == 0) {
return true;
}
if (mustFetch) {
return true;
}
return false;
}
@NonNull
@Override
protected LiveData<List<Milestone>> loadFromDb() {
return mMiscDao.loadMilestones();
}
@NonNull
@Override
protected LiveData<ApiResponse<Response<ListMilestonesData>>> createCall() {
return mApiService.getMilestones(new Request("listFixFors"));
}
}.asLiveData();
mMilestonesPublicLiveData.addSource(mFetchMilestonesLiveData, value -> {
mMilestonesPublicLiveData.setValue(value);
});
return mMilestonesPublicLiveData;
}
use of com.bluestacks.bugzy.data.remote.model.Response in project bugzy by cpunq.
the class Repository method getAreas.
public MediatorLiveData<Resource<List<Area>>> getAreas(boolean mustFetch) {
if (mFetchAreasLiveData != null) {
if (mFetchAreasLiveData.getValue().status == Status.LOADING && !mustFetch) {
// If the content is in loading state and the request doesn't require us to fetch again
return mAreasPublicLiveData;
}
mAreasPublicLiveData.removeSource(mFetchAreasLiveData);
mFetchAreasLiveData = null;
}
mFetchAreasLiveData = new NetworkBoundResource<List<Area>, Response<ListAreasData>>(mAppExecutors) {
@Override
protected void saveCallResult(@NonNull Response<ListAreasData> item) {
mSsRespository.updateAreaSearchSuggestion(item.getData().getAreas());
db.beginTransaction();
try {
mMiscDao.insert(item.getData().getAreas());
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
@Override
protected boolean shouldFetch(@Nullable List<Area> data) {
if (data == null || data.size() == 0) {
return true;
}
if (mustFetch) {
return true;
}
return false;
}
@NonNull
@Override
protected LiveData<List<Area>> loadFromDb() {
return mMiscDao.loadAreas();
}
@NonNull
@Override
protected LiveData<ApiResponse<Response<ListAreasData>>> createCall() {
return mApiService.getAreas(new Request("listAreas"));
}
}.asLiveData();
mAreasPublicLiveData.addSource(mFetchAreasLiveData, value -> {
mAreasPublicLiveData.setValue(value);
});
return mAreasPublicLiveData;
}
use of com.bluestacks.bugzy.data.remote.model.Response in project bugzy by cpunq.
the class Repository method getCategories.
public LiveData<Resource<List<Category>>> getCategories(boolean mustFetch) {
if (mFetchCategoriesLiveData != null) {
if (mFetchCategoriesLiveData.getValue().status == Status.LOADING && !mustFetch) {
// If the content is in loading state and the request doesn't require us to fetch again
return mCategoriesPublicLiveData;
}
mCategoriesPublicLiveData.removeSource(mFetchCategoriesLiveData);
mFetchCategoriesLiveData = null;
}
mFetchCategoriesLiveData = new NetworkBoundResource<List<Category>, Response<ListCategoriesData>>(mAppExecutors) {
@Override
protected void saveCallResult(@NonNull Response<ListCategoriesData> item) {
db.beginTransaction();
try {
mMiscDao.insertCategories(item.getData().getCategories());
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
@Override
protected boolean shouldFetch(@Nullable List<Category> data) {
if (data == null || data.size() == 0) {
return true;
}
if (mustFetch) {
return true;
}
return false;
}
@NonNull
@Override
protected LiveData<List<Category>> loadFromDb() {
return mMiscDao.loadCategories();
}
@NonNull
@Override
protected LiveData<ApiResponse<Response<ListCategoriesData>>> createCall() {
return mApiService.getCategories(new Request("listCategories"));
}
}.asLiveData();
mCategoriesPublicLiveData.addSource(mFetchCategoriesLiveData, value -> {
mCategoriesPublicLiveData.setValue(value);
});
return mCategoriesPublicLiveData;
}
use of com.bluestacks.bugzy.data.remote.model.Response in project bugzy by cpunq.
the class Repository method getProjects.
public LiveData<Resource<List<Project>>> getProjects(boolean mustFetch) {
if (mFetchProjectsLiveData != null) {
if (mFetchProjectsLiveData.getValue().status == Status.LOADING && !mustFetch) {
// If the content is in loading state and the request doesn't require us to fetch again
return mProjectsPublicLiveData;
}
mProjectsPublicLiveData.removeSource(mFetchProjectsLiveData);
mFetchProjectsLiveData = null;
}
mFetchProjectsLiveData = new NetworkBoundResource<List<Project>, Response<ListProjectsData>>(mAppExecutors) {
@Override
protected void saveCallResult(@NonNull Response<ListProjectsData> item) {
db.beginTransaction();
try {
mMiscDao.insertProjects(item.getData().getProjects());
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
@Override
protected boolean shouldFetch(@Nullable List<Project> data) {
if (data == null || data.size() == 0) {
return true;
}
if (mustFetch) {
return true;
}
return false;
}
@NonNull
@Override
protected LiveData<List<Project>> loadFromDb() {
return mMiscDao.loadProjects();
}
@NonNull
@Override
protected LiveData<ApiResponse<Response<ListProjectsData>>> createCall() {
return mApiService.getProjects(new Request("listProjects"));
}
}.asLiveData();
mProjectsPublicLiveData.addSource(mFetchProjectsLiveData, value -> {
mProjectsPublicLiveData.setValue(value);
});
return mProjectsPublicLiveData;
}
use of com.bluestacks.bugzy.data.remote.model.Response in project bugzy by cpunq.
the class Repository method login.
public LiveData<Resource<Response<LoginData>>> login(String email, String password) {
NetworkBoundTask<Response<LoginData>> task = new NetworkBoundTask<Response<LoginData>>(mAppExecutors, mGson) {
@Override
public void saveCallResult(@NonNull Response<LoginData> result) {
String token = result.getData().getToken();
mPrefs.setString(PrefsHelper.Key.ACCESS_TOKEN, token);
mPrefs.setBoolean(PrefsHelper.Key.USER_LOGGED_IN, true);
mSsRespository.insertDefaultSearchSuggestions();
mAppExecutors.mainThread().execute(new Runnable() {
@Override
public void run() {
mToken.setValue(token);
}
});
}
@NonNull
@Override
protected Call<Response<LoginData>> createCall() {
return mApiService.login(new LoginRequest(email, password));
}
};
mAppExecutors.networkIO().execute(task);
return task.asLiveData();
}
Aggregations