use of com.instructure.canvasapi2.models.ModuleItem 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.ModuleItem in project instructure-android by instructure.
the class ModuleListRecyclerAdapterTest method testAreContentsTheSame_SameModule.
@Test
public void testAreContentsTheSame_SameModule() {
ModuleItem item = new ModuleItem();
item.setTitle("item");
assertTrue(mAdapter.createItemCallback().areContentsTheSame(item, item));
}
use of com.instructure.canvasapi2.models.ModuleItem in project instructure-android by instructure.
the class ModuleUtilityTest method testGetFragment_page.
@Test
public void testGetFragment_page() {
String url = "https://mobile.canvas.net/api/v1/courses/222/pages/hello-world";
ModuleItem moduleItem = new ModuleItem();
moduleItem.setType("Page");
moduleItem.setId(4567);
moduleItem.setUrl(url);
Course course = new Course();
Bundle expectedBundle = new Bundle();
expectedBundle.putSerializable(Const.CANVAS_CONTEXT, course);
expectedBundle.putString(Const.PAGE_NAME, "hello-world");
ParentFragment parentFragment = callGetFragment(moduleItem, course, null);
assertNotNull(parentFragment);
assertEquals(PageDetailsFragment.class, parentFragment.getClass());
assertEquals(expectedBundle.toString(), parentFragment.getArguments().toString());
}
use of com.instructure.canvasapi2.models.ModuleItem 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.ModuleItem in project instructure-android by instructure.
the class CourseModuleProgressionFragment method updateBottomNavBarButtons.
// the bottom navigation bar has prev and next arrows that sometimes show up and sometimes don't depending
// on where the user is (on the first module item there isn't a prev button). We also may need to update these
// dynamically when we use an async task to get the next group of module items
private void updateBottomNavBarButtons() {
// make them visible by default
prev.setVisibility(View.VISIBLE);
next.setVisibility(View.VISIBLE);
// don't want to see the previous button if we're on the first item
if (currentPos == 0) {
prev.setVisibility(View.INVISIBLE);
}
// don't show the next button if we're on the last item
if (currentPos + 1 >= NUM_ITEMS) {
next.setVisibility(View.INVISIBLE);
}
// get the fragment and update the title
Fragment fragment = adapter.getItem(currentPos);
ModuleItem.CompletionRequirement completionRequirement = getCurrentModuleItem(currentPos).getCompletionRequirement();
if (completionRequirement != null && ModuleItem.MUST_VIEW.equals(completionRequirement.getType())) {
// reload the module object to update the items. By viewing this item subsequent items may now be unlocked
adapter.notifyDataSetChanged();
addLockedIconIfNeeded(modules, items, groupPos, childPos);
}
ModuleItem moduleItem = getCurrentModuleItem(currentPos);
updateModuleMarkDoneView(moduleItem);
}
Aggregations