Search in sources :

Example 1 with Person

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;
}
Also used : ApiResponse(in.bugzy.data.remote.ApiResponse) Response(in.bugzy.data.remote.model.Response) ListPeopleRequest(in.bugzy.data.remote.model.ListPeopleRequest) NonNull(android.support.annotation.NonNull) ListPeopleData(in.bugzy.data.remote.model.ListPeopleData) NetworkBoundResource(in.bugzy.data.remote.NetworkBoundResource) List(java.util.List) ArrayList(java.util.ArrayList) Person(in.bugzy.data.model.Person) Nullable(android.support.annotation.Nullable) ApiResponse(in.bugzy.data.remote.ApiResponse)

Example 2 with Person

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());
}
Also used : Person(in.bugzy.data.model.Person)

Aggregations

Person (in.bugzy.data.model.Person)2 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 ApiResponse (in.bugzy.data.remote.ApiResponse)1 NetworkBoundResource (in.bugzy.data.remote.NetworkBoundResource)1 ListPeopleData (in.bugzy.data.remote.model.ListPeopleData)1 ListPeopleRequest (in.bugzy.data.remote.model.ListPeopleRequest)1 Response (in.bugzy.data.remote.model.Response)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1