use of com.instructure.canvasapi2.models.ModuleObject in project instructure-android by instructure.
the class ModuleBinder method bind.
public static void bind(final ModuleViewHolder holder, final ModuleObject moduleObject, final ModuleItem moduleItem, final Context context, final ModuleAdapterToFragmentCallback adapterToFragmentCallback, final boolean isSequentiallEnabled, final int courseColor, final boolean isFirstItem, final boolean isLastItem) {
boolean isLocked = ModuleUtility.isGroupLocked(moduleObject);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
adapterToFragmentCallback.onRowClicked(moduleObject, moduleItem, holder.getAdapterPosition(), true);
}
});
// Title
holder.title.setText(moduleItem.getTitle());
if (moduleItem.getType().equals(ModuleItem.TYPE.Locked.toString()) || moduleItem.getType().equals(ModuleItem.TYPE.ChooseAssignmentGroup.toString())) {
holder.title.setTypeface(null, Typeface.ITALIC);
holder.title.setTextColor(context.getResources().getColor(R.color.secondaryText));
} else {
holder.title.setTypeface(null, Typeface.NORMAL);
holder.title.setTextColor(context.getResources().getColor(R.color.primaryText));
}
// Description
if (moduleItem.getCompletionRequirement() != null && moduleItem.getCompletionRequirement().getType() != null) {
setVisible(holder.description);
holder.description.setTextColor(context.getResources().getColor(R.color.canvasTextMedium));
String requireText = moduleItem.getCompletionRequirement().getType();
if (requireText.equals(ModuleObject.STATE.must_submit.toString())) {
if (moduleItem.getCompletionRequirement().isCompleted()) {
holder.description.setText(context.getString(R.string.moduleItemSubmitted));
holder.description.setTextColor(courseColor);
} else {
holder.description.setText(context.getString(R.string.moduleItemSubmit));
}
} else if (requireText.equals(ModuleObject.STATE.must_view.toString())) {
if (moduleItem.getCompletionRequirement().isCompleted()) {
holder.description.setText(context.getString(R.string.moduleItemViewed));
} else {
holder.description.setText(context.getString(R.string.moduleItemMustView));
}
} else if (requireText.equals(ModuleObject.STATE.must_contribute.toString())) {
if (moduleItem.getCompletionRequirement().isCompleted()) {
holder.description.setText(context.getString(R.string.moduleItemContributed));
} else {
holder.description.setText(context.getString(R.string.moduleItemContribute));
}
} else // min_score only present when type == 'min_score'
if (requireText.equals(ModuleObject.STATE.min_score.toString())) {
if (moduleItem.getCompletionRequirement().isCompleted()) {
holder.description.setText(context.getString(R.string.moduleItemMinScoreMet));
} else {
holder.description.setText(context.getString(R.string.moduleItemMinScore) + " " + moduleItem.getCompletionRequirement().getMin_score());
}
} else {
holder.description.setText("");
setGone(holder.description);
}
} else {
holder.description.setText("");
setGone(holder.description);
}
// Indicator
setGone(holder.indicator);
if (moduleItem.getCompletionRequirement() != null && moduleItem.getCompletionRequirement().isCompleted()) {
Drawable drawable = ColorKeeper.getColoredDrawable(context, R.drawable.vd_check_white_24dp, courseColor);
holder.indicator.setImageDrawable(drawable);
setVisible(holder.indicator);
}
if (isLocked) {
Drawable drawable = ColorKeeper.getColoredDrawable(context, R.drawable.vd_lock, courseColor);
holder.indicator.setImageDrawable(drawable);
setVisible(holder.indicator);
}
// Icon
int drawableResource = -1;
if (moduleItem.getType().equals(ModuleItem.TYPE.Assignment.toString())) {
drawableResource = R.drawable.vd_assignment;
} else if (moduleItem.getType().equals(ModuleItem.TYPE.Discussion.toString())) {
drawableResource = R.drawable.vd_discussion;
} else if (moduleItem.getType().equals(ModuleItem.TYPE.File.toString())) {
drawableResource = R.drawable.vd_download;
} else if (moduleItem.getType().equals(ModuleItem.TYPE.Page.toString())) {
drawableResource = R.drawable.vd_pages;
} else if (moduleItem.getType().equals(ModuleItem.TYPE.SubHeader.toString())) {
setGone(holder.icon);
} else if (moduleItem.getType().equals(ModuleItem.TYPE.Quiz.toString())) {
drawableResource = R.drawable.vd_quiz;
} else if (moduleItem.getType().equals(ModuleItem.TYPE.ExternalUrl.toString())) {
drawableResource = R.drawable.vd_link;
} else if (moduleItem.getType().equals(ModuleItem.TYPE.ExternalTool.toString())) {
drawableResource = R.drawable.vd_lti;
} else if (moduleItem.getType().equals(ModuleItem.TYPE.Locked.toString())) {
drawableResource = R.drawable.vd_lock;
} else if (moduleItem.getType().equals(ModuleItem.TYPE.ChooseAssignmentGroup.toString())) {
drawableResource = R.drawable.vd_pages;
}
if (drawableResource == -1) {
setGone(holder.icon);
} else {
Drawable drawable = ColorKeeper.getColoredDrawable(context, drawableResource, courseColor);
holder.icon.setImageDrawable(drawable);
}
// Details
ModuleContentDetails details = moduleItem.getModuleDetails();
if (details != null) {
boolean hasDate, hasPoints;
if (details.getDueDate() != null) {
holder.date.setText(DateHelper.createPrefixedDateTimeString(context, R.string.toDoDue, details.getDueDate()));
hasDate = true;
} else {
holder.date.setText("");
hasDate = false;
}
String points = details.getPointsPossible();
if (!TextUtils.isEmpty(points)) {
holder.points.setText(context.getString(R.string.totalPoints, com.instructure.canvasapi2.utils.NumberHelper.formatDecimal(Double.parseDouble(points), 2, true)));
hasPoints = true;
} else {
holder.points.setText("");
hasPoints = false;
}
if (!hasDate && !hasPoints) {
setGone(holder.date);
setGone(holder.points);
} else {
if (hasDate)
setVisible(holder.date);
else
setInvisible(holder.date);
if (hasPoints)
setVisible(holder.points);
else
setInvisible(holder.points);
}
} else {
holder.points.setText("");
holder.date.setText("");
setGone(holder.date);
setGone(holder.points);
}
updateShadows(isFirstItem, isLastItem, holder.shadowTop, holder.shadowBottom);
}
use of com.instructure.canvasapi2.models.ModuleObject in project instructure-android by instructure.
the class ModuleUtilityTest method testGetFragment_file.
@Test
public void testGetFragment_file() {
String url = "https://mobile.canvas.net/api/v1/courses/222/assignments/123456789";
ModuleItem moduleItem = new ModuleItem();
moduleItem.setType("File");
moduleItem.setId(4567);
moduleItem.setUrl(url);
ModuleObject moduleObject = new ModuleObject();
moduleObject.setId(1234);
Course course = new Course();
String expectedUrl = "courses/222/assignments/123456789";
Bundle expectedBundle = new Bundle();
expectedBundle.putSerializable(Const.CANVAS_CONTEXT, course);
expectedBundle.putString(Const.FILE_URL, expectedUrl);
expectedBundle.putLong(Const.MODULE_ID, moduleObject.getId());
expectedBundle.putLong(Const.ITEM_ID, moduleItem.getId());
ParentFragment parentFragment = callGetFragment(moduleItem, course, moduleObject);
assertNotNull(parentFragment);
assertEquals(FileDetailsFragment.class, parentFragment.getClass());
assertEquals(expectedBundle.toString(), parentFragment.getArguments().toString());
// test module object is null
moduleObject = null;
expectedBundle = new Bundle();
expectedBundle.putSerializable(Const.CANVAS_CONTEXT, course);
expectedBundle.putString(Const.FILE_URL, expectedUrl);
parentFragment = callGetFragment(moduleItem, course, moduleObject);
assertNotNull(parentFragment);
assertEquals(FileDetailsFragment.class, parentFragment.getClass());
assertEquals(expectedBundle.toString(), parentFragment.getArguments().toString());
}
use of com.instructure.canvasapi2.models.ModuleObject in project instructure-android by instructure.
the class ModuleListFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = getLayoutInflater().inflate(R.layout.fragment_module_list, container, false);
mToolbar = rootView.findViewById(R.id.toolbar);
CardView cardView = rootView.findViewById(R.id.cardView);
if (cardView != null) {
cardView.setCardBackgroundColor(Color.WHITE);
}
mRecyclerAdapter = new ModuleListRecyclerAdapter(mCourse, getDefaultSelectedId(), getContext(), getCanvasContext(), new ModuleAdapterToFragmentCallback() {
@Override
public void onRowClicked(ModuleObject moduleObject, ModuleItem moduleItem, int position, boolean isOpenDetail) {
if (moduleItem.getType() != null && moduleItem.getType().equals(ModuleObject.STATE.unlock_requirements.toString())) {
return;
}
// don't do anything with headers if the user selects it
if (moduleItem.getType() != null && (moduleItem.getType().equals(ModuleItem.TYPE.SubHeader.toString()))) {
return;
}
boolean isLocked = ModuleUtility.isGroupLocked(moduleObject);
if (isLocked) {
return;
}
// Remove all the subheaders and stuff.
ArrayList<ModuleObject> groups = mRecyclerAdapter.getGroups();
ArrayList<ArrayList<ModuleItem>> moduleItemsArray = new ArrayList<>();
for (int i = 0; i < groups.size(); i++) {
ArrayList<ModuleItem> moduleItems = mRecyclerAdapter.getItems(groups.get(i));
moduleItemsArray.add(moduleItems);
}
ModuleProgressionUtility.ModuleHelper moduleHelper = ModuleProgressionUtility.prepareModulesForCourseProgression(getContext(), moduleItem.getId(), groups, moduleItemsArray);
Navigation navigation = getNavigation();
if (navigation != null) {
Bundle bundle = CourseModuleProgressionFragment.createBundle(groups, moduleHelper.strippedModuleItems, mCourse, moduleHelper.newGroupPosition, moduleHelper.newChildPosition);
navigation.addFragment(FragUtils.getFrag(CourseModuleProgressionFragment.class, bundle));
}
}
@Override
public void onRefreshFinished() {
setRefreshing(false);
}
});
configureRecyclerView(rootView, getContext(), mRecyclerAdapter, R.id.swipeRefreshLayout, R.id.emptyPandaView, R.id.listView);
return rootView;
}
use of com.instructure.canvasapi2.models.ModuleObject 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.ModuleObject in project instructure-android by instructure.
the class ModuleListRecyclerAdapter method getPrerequisiteString.
// never actually shows prereqs because grayed out module items show instead.
private String getPrerequisiteString(ModuleObject moduleObject) {
String prereqString = getContext().getString(R.string.noItemsToDisplayShort);
if (ModuleUtility.isGroupLocked(moduleObject)) {
prereqString = getContext().getString(R.string.locked);
}
if (moduleObject.getState() != null && moduleObject.getState().equals(ModuleObject.STATE.locked.toString()) && getGroupItemCount(moduleObject) > 0 && getItem(moduleObject, 0).getType().equals(ModuleObject.STATE.unlock_requirements.toString())) {
StringBuilder reqs = new StringBuilder();
long[] ids = moduleObject.getPrerequisite_ids();
// check to see if they need to finish other modules first
if (ids != null) {
for (int i = 0; i < ids.length; i++) {
ModuleObject prereqModuleObject = getGroup(ids[i]);
if (prereqModuleObject != null) {
if (i == 0) {
// if it's the first one, add the "Prerequisite:" label
reqs.append(getContext().getString(R.string.prerequisites) + " " + prereqModuleObject.getName());
} else {
reqs.append(", " + prereqModuleObject.getName());
}
}
}
}
if (moduleObject.getUnlock_at() != null) {
// only want a newline if there are prerequisite ids
if (ids.length > 0 && ids[0] != 0) {
reqs.append("\n");
}
reqs.append(DateHelper.createPrefixedDateTimeString(getContext(), R.string.unlocked, moduleObject.getUnlock_at()));
}
prereqString = reqs.toString();
}
return prereqString;
}
Aggregations