Search in sources :

Example 1 with CaseStatus

use of in.bugzy.data.model.CaseStatus in project bugzy by cpunq.

the class Repository method getStatuses.

public LiveData<Resource<List<CaseStatus>>> getStatuses(boolean mustFetch) {
    if (mFetchStatusesLiveData != null) {
        if (mFetchStatusesLiveData.getValue().status == Status.LOADING && !mustFetch) {
            // If the content is in loading state and the request doesn't require us to fetch again
            return mStatusesPublicLiveData;
        }
        mStatusesPublicLiveData.removeSource(mFetchStatusesLiveData);
        mFetchStatusesLiveData = null;
    }
    mFetchStatusesLiveData = new NetworkBoundResource<List<CaseStatus>, Response<ListStatusesData>>(mAppExecutors) {

        @Override
        protected void saveCallResult(@NonNull Response<ListStatusesData> item) {
            db.beginTransaction();
            try {
                mMiscDao.insertStatuses(item.getData().getStatuses());
                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
            }
        }

        @Override
        protected boolean shouldFetch(@Nullable List<CaseStatus> data) {
            if (data == null || data.size() == 0) {
                return true;
            }
            if (mustFetch) {
                return true;
            }
            return false;
        }

        @NonNull
        @Override
        protected LiveData<List<CaseStatus>> loadFromDb() {
            return mMiscDao.loadStatuses();
        }

        @NonNull
        @Override
        protected LiveData<ApiResponse<Response<ListStatusesData>>> createCall() {
            return mApiService.getStatuses(new Request("listStatuses"));
        }
    }.asLiveData();
    mStatusesPublicLiveData.addSource(mFetchStatusesLiveData, value -> {
        mStatusesPublicLiveData.setValue(value);
    });
    return mStatusesPublicLiveData;
}
Also used : ApiResponse(in.bugzy.data.remote.ApiResponse) Response(in.bugzy.data.remote.model.Response) CaseStatus(in.bugzy.data.model.CaseStatus) NonNull(android.support.annotation.NonNull) FiltersRequest(in.bugzy.data.remote.model.FiltersRequest) LoginRequest(in.bugzy.data.remote.model.LoginRequest) Request(in.bugzy.data.remote.model.Request) ListPeopleRequest(in.bugzy.data.remote.model.ListPeopleRequest) MyDetailsRequest(in.bugzy.data.remote.model.MyDetailsRequest) ListStatusesData(in.bugzy.data.remote.model.ListStatusesData) NetworkBoundResource(in.bugzy.data.remote.NetworkBoundResource) List(java.util.List) ArrayList(java.util.ArrayList) Nullable(android.support.annotation.Nullable) ApiResponse(in.bugzy.data.remote.ApiResponse)

Example 2 with CaseStatus

use of in.bugzy.data.model.CaseStatus in project bugzy by cpunq.

the class CaseEditActivity method subscribeToViewModel.

public void subscribeToViewModel() {
    mCaseEditViewModel.getMilestones().observe(this, value -> {
        if (value != null && value.data != null) {
            showMilestones(value.data);
        }
    });
    mCaseEditViewModel.getAreas().observe(this, value -> {
        if (value != null && value.data != null) {
            showAreas(value.data);
        }
    });
    mCaseEditViewModel.getProjects().observe(this, value -> {
        if (value.data != null) {
            showProjects(value.data);
        }
    });
    mCaseEditViewModel.getPersons().observe(this, value -> {
        if (value.data != null) {
            showPeople(value.data);
        }
    });
    mCaseEditViewModel.getPriorities().observe(this, value -> {
        if (value.data != null) {
            showPriorities(value.data);
        }
    });
    mCaseEditViewModel.getCategories().observe(this, value -> {
        if (value.data != null) {
            showCategories(value.data);
        }
    });
    mCaseEditViewModel.getRequiredMergeIns().observe(this, value -> {
        if (value != null) {
            showRequiredMergeIns(value);
        }
    });
    mCaseEditViewModel.getStatuses().observe(this, value -> {
        if (value.data != null) {
            showStatuses(value.data);
        } else {
            showStatuses(new ArrayList<CaseStatus>());
        }
    });
    mCaseEditViewModel.getTags().observe(this, value -> {
        showTags(value.data);
    });
    mCaseEditViewModel.getToken().observe(this, token -> {
        mToken = token;
        mAdapter.setToken(token);
        mAttachmentsAdapter.setToken(token);
    });
    mCaseEditViewModel.getCaseLiveData().observe(this, value -> {
        if (value == null) {
            return;
        }
        if (value.data != null) {
            showCaseDetails(value.data);
        }
        if (value.status == Status.LOADING) {
            showLoading();
            return;
        }
        if (value.status == Status.ERROR) {
            showCaseFetchError(value.message);
            return;
        }
        if (value.status == Status.SUCCESS) {
            hideLoading();
        }
    });
    mCaseEditViewModel.getEditCaseStatus().observe(this, status -> {
        if (status.status == Status.LOADING) {
            showLoading();
            return;
        }
        if (status.status == Status.ERROR) {
            showEditCaseError(status.message);
            return;
        }
        if (status.status == Status.SUCCESS) {
            Intent i = new Intent(this, CaseDetailsActivity.class);
            Bundle args = new Bundle();
            args.putString("bug_id", String.valueOf(status.data.getData().getCase().getIxBug()));
            args.putSerializable("bug", status.data.getData().getCase());
            i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            i.putExtras(args);
            startActivity(i);
            finish();
        }
    });
    mCaseEditViewModel.getDefaultPropSelectionLiveData().observe(this, map -> {
        Log.d(TAG, "Got update: ");
        for (CaseEditViewModel.PropType key : map.keySet()) {
            switch(key) {
                case PROJECT:
                    mProjectSpinner.setSelection(map.get(PROJECT));
                    break;
                case AREA:
                    Log.d(TAG, "Got area update: " + map.get(AREA));
                    mAreaSpinner.setSelection(map.get(AREA));
                    break;
                case MILESTONE:
                    mMileStoneSpinner.setSelection(map.get(MILESTONE));
                    break;
                case CATEGORY:
                    mCategorySpinner.setSelection(map.get(CATEGORY));
                    break;
                case STATUS:
                    mStatusesSpinner.setSelection(map.get(STATUS));
                    break;
                case ASSIGNEDTO:
                    mAssignedToSpinner.setSelection(map.get(ASSIGNEDTO));
                    break;
                case PRIORITY:
                    mPrioritySpinner.setSelection(map.get(PRIORITY));
                    break;
            }
        }
    });
    mCaseEditViewModel.getUpdateRequiredMergeInSelection().observe(this, position -> {
        mRequiredMergeInSpinner.setSelection(position);
    });
    mCaseEditViewModel.getOpenPeopleSelector().observe(this, v -> {
        mAssignedToSpinner.performClick();
    });
    mCaseEditViewModel.getPrimaryButtonText().observe(this, v -> {
        mSaveButton.setText(v);
    });
    mCaseEditViewModel.getScrollAttachmentsToLast().observe(this, v -> {
        if (mAttachments.size() > 0) {
            mAttachmentsRecyclerView.smoothScrollToPosition(mAttachments.size() - 1);
        }
    });
    mCaseEditViewModel.getAttachmentsLiveData().observe(this, attachments -> {
        mAttachments = attachments;
        mAttachmentsAdapter.setList(attachments);
        mAttachmentsAdapter.notifyDataSetChanged();
    });
}
Also used : Bundle(android.os.Bundle) CaseStatus(in.bugzy.data.model.CaseStatus) PropType(in.bugzy.ui.editcase.CaseEditViewModel.PropType) Intent(android.content.Intent)

Aggregations

CaseStatus (in.bugzy.data.model.CaseStatus)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 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 FiltersRequest (in.bugzy.data.remote.model.FiltersRequest)1 ListPeopleRequest (in.bugzy.data.remote.model.ListPeopleRequest)1 ListStatusesData (in.bugzy.data.remote.model.ListStatusesData)1 LoginRequest (in.bugzy.data.remote.model.LoginRequest)1 MyDetailsRequest (in.bugzy.data.remote.model.MyDetailsRequest)1 Request (in.bugzy.data.remote.model.Request)1 Response (in.bugzy.data.remote.model.Response)1 PropType (in.bugzy.ui.editcase.CaseEditViewModel.PropType)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1