Search in sources :

Example 1 with Attachment

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

the class CaseEditActivity method setupEventsRecyclerView.

private void setupEventsRecyclerView() {
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    mEventsRecyclerView.setLayoutManager(layoutManager);
    mAdapter = new CaseEventsAdapter(this);
    mAdapter.setOnAttachmentClickListener(new CaseEventsAdapter.OnAttachmentClickListener() {

        @Override
        public void onAttachmentClick(View v, CaseEvent event, int attachmentPosition) {
            Attachment attachment = event.getsAttachments().get(attachmentPosition);
            String filename = attachment.getFilename().toLowerCase();
            if (filename.endsWith("png") || filename.endsWith("jpg") || filename.endsWith("jpeg")) {
                openImageActivity(v, attachment.getFullUrl());
                return;
            }
            // For other attachments leave things to browser
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(attachment.getFullUrl()));
            startActivity(i);
        }
    });
    mEventsRecyclerView.setAdapter(mAdapter);
    mEventsRecyclerView.setNestedScrollingEnabled(false);
}
Also used : CaseEventsAdapter(in.bugzy.ui.caseevents.CaseEventsAdapter) Attachment(in.bugzy.data.model.Attachment) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BindView(butterknife.BindView) NachoTextView(com.hootsuite.nachos.NachoTextView) View(android.view.View) AdapterView(android.widget.AdapterView) ImagePickerSheetView(com.flipboard.bottomsheet.commons.ImagePickerSheetView) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) CaseEvent(in.bugzy.data.model.CaseEvent)

Example 2 with Attachment

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

the class CaseDetailsFragment method setupViews.

private void setupViews() {
    mlinearLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mlinearLayoutManager);
    mAdapter = new CaseEventsAdapter(getContext());
    mRecyclerView.setAdapter(mAdapter);
    mAdapter.setOnAttachmentClickListener((view, event, attachmentPosition) -> {
        // TODO: Move this logic to ViewModel
        Attachment attachment = event.getsAttachments().get(attachmentPosition);
        String filename = attachment.getFilename().toLowerCase();
        if (filename.endsWith("png") || filename.endsWith("jpg") || filename.endsWith("jpeg")) {
            mParentActivity.openImageActivity(view, attachment.getFullUrl());
            return;
        }
        // For other attachments leave things to browser
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(attachment.getFullUrl()));
        startActivity(i);
    });
    prepareActionsButtons();
    prepareRecyclerScrollListener();
}
Also used : CaseEventsAdapter(in.bugzy.ui.caseevents.CaseEventsAdapter) Attachment(in.bugzy.data.model.Attachment) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 3 with Attachment

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

the class CaseEditViewModel method addAttachment.

public void addAttachment(Uri fileUri) {
    Attachment at = new Attachment();
    at.setUri(fileUri);
    mAttachmentsLiveData.getValue().add(at);
    // Trigger update
    mAttachmentsLiveData.setValue(mAttachmentsLiveData.getValue());
    mScrollAttachmentsToLast.call();
}
Also used : Attachment(in.bugzy.data.model.Attachment)

Example 4 with Attachment

use of in.bugzy.data.model.Attachment 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

Attachment (in.bugzy.data.model.Attachment)4 Intent (android.content.Intent)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 CaseEventsAdapter (in.bugzy.ui.caseevents.CaseEventsAdapter)2 NonNull (android.support.annotation.NonNull)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 ImagePickerSheetView (com.flipboard.bottomsheet.commons.ImagePickerSheetView)1 NachoTextView (com.hootsuite.nachos.NachoTextView)1 CaseEvent (in.bugzy.data.model.CaseEvent)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