Search in sources :

Example 1 with FileUploadNotification

use of com.instructure.pandautils.utils.FileUploadNotification in project instructure-android by instructure.

the class QuizQuestionsFragment method onFileUploadEvent.

@Subscribe(threadMode = ThreadMode.MAIN)
public void onFileUploadEvent(FileUploadEvent event) {
    // update the adapter item
    event.get(new Function1<FileUploadNotification, Unit>() {

        @Override
        public Unit invoke(FileUploadNotification notification) {
            final Intent statusIntent = notification.getIntent();
            if (statusIntent != null) {
                if (FileUploadService.QUIZ_UPLOAD_COMPLETE.equals(statusIntent.getAction())) {
                    if (statusIntent.hasExtra(Const.ATTACHMENT)) {
                        long questionId = statusIntent.getLongExtra(Const.QUIZ_ANSWER_ID, -1);
                        int position = statusIntent.getIntExtra(Const.POSITION, -1);
                        Attachment attachment = (Attachment) statusIntent.getExtras().get(Const.ATTACHMENT);
                        if (attachment != null && questionId != -1) {
                            quizQuestionAdapter.setFileUploadForQuiz(questionId, attachment, position);
                        }
                    }
                } else if (FileUploadService.UPLOAD_ERROR.equals(statusIntent.getAction())) {
                    final Bundle bundle = statusIntent.getExtras();
                    if (bundle != null && bundle.containsKey(Const.MESSAGE)) {
                        String errorMessage = bundle.getString(Const.MESSAGE);
                        if (null == errorMessage || "".equals(errorMessage)) {
                            errorMessage = getString(R.string.errorUploadingFile);
                        }
                        showToast(errorMessage);
                    }
                    final long questionId = statusIntent.getLongExtra(Const.QUIZ_ANSWER_ID, -1);
                    if (questionId != -1) {
                        final int position = statusIntent.getIntExtra(Const.POSITION, -1);
                        quizQuestionAdapter.setIsLoading(questionId, false, position);
                    }
                }
            }
            return null;
        }
    });
}
Also used : FileUploadNotification(com.instructure.pandautils.utils.FileUploadNotification) Bundle(android.os.Bundle) Intent(android.content.Intent) Attachment(com.instructure.canvasapi2.models.Attachment) Unit(kotlin.Unit) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 2 with FileUploadNotification

use of com.instructure.pandautils.utils.FileUploadNotification in project instructure-android by instructure.

the class AddSubmissionFragment method setUpCallback.

// /////////////////////////////////////////////////////////////////////////
// CallBack
// /////////////////////////////////////////////////////////////////////////
public void setUpCallback() {
    canvasCallbackSubmission = new StatusCallback<Submission>() {

        @Override
        public void onResponse(@NonNull Response<Submission> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            Submission result = response.body();
            if (result.getBody() != null || result.getUrl() != null) {
                Toast.makeText(getActivity(), R.string.successPostingSubmission, Toast.LENGTH_LONG).show();
                // clear text fields because they are saved
                textSubmission.setText("");
                urlSubmission.setText("");
                // Send broadcast so list is updated.
                EventBus.getDefault().post(new FileUploadEvent(new FileUploadNotification(null, new ArrayList<Attachment>())));
                Navigation navigation = getNavigation();
                if (navigation != null)
                    navigation.popCurrentFragment();
            } else {
                Toast.makeText(getActivity(), R.string.errorPostingSubmission, Toast.LENGTH_LONG).show();
            }
        }
    };
    mLTIToolCallback = new StatusCallback<List<LTITool>>() {

        @Override
        public void onResponse(@NonNull Response<List<LTITool>> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            for (LTITool ltiTool : response.body()) {
                final String url = ltiTool.getUrl();
                if (url != null && url.contains("instructuremedia.com/lti/launch")) {
                    mArcUpload.setVisibility(View.VISIBLE);
                    mArcLTITool = ltiTool;
                    break;
                }
            }
            // check to see if we should automatically show the file upload dialog
            showFileUploadDialog();
        }

        @Override
        public void onFail(@Nullable Call<List<LTITool>> call, @NonNull Throwable error, @Nullable Response response) {
            // we don't want to show it if this failed due to there being no cache
            if (response != null && response.code() != 504) {
                showFileUploadDialog();
            }
        }
    };
}
Also used : Navigation(com.instructure.interactions.Navigation) Submission(com.instructure.canvasapi2.models.Submission) LTITool(com.instructure.canvasapi2.models.LTITool) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) ArrayList(java.util.ArrayList) FileUploadNotification(com.instructure.pandautils.utils.FileUploadNotification) Response(retrofit2.Response) ApiType(com.instructure.canvasapi2.utils.ApiType) FileUploadEvent(com.instructure.pandautils.utils.FileUploadEvent) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

FileUploadNotification (com.instructure.pandautils.utils.FileUploadNotification)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Attachment (com.instructure.canvasapi2.models.Attachment)1 LTITool (com.instructure.canvasapi2.models.LTITool)1 Submission (com.instructure.canvasapi2.models.Submission)1 ApiType (com.instructure.canvasapi2.utils.ApiType)1 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)1 Navigation (com.instructure.interactions.Navigation)1 FileUploadEvent (com.instructure.pandautils.utils.FileUploadEvent)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Unit (kotlin.Unit)1 Subscribe (org.greenrobot.eventbus.Subscribe)1 Response (retrofit2.Response)1