use of com.instructure.canvasapi2.utils.ApiType 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();
}
}
};
}
use of com.instructure.canvasapi2.utils.ApiType in project instructure-android by instructure.
the class ModuleListRecyclerAdapter method getModuleItemsCallback.
private ModuleItemCallback getModuleItemsCallback(final ModuleObject moduleObject, final boolean isNotifyGroupChange) {
if (mModuleItemCallbacks.containsKey(moduleObject.getId())) {
return mModuleItemCallbacks.get(moduleObject.getId());
} else {
ModuleItemCallback moduleItemCallback = new ModuleItemCallback(moduleObject) {
private int checkMasteryPaths(int position, ModuleItem item) {
if (item.getMasteryPaths() != null && item.getMasteryPaths().isLocked()) {
// add another module item that says it's locked
ModuleItem masteryPathsLocked = new ModuleItem();
// set an id so that if there is more than one path we'll display all of them. otherwise addOrUpdateItem will overwrite it
masteryPathsLocked.setId(UUID.randomUUID().getLeastSignificantBits());
masteryPathsLocked.setTitle(String.format(Locale.getDefault(), getContext().getString(R.string.locked_mastery_paths), item.getTitle()));
masteryPathsLocked.setType(ModuleItem.TYPE.Locked.toString());
masteryPathsLocked.setCompletionRequirement(null);
masteryPathsLocked.setPosition(position++);
addOrUpdateItem(this.getModuleObject(), masteryPathsLocked);
} else if (item.getMasteryPaths() != null && !item.getMasteryPaths().isLocked() && item.getMasteryPaths().getSelectedSetId() == 0) {
// add another module item that says select to choose assignment group
// We only want to do this when we have a mastery paths object, it's unlocked, and the user hasn't already selected a set
ModuleItem masteryPathsSelect = new ModuleItem();
// set an id so that if there is more than one path we'll display all of them. otherwise addOrUpdateItem will overwrite it
masteryPathsSelect.setId(UUID.randomUUID().getLeastSignificantBits());
masteryPathsSelect.setTitle(getContext().getString(R.string.choose_assignment_group));
masteryPathsSelect.setType(ModuleItem.TYPE.ChooseAssignmentGroup.toString());
masteryPathsSelect.setCompletionRequirement(null);
masteryPathsSelect.setPosition(position++);
// sort the mastery paths by position
ArrayList<AssignmentSet> assignmentSets = new ArrayList<>();
assignmentSets.addAll(Arrays.asList(item.getMasteryPaths().getAssignmentSets()));
Collections.sort(assignmentSets, new Comparator<AssignmentSet>() {
@Override
public int compare(AssignmentSet lh, AssignmentSet rh) {
if (lh != null && rh != null) {
if (lh.getPosition() < rh.getPosition()) {
return -1;
} else if (lh.getPosition() > rh.getPosition()) {
return 1;
}
}
return 0;
}
});
AssignmentSet[] set = new AssignmentSet[assignmentSets.size()];
assignmentSets.toArray(set);
item.getMasteryPaths().setAssignmentSets(set);
masteryPathsSelect.setMasteryPathsItemId(item.getId());
masteryPathsSelect.setMasteryPaths(item.getMasteryPaths());
addOrUpdateItem(this.getModuleObject(), masteryPathsSelect);
}
return position;
}
@Override
public void onResponse(@NonNull Response<List<ModuleItem>> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
List<ModuleItem> moduleItems = response.body();
if (type == ApiType.API) {
int position = (moduleItems.size() > 0 && moduleItems.get(0) != null) ? moduleItems.get(0).getPosition() - 1 : 0;
for (ModuleItem item : moduleItems) {
item.setPosition(position++);
addOrUpdateItem(this.getModuleObject(), item);
position = checkMasteryPaths(position, item);
}
String nextItemsURL = linkHeaders.nextUrl;
if (nextItemsURL != null) {
ModuleManager.getNextPageModuleItems(nextItemsURL, this, true);
}
this.setIsFromNetwork(true);
expandGroup(this.getModuleObject(), isNotifyGroupChange);
} else if (type == ApiType.CACHE) {
int position = (moduleItems.size() > 0 && moduleItems.get(0) != null) ? moduleItems.get(0).getPosition() - 1 : 0;
for (ModuleItem item : moduleItems) {
item.setPosition(position++);
addOrUpdateItem(this.getModuleObject(), item);
}
String nextItemsURL = linkHeaders.nextUrl;
if (nextItemsURL != null) {
ModuleManager.getNextPageModuleItems(nextItemsURL, this, true);
}
// Wait for the network to expand when there are no items
if (moduleItems.size() > 0) {
expandGroup(this.getModuleObject(), isNotifyGroupChange);
}
}
}
@Override
public void onFail(@Nullable Call<List<ModuleItem>> call, @NonNull Throwable error, @Nullable Response response) {
// Only expand if there was no cache result and no network. No connection empty cell will be displayed
if (response != null && response.code() == 504 && APIHelper.isCachedResponse(response) && getContext() != null && !Utils.isNetworkAvailable(getContext())) {
expandGroup(this.getModuleObject(), isNotifyGroupChange);
}
}
};
mModuleItemCallbacks.put(moduleObject.getId(), moduleItemCallback);
return moduleItemCallback;
}
}
use of com.instructure.canvasapi2.utils.ApiType in project instructure-android by instructure.
the class QuizSubmissionQuestionListRecyclerAdapter method addMultipleDropdown.
private void addMultipleDropdown(final QuizSubmissionQuestion baseItem, QuizMultipleDropdownViewHolder holder, int position, int courseColor) {
addAnsweredQuestion(baseItem);
QuizMultipleDropdownBinder.bind(holder, baseItem, courseColor, position, shouldLetAnswer, getContext(), embeddedWebViewCallback, webViewClientCallback, new QuizPostMultipleDropdown() {
@Override
public void postMultipleDropdown(final long questionId, HashMap<String, Long> answers) {
QuizManager.postQuizQuestionMultipleDropdown(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;
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 a LinkedTreeMap
for (String map : ((LinkedTreeMap<String, String>) baseItem.getAnswer()).values()) {
if (map != null && !map.equals("null")) {
numAnswers++;
}
}
if (numAnswers == ((LinkedTreeMap<String, String>) baseItem.getAnswer()).size()) {
addAnsweredQuestion(questionId);
} else {
removeAnsweredQuestion(questionId);
}
}
}
});
}
}, flagStateCallback);
}
use of com.instructure.canvasapi2.utils.ApiType 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);
}
use of com.instructure.canvasapi2.utils.ApiType 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);
}
}
Aggregations