use of in.bugzy.data.model.Person in project bugzy by cpunq.
the class Repository method getPeople.
public LiveData<Resource<List<Person>>> getPeople(boolean mustFetch) {
if (mFetchPeopleLiveData != null) {
if (mFetchPeopleLiveData.getValue().status == Status.LOADING && !mustFetch) {
// If the content is in loading state and the request doesn't require us to fetch again
return mPeoplePublicLiveData;
}
mPeoplePublicLiveData.removeSource(mFetchPeopleLiveData);
mFetchPeopleLiveData = null;
}
mFetchPeopleLiveData = new NetworkBoundResource<List<Person>, Response<ListPeopleData>>(mAppExecutors) {
@Override
protected void saveCallResult(@NonNull Response<ListPeopleData> item) {
mSsRespository.updatePeopleSearchSuggestion(item.getData().getPersons());
try {
db.beginTransaction();
db.miscDao().insertPersons(item.getData().getPersons());
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
@Override
protected boolean shouldFetch(@Nullable List<Person> data) {
if (data == null || data.size() == 0) {
return true;
}
if (mustFetch) {
return true;
}
return false;
}
@NonNull
@Override
protected LiveData<List<Person>> loadFromDb() {
return mMiscDao.loadPersons();
}
@NonNull
@Override
protected LiveData<ApiResponse<Response<ListPeopleData>>> createCall() {
return mApiService.listPeople(new ListPeopleRequest());
}
}.asLiveData();
mPeoplePublicLiveData.addSource(mFetchPeopleLiveData, value -> {
mPeoplePublicLiveData.setValue(value);
});
return mPeoplePublicLiveData;
}
use of in.bugzy.data.model.Person in project bugzy by cpunq.
the class BugzyApp method setCrashlyticsUserIfPresent.
private void setCrashlyticsUserIfPresent(String organisationName) {
if (TextUtils.isEmpty(mPrefsHelper.getString(PrefsHelper.Key.USER_EMAIL))) {
return;
}
Person me = new Person();
me.setFullname(mPrefsHelper.getString(PrefsHelper.Key.USER_NAME));
me.setPersonid(mPrefsHelper.getInt(PrefsHelper.Key.PERSON_ID));
me.setEmail(mPrefsHelper.getString(PrefsHelper.Key.USER_EMAIL));
String token = mPrefsHelper.getString(PrefsHelper.Key.ACCESS_TOKEN, "");
mBugzyUrlGenerator.setOrganisationName(organisationName);
mBugzyUrlGenerator.setToken(token);
Crashlytics.setUserIdentifier(me.getPersonid() + "");
Crashlytics.setUserEmail(me.getEmail());
Crashlytics.setUserName(me.getFullname());
}
Aggregations