Search in sources :

Example 96 with StatusCallback

use of com.instructure.canvasapi2.StatusCallback in project instructure-android by instructure.

the class PollsManager method getNextPagePollSessions.

public static void getNextPagePollSessions(String nextUrl, StatusCallback<PollSessionResponse> callback, boolean forceNetwork) {
    if (isTesting() || mTesting) {
    // TODO:
    } else {
        final RestBuilder adapter = new RestBuilder(callback);
        final RestParams params = new RestParams.Builder().withPerPageQueryParam(true).withShouldIgnoreToken(false).withForceReadFromNetwork(forceNetwork).build();
        PollsSessionAPI.getNextPagePollSessions(nextUrl, adapter, params, callback);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 97 with StatusCallback

use of com.instructure.canvasapi2.StatusCallback in project instructure-android by instructure.

the class PollsManager method updatePollSession.

public static void updatePollSession(long pollId, long pollSessionId, long courseId, long sectionId, boolean hasPublicResults, StatusCallback<PollSessionResponse> callback, boolean forceNetwork) {
    if (isTesting() || mTesting) {
    // TODO:
    } else {
        final RestBuilder adapter = new RestBuilder(callback);
        final RestParams params = new RestParams.Builder().withPerPageQueryParam(true).withShouldIgnoreToken(false).withForceReadFromNetwork(forceNetwork).build();
        PollsSessionAPI.updatePollSession(pollId, pollSessionId, courseId, sectionId, hasPublicResults, adapter, params, callback);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 98 with StatusCallback

use of com.instructure.canvasapi2.StatusCallback in project instructure-android by instructure.

the class PollsManager method getPollSubmission.

public static void getPollSubmission(long pollId, long pollSessionId, long pollSubmissionId, StatusCallback<PollSubmissionResponse> callback, boolean forceNetwork) {
    if (isTesting() || mTesting) {
    // TODO:
    } else {
        final RestBuilder adapter = new RestBuilder(callback);
        final RestParams params = new RestParams.Builder().withPerPageQueryParam(true).withShouldIgnoreToken(false).withForceReadFromNetwork(forceNetwork).build();
        PollSubmissionAPI.getPollSubmission(pollId, pollSessionId, pollSubmissionId, adapter, params, callback);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 99 with StatusCallback

use of com.instructure.canvasapi2.StatusCallback in project instructure-android by instructure.

the class CourseModuleProgressionFragment method setButtonListeners.

private void setButtonListeners() {
    prev.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            setupPrevModuleName(currentPos);
            setupPreviousModule(getModuleItemGroup(currentPos));
            if (currentPos >= 1) {
                viewPager.setCurrentItem(--currentPos);
            }
            updateBottomNavBarButtons();
        }
    });
    next.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            setupNextModuleName(currentPos);
            setupNextModule(getModuleItemGroup(currentPos));
            if (currentPos < (NUM_ITEMS - 1)) {
                viewPager.setCurrentItem(++currentPos);
            }
            updateBottomNavBarButtons();
        }
    });
    markDoneButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (getModelObject() != null && getModelObject().getCompletionRequirement() != null) {
                if (getModelObject().getCompletionRequirement().isCompleted()) {
                    ModuleManager.markAsNotDone(getCanvasContext(), getModelObject().getModuleId(), getModelObject().getId(), new StatusCallback<ResponseBody>() {

                        @Override
                        public void onResponse(@NonNull Response<ResponseBody> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                            markDoneCheckBox.setChecked(false);
                            getModelObject().getCompletionRequirement().setCompleted(false);
                            notifyOfItemChanged(getModelObject());
                        }
                    });
                } else {
                    ModuleManager.markAsDone(getCanvasContext(), getModelObject().getModuleId(), getModelObject().getId(), new StatusCallback<ResponseBody>() {

                        @Override
                        public void onResponse(@NonNull Response<ResponseBody> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                            markDoneCheckBox.setChecked(true);
                            getModelObject().getCompletionRequirement().setCompleted(true);
                            notifyOfItemChanged(getModelObject());
                        }
                    });
                }
            }
        }
    });
}
Also used : Response(retrofit2.Response) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) NonNull(android.support.annotation.NonNull) ApiType(com.instructure.canvasapi2.utils.ApiType) OnClickListener(android.view.View.OnClickListener) StatusCallback(com.instructure.canvasapi2.StatusCallback) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 100 with StatusCallback

use of com.instructure.canvasapi2.StatusCallback in project instructure-android by instructure.

the class FileDetailsFragment method setUpCallback.

public void setUpCallback() {
    fileFolderCanvasCallback = new StatusCallback<FileFolder>() {

        @Override
        public void onResponse(@NonNull Response<FileFolder> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            // set up everything else now, we should have a file
            file = response.body();
            if (file != null) {
                if (file.getLockInfo() != null) {
                    // file is locked
                    icon.setImageResource(R.drawable.vd_lock);
                    openButton.setVisibility(View.GONE);
                    downloadButton.setVisibility(View.GONE);
                    fileTypeTextView.setVisibility(View.INVISIBLE);
                    String lockedMessage = "";
                    if (file.getLockInfo().getLockedModuleName() != null) {
                        lockedMessage = "<p>" + String.format(getActivity().getString(R.string.lockedFileDesc), "<b>" + file.getLockInfo().getLockedModuleName() + "</b>") + "</p>";
                    }
                    if (file.getLockInfo().getModulePrerequisiteNames().size() > 0) {
                        // we only want to add this text if there are module completion requirements
                        lockedMessage += getActivity().getString(R.string.mustComplete) + "<br>";
                        // textViews can't display <ul> and <li> tags, so we need to use "&#8226; " instead
                        for (int i = 0; i < file.getLockInfo().getModulePrerequisiteNames().size(); i++) {
                            // "&#8226; "
                            lockedMessage += "&#8226; " + file.getLockInfo().getModulePrerequisiteNames().get(i);
                        }
                        lockedMessage += "<br><br>";
                    }
                    // check to see if there is an unlocked date
                    if (file.getLockInfo().getUnlockAt() != null && file.getLockInfo().getUnlockAt().after(new Date())) {
                        lockedMessage += DateHelper.createPrefixedDateTimeString(getContext(), getActivity().getString(R.string.unlockedAt) + "<br>&#8226; ", file.getLockInfo().getUnlockAt());
                    }
                    fileNameTextView.setText(StringUtilities.simplifyHTML(Html.fromHtml(lockedMessage)));
                } else {
                    setupTextViews();
                    setupClickListeners();
                    // if the file has a thumbnail then show it. Make it a little bigger since the thumbnail size is pretty small
                    if (!TextUtils.isEmpty(file.getThumbnailUrl())) {
                        int dp = (int) ViewUtils.convertDipsToPixels(150, getActivity());
                        Picasso.with(getActivity()).load(file.getThumbnailUrl()).resize(dp, dp).centerInside().into(icon);
                    }
                }
                setPageViewReady();
            }
            toolbar.setTitle(title());
        }
    };
    markReadCanvasCallback = new StatusCallback<ResponseBody>() {

        @Override
        public void onResponse(@NonNull Response<ResponseBody> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
        }
    };
}
Also used : LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) FileFolder(com.instructure.canvasapi2.models.FileFolder) ApiType(com.instructure.canvasapi2.utils.ApiType) Date(java.util.Date) ResponseBody(okhttp3.ResponseBody)

Aggregations

RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)279 RestParams (com.instructure.canvasapi2.builders.RestParams)247 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)80 Response (okhttp3.Response)57 List (java.util.List)56 StatusCallback (com.instructure.canvasapi2.StatusCallback)44 ArrayList (java.util.ArrayList)43 ExhaustiveListCallback (com.instructure.canvasapi2.utils.ExhaustiveListCallback)31 NonNull (android.support.annotation.NonNull)30 Request (okhttp3.Request)27 ApiType (com.instructure.canvasapi2.utils.ApiType)22 QuizSubmissionResponse (com.instructure.canvasapi2.models.QuizSubmissionResponse)14 Response (retrofit2.Response)14 QuizSubmissionQuestionResponse (com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse)12 ParentResponse (com.instructure.canvasapi2.models.ParentResponse)10 Conversation (com.instructure.canvasapi2.models.Conversation)9 FileFolder (com.instructure.canvasapi2.models.FileFolder)8 GradingPeriodResponse (com.instructure.canvasapi2.models.GradingPeriodResponse)8 User (com.instructure.canvasapi2.models.User)7 Assignment (com.instructure.canvasapi2.models.Assignment)6