use of com.instructure.canvasapi2.models.Group in project instructure-android by instructure.
the class CanvasContextSpinnerAdapter method newAdapterInstance.
public static CanvasContextSpinnerAdapter newAdapterInstance(Context context, List<Course> courses, List<Group> groups) {
ArrayList<CanvasContext> canvasContexts = new ArrayList<>();
if (!courses.isEmpty()) {
Course courseSeparator = new Course();
courseSeparator.setName(context.getString(R.string.courses));
courseSeparator.setId(COURSE_SEPARATOR);
canvasContexts.add(courseSeparator);
canvasContexts.addAll(courses);
}
if (!groups.isEmpty()) {
Course groupSeparator = new Course();
groupSeparator.setName(context.getString(R.string.groups));
groupSeparator.setId(GROUP_SEPARATOR);
canvasContexts.add(groupSeparator);
canvasContexts.addAll(groups);
}
return new CanvasContextSpinnerAdapter(context, canvasContexts);
}
use of com.instructure.canvasapi2.models.Group 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.models.Group in project instructure-android by instructure.
the class ModuleListRecyclerAdapter method isSequentiallyEnabled.
// endregion
// region Module binder Helpers
private boolean isSequentiallyEnabled(ModuleObject moduleObject, ModuleItem moduleItem) {
// 0 based) or the previous item is unlocked
if (mCanvasContext instanceof Course && (((Course) mCanvasContext).isTeacher() || ((Course) mCanvasContext).isTA())) {
return true;
}
if (moduleObject.isSequential_progress() && (moduleObject.getState() != null && (moduleObject.getState().equals(ModuleObject.STATE.unlocked.toString()) || moduleObject.getState().equals(ModuleObject.STATE.started.toString())))) {
// group is sequential, need to figure out which ones to grey out
int indexOfCurrentModuleItem = storedIndexOfItem(moduleObject, moduleItem);
if (indexOfCurrentModuleItem != -1) {
// getItem performs invalid index checks
ModuleItem previousModuleItem = getItem(moduleObject, indexOfCurrentModuleItem - 1);
ModuleItem nextModuleItem = getItem(moduleObject, indexOfCurrentModuleItem + 1);
if (isComplete(moduleItem)) {
return true;
} else if (previousModuleItem == null) {
// Its the first one in the sequence
return true;
} else if (!isComplete(previousModuleItem)) {
// previous item is not complete
return false;
} else if (isComplete(previousModuleItem) && !isComplete(moduleItem)) {
// previous complete, so show current as next in sequence
return true;
} else {
return false;
}
}
}
return true;
}
use of com.instructure.canvasapi2.models.Group in project instructure-android by instructure.
the class RubricRecyclerAdapter method createItemCallback.
@Override
public GroupSortedList.ItemComparatorCallback<RubricCriterion, RubricItem> createItemCallback() {
return new GroupSortedList.ItemComparatorCallback<RubricCriterion, RubricItem>() {
@Override
public int compare(RubricCriterion group, RubricItem o1, RubricItem o2) {
// put comments at the bottom
if (o1 instanceof RubricCommentItem && o2 instanceof RubricCommentItem) {
return 0;
} else if (o1 instanceof RubricCommentItem) {
return 1;
} else if (o2 instanceof RubricCommentItem) {
return -1;
}
RubricCriterionRating r1 = ((RubricRatingItem) o1).getRating();
RubricCriterionRating r2 = ((RubricRatingItem) o2).getRating();
if (r2.getId() != null && r2.getId().contains("null")) {
return -1;
} else if (r1.getId() != null && r1.getId().contains("null")) {
return -1;
}
return Double.compare(r2.getPoints(), r1.getPoints());
}
@Override
public boolean areContentsTheSame(RubricItem oldItem, RubricItem newItem) {
if (newItem instanceof RubricCommentItem || oldItem instanceof RubricCommentItem) {
// if its a comment always refresh the layout
return false;
} else {
RubricCriterionRating oldRating = ((RubricRatingItem) oldItem).getRating();
RubricCriterionRating newRating = ((RubricRatingItem) newItem).getRating();
return !(oldRating.getDescription() == null || newRating.getDescription() == null) && oldRating.getDescription().equals(newRating.getDescription()) && oldRating.getPoints() == newRating.getPoints();
}
}
@Override
public boolean areItemsTheSame(RubricItem item1, RubricItem item2) {
if (item1 instanceof RubricCommentItem ^ item2 instanceof RubricCommentItem) {
return false;
} else if ((item1 instanceof RubricCommentItem && ((RubricCommentItem) item1).getComment() == null) && (((RubricCommentItem) item2).getComment() == null)) {
return true;
} else if (item1 instanceof RubricCommentItem) {
return (((RubricCommentItem) item1).getComment() != null && ((RubricCommentItem) item2).getComment() != null) && ((RubricCommentItem) item1).getComment().equals(((RubricCommentItem) item2).getComment());
} else {
return (((RubricRatingItem) item1).getRating().getId() != null && ((RubricRatingItem) item2).getRating().getId() != null) && ((RubricRatingItem) item1).getRating().getId().equals(((RubricRatingItem) item2).getRating().getId());
}
}
@Override
public long getUniqueItemId(RubricItem item) {
if (item instanceof RubricCommentItem) {
if (!TextUtils.isEmpty(((RubricCommentItem) item).getComment())) {
return (((RubricCommentItem) item).getComment() + UUID.randomUUID().toString().hashCode()).hashCode();
} else {
return UUID.randomUUID().toString().hashCode();
}
} else {
if (!TextUtils.isEmpty(((RubricRatingItem) item).getRating().getId())) {
return (((RubricRatingItem) item).getRating().getId() + ((RubricRatingItem) item).getRating().getDescription()).hashCode();
} else {
return UUID.randomUUID().toString().hashCode();
}
}
}
@Override
public int getChildType(RubricCriterion group, RubricItem item) {
return (item instanceof RubricCommentItem) ? RubricViewHolder.TYPE_ITEM_COMMENT : RubricViewHolder.TYPE_ITEM_POINTS;
}
};
}
use of com.instructure.canvasapi2.models.Group in project instructure-android by instructure.
the class GroupManager method getAllGroupsForCourse.
public static void getAllGroupsForCourse(long courseId, StatusCallback<List<Group>> callback, boolean forceNetwork) {
if (isTesting() || mTesting) {
// TODO
} else {
final RestParams params = new RestParams.Builder().withForceReadFromNetwork(forceNetwork).withPerPageQueryParam(true).withShouldIgnoreToken(false).build();
final RestBuilder adapter = new RestBuilder(callback);
StatusCallback<List<Group>> depaginatedCallback = new ExhaustiveListCallback<Group>(callback) {
@Override
public void getNextPage(@NonNull StatusCallback<List<Group>> callback, @NonNull String nextUrl, boolean isCached) {
GroupAPI.getNextPageGroups(nextUrl, adapter, callback, params);
}
};
adapter.setStatusCallback(depaginatedCallback);
GroupAPI.getGroupsForCourse(adapter, depaginatedCallback, params, courseId);
}
}
Aggregations