Search in sources :

Example 51 with LinkHeaders

use of com.instructure.canvasapi2.utils.LinkHeaders in project instructure-android by instructure.

the class QuizSubmissionQuestionListRecyclerAdapter method addMatchingQuestion.

private void addMatchingQuestion(final QuizSubmissionQuestion baseItem, QuizMatchingViewHolder holder, int position, int courseColor) {
    addAnsweredQuestion(baseItem);
    QuizMatchingBinder.bind(holder, baseItem, courseColor, position, shouldLetAnswer, getContext(), embeddedWebViewCallback, webViewClientCallback, new QuizPostMatching() {

        @Override
        public void postMatching(final long questionId, HashMap<Long, Integer> answers) {
            QuizManager.postQuizQuestionMatching(quizSubmission, questionId, answers, true, new StatusCallback<QuizSubmissionQuestionResponse>() {

                @Override
                public void onResponse(@NonNull Response<QuizSubmissionQuestionResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                    if (type == ApiType.CACHE)
                        return;
                    final QuizSubmissionQuestionResponse quizSubmissionQuestionResponse = response.body();
                    if (quizSubmissionQuestionResponse.getQuizSubmissionQuestions() != null) {
                        for (QuizSubmissionQuestion question : quizSubmissionQuestionResponse.getQuizSubmissionQuestions()) {
                            if (baseItem.getId() == question.getId()) {
                                baseItem.setAnswer(question.getAnswer());
                            }
                        }
                        // make sure each answer has a match
                        int numAnswers = 0;
                        // API returns an ArrayList of LinkedTreeMaps
                        for (LinkedTreeMap<String, String> map : ((ArrayList<LinkedTreeMap<String, String>>) baseItem.getAnswer())) {
                            if (map.get(Const.QUIZ_MATCH_ID) != null && !map.get(Const.QUIZ_MATCH_ID).equals("null")) {
                                numAnswers++;
                            }
                        }
                        if (numAnswers == baseItem.getAnswers().length) {
                            addAnsweredQuestion(questionId);
                        } else {
                            removeAnsweredQuestion(questionId);
                        }
                    }
                }
            });
        }
    }, flagStateCallback);
}
Also used : QuizPostMatching(com.instructure.candroid.interfaces.QuizPostMatching) LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) StatusCallback(com.instructure.canvasapi2.StatusCallback) QuizSubmissionQuestion(com.instructure.canvasapi2.models.QuizSubmissionQuestion) QuizSubmissionResponse(com.instructure.canvasapi2.models.QuizSubmissionResponse) Response(retrofit2.Response) QuizSubmissionQuestionResponse(com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse) NonNull(android.support.annotation.NonNull) ApiType(com.instructure.canvasapi2.utils.ApiType) QuizSubmissionQuestionResponse(com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse)

Example 52 with LinkHeaders

use of com.instructure.canvasapi2.utils.LinkHeaders in project instructure-android by instructure.

the class FileFolderManager method getFirstPageFoldersRoot.

public static void getFirstPageFoldersRoot(CanvasContext canvasContext, boolean forceNetwork, final StatusCallback<List<FileFolder>> callback) {
    if (isTesting() || mTesting) {
    // TODO
    } else {
        final RestBuilder adapter = new RestBuilder(callback);
        RestParams params = new RestParams.Builder().withCanvasContext(canvasContext).withForceReadFromNetwork(forceNetwork).withPerPageQueryParam(true).build();
        final RestParams folderParams = new RestParams.Builder().withForceReadFromNetwork(forceNetwork).build();
        FileFolderAPI.getRootFolderForContext(adapter, canvasContext, new StatusCallback<FileFolder>() {

            @Override
            public void onResponse(@NonNull Response<FileFolder> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                FileFolderAPI.getFirstPageFolders(adapter, response.body().getId(), callback, folderParams);
            }
        }, params);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) FileFolder(com.instructure.canvasapi2.models.FileFolder) UpdateFileFolder(com.instructure.canvasapi2.models.UpdateFileFolder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) ApiType(com.instructure.canvasapi2.utils.ApiType) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 53 with LinkHeaders

use of com.instructure.canvasapi2.utils.LinkHeaders in project instructure-android by instructure.

the class FileFolderManager method getAllFilesRoot.

public static void getAllFilesRoot(CanvasContext canvasContext, final boolean forceNetwork, final StatusCallback<List<FileFolder>> callback) {
    if (isTesting() || mTesting) {
    // TODO
    } else {
        final RestBuilder adapter = new RestBuilder(callback);
        final RestParams params = new RestParams.Builder().withCanvasContext(canvasContext).withForceReadFromNetwork(forceNetwork).withPerPageQueryParam(true).build();
        FileFolderAPI.getRootFolderForContext(adapter, canvasContext, new StatusCallback<FileFolder>() {

            @Override
            public void onResponse(@NonNull Response<FileFolder> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                getAllFiles(response.body().getId(), forceNetwork, callback);
            }
        }, params);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) FileFolder(com.instructure.canvasapi2.models.FileFolder) UpdateFileFolder(com.instructure.canvasapi2.models.UpdateFileFolder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) ApiType(com.instructure.canvasapi2.utils.ApiType) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 54 with LinkHeaders

use of com.instructure.canvasapi2.utils.LinkHeaders in project instructure-android by instructure.

the class BaseRouterActivity method handleSpecificFile.

private void handleSpecificFile(long courseId, String fileID) {
    final CanvasContext canvasContext = CanvasContext.getGenericContext(CanvasContext.Type.COURSE, courseId, "");
    Logger.d("handleSpecificFile()");
    FileFolderManager.getFileFolderFromURLAirwolf(ApiPrefs.getAirwolfDomain(), "files/" + fileID, new StatusCallback<FileFolder>() {

        @Override
        public void onResponse(@NonNull Response<FileFolder> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (type == ApiType.API) {
                FileFolder fileFolder = response.body();
                if (fileFolder == null || response.code() == 404) {
                    Toast.makeText(BaseRouterActivity.this, R.string.fileNoLongerExists, Toast.LENGTH_LONG).show();
                } else {
                    if (fileFolder.isLocked() || fileFolder.isLockedForUser()) {
                        Toast.makeText(BaseRouterActivity.this, String.format(getString(R.string.fileLocked), (fileFolder.getDisplayName() == null) ? getString(R.string.file) : fileFolder.getDisplayName()), Toast.LENGTH_LONG).show();
                    } else {
                        downloadMedia(BaseRouterActivity.this, fileFolder.getContentType(), fileFolder.getUrl(), fileFolder.getDisplayName());
                    }
                }
            }
        }

        @Override
        public void onFail(@Nullable Call<FileFolder> call, @NonNull Throwable error, @Nullable Response response) {
            if (response != null && response.code() == 404) {
                Toast.makeText(BaseRouterActivity.this, R.string.fileNoLongerExists, Toast.LENGTH_LONG).show();
            }
        }
    });
}
Also used : Response(retrofit2.Response) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) FileFolder(com.instructure.canvasapi2.models.FileFolder) ApiType(com.instructure.canvasapi2.utils.ApiType) CanvasContext(com.instructure.canvasapi2.models.CanvasContext)

Example 55 with LinkHeaders

use of com.instructure.canvasapi2.utils.LinkHeaders in project instructure-android by instructure.

the class SettingsActivity method removeStudent.

public void removeStudent(final Student student) {
    AnalyticUtils.trackButtonPressed(AnalyticUtils.REMOVE_STUDENT);
    setResult(RESULT_OK);
    final ProgressDialog dialog = ProgressDialog.show(SettingsActivity.this, getString(R.string.removingStudent), "", true, false);
    dialog.show();
    // this api call removes student data from the db (like alerts info).
    UserManager.removeStudentAirwolf(ApiPrefs.getAirwolfDomain(), student.getParentId(), student.getStudentId(), new StatusCallback<ResponseBody>() {

        @Override
        public void onResponse(@NonNull Response<ResponseBody> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            dialog.dismiss();
            Toast.makeText(SettingsActivity.this, getString(R.string.studentRemoved), Toast.LENGTH_SHORT).show();
            int adapterSizeBeforeRemove = getAdapter().size();
            boolean removed = getAdapter().removeItem(student);
            if (removed && adapterSizeBeforeRemove == 1) {
                // Catches case for removing last student
                finish();
            }
        }
    });
}
Also used : LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) ApiType(com.instructure.canvasapi2.utils.ApiType) ProgressDialog(android.app.ProgressDialog) ResponseBody(okhttp3.ResponseBody)

Aggregations

LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)87 Response (okhttp3.Response)57 ArrayList (java.util.ArrayList)31 Request (okhttp3.Request)27 List (java.util.List)25 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)24 ApiType (com.instructure.canvasapi2.utils.ApiType)23 Response (retrofit2.Response)15 QuizSubmissionResponse (com.instructure.canvasapi2.models.QuizSubmissionResponse)13 QuizSubmissionQuestionResponse (com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse)12 ParentResponse (com.instructure.canvasapi2.models.ParentResponse)10 Conversation (com.instructure.canvasapi2.models.Conversation)9 NonNull (android.support.annotation.NonNull)8 GradingPeriodResponse (com.instructure.canvasapi2.models.GradingPeriodResponse)8 StatusCallback (com.instructure.canvasapi2.StatusCallback)7 FileFolder (com.instructure.canvasapi2.models.FileFolder)6 Submission (com.instructure.canvasapi2.models.Submission)6 Assignment (com.instructure.canvasapi2.models.Assignment)5 CourseNickname (com.instructure.canvasapi2.models.CourseNickname)5 ResponseBody (okhttp3.ResponseBody)5