Search in sources :

Example 1 with EditCaseData

use of in.bugzy.data.remote.model.EditCaseData in project bugzy by cpunq.

the class CasesRepository method editCase.

public LiveData<Resource<Response<EditCaseData>>> editCase(final CaseEditRequest request, int mode, List<Attachment> attachments) {
    NetworkBoundTask<Response<EditCaseData>> task = new NetworkBoundTask<Response<EditCaseData>>(mAppExecutors, mGson) {

        @Override
        public void saveCallResult(@NonNull Response<EditCaseData> result) {
            // Save?? ;)
            if (result.getData() == null) {
                return;
            }
        }

        @NonNull
        @Override
        protected Call<Response<EditCaseData>> createCall() {
            List<MultipartBody.Part> fileParts = new ArrayList<>();
            int i = 0;
            for (Attachment attachment : attachments) {
                fileParts.add(prepareFilePart("File" + i, attachment.getUri()));
                i++;
            }
            request.setFileCount(fileParts.size());
            request.setToken(mPrefs.getString(PrefsHelper.Key.ACCESS_TOKEN));
            switch(mode) {
                case CaseEditActivity.MODE_EDIT:
                case CaseEditActivity.MODE_ASSIGN:
                    return mApiService.editCase(request, fileParts);
                case CaseEditActivity.MODE_NEW:
                    return mApiService.newCase(request, fileParts);
                case CaseEditActivity.MODE_CLOSE:
                    return mApiService.closeCase(request, fileParts);
                case CaseEditActivity.MODE_RESOLVE:
                    return mApiService.resolveCase(request, fileParts);
                case CaseEditActivity.MODE_REACTIVATE:
                    return mApiService.reactivateCase(request, fileParts);
                case CaseEditActivity.MODE_REOPEN:
                    return mApiService.reopenCase(request, fileParts);
                default:
                    return mApiService.editCase(request, fileParts);
            }
        }
    };
    mAppExecutors.networkIO().execute(task);
    return task.asLiveData();
}
Also used : ApiResponse(in.bugzy.data.remote.ApiResponse) Response(in.bugzy.data.remote.model.Response) EditCaseData(in.bugzy.data.remote.model.EditCaseData) NonNull(android.support.annotation.NonNull) ArrayList(java.util.ArrayList) Attachment(in.bugzy.data.model.Attachment) NetworkBoundTask(in.bugzy.data.remote.NetworkBoundTask)

Aggregations

NonNull (android.support.annotation.NonNull)1 Attachment (in.bugzy.data.model.Attachment)1 ApiResponse (in.bugzy.data.remote.ApiResponse)1 NetworkBoundTask (in.bugzy.data.remote.NetworkBoundTask)1 EditCaseData (in.bugzy.data.remote.model.EditCaseData)1 Response (in.bugzy.data.remote.model.Response)1 ArrayList (java.util.ArrayList)1