use of com.instructure.canvasapi2.models.Assignment in project instructure-android by instructure.
the class MasteryPathOptionsFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
mRootView = getLayoutInflater().inflate(R.layout.fragment_mastery_paths_options, container, false);
mRecyclerAdapter = new MasteryPathOptionsRecyclerAdapter(getContext(), getCanvasContext(), mAssignments, new AdapterToFragmentCallback<Assignment>() {
@Override
public void onRowClicked(Assignment assignment, int position, boolean isOpenDetail) {
Navigation navigation = getNavigation();
if (navigation != null) {
Bundle bundle = AssignmentBasicFragment.createBundle(getCanvasContext(), assignment);
navigation.addFragment(FragUtils.getFrag(AssignmentBasicFragment.class, bundle));
}
}
@Override
public void onRefreshFinished() {
}
});
configureRecyclerView(mRootView, getContext(), mRecyclerAdapter, R.id.swipeRefreshLayout, R.id.emptyPandaView, R.id.listView);
// disable the swiperefreshlayout because we don't want to pull to refresh. It doesn't make an API call, so it wouldn't refresh anything
mRootView.findViewById(R.id.swipeRefreshLayout).setEnabled(false);
mSelect = (Button) mRootView.findViewById(R.id.select_option);
mSelect.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ModuleManager.selectMasteryPath(getCanvasContext(), mModuleObjectId, mModuleItemId, mAssignmentSet.getId(), mSelectOptionCallback);
}
});
setupCallbacks();
return mRootView;
}
use of com.instructure.canvasapi2.models.Assignment 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.Assignment in project instructure-android by instructure.
the class AssignmentBinder method bind.
public static void bind(Context context, final AssignmentViewHolder holder, final Assignment assignment, final int courseColor, final AdapterToFragmentCallback adapterToFragmentCallback) {
holder.title.setText(assignment.getName());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
adapterToFragmentCallback.onRowClicked(assignment, holder.getAdapterPosition(), true);
}
});
long courseId = assignment.getCourseId();
int color = ColorKeeper.getOrGenerateColor(CanvasContext.makeContextId(CanvasContext.Type.COURSE, courseId));
Submission submission = assignment.getSubmission();
if (assignment.isMuted()) {
// mute that score
holder.points.setVisibility(View.GONE);
} else {
holder.points.setVisibility(View.VISIBLE);
setupGradeText(context, holder.points, assignment, submission, courseColor);
}
final int drawable = getAssignmentIcon(assignment);
holder.icon.setImageDrawable(ColorKeeper.getColoredDrawable(context, drawable, color));
if (assignment.getDueAt() != null) {
holder.date.setText(DateHelper.createPrefixedDateTimeString(context, R.string.toDoDue, assignment.getDueAt()));
} else {
holder.date.setText(context.getResources().getString(R.string.toDoNoDueDate));
}
// set description to assignment description or excused
String description;
if (submission != null && submission.isExcused()) {
description = context.getString(R.string.excusedAssignment);
holder.description.setTypeface(null, Typeface.BOLD);
} else {
description = getHtmlAsText(assignment.getDescription());
holder.description.setTypeface(null, Typeface.NORMAL);
}
setCleanText(holder.description, description);
if (TextUtils.isEmpty(description)) {
setGone(holder.description);
} else {
setVisible(holder.description);
}
}
use of com.instructure.canvasapi2.models.Assignment in project instructure-android by instructure.
the class ScheduleItemBinder method bind.
public static void bind(final ScheduleItemViewHolder holder, final ScheduleItem item, final Context context, final int courseColor, final String contextName, final AdapterToFragmentCallback<ScheduleItem> adapterToFragmentCallback) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
adapterToFragmentCallback.onRowClicked(item, holder.getAdapterPosition(), false);
}
});
switch(item.getItemType()) {
case TYPE_SYLLABUS:
{
holder.title.setText(context.getString(R.string.syllabus));
Drawable drawable = ColorKeeper.getColoredDrawable(context, R.drawable.vd_syllabus, courseColor);
holder.icon.setImageDrawable(drawable);
break;
}
case TYPE_CALENDAR:
{
Drawable drawable = ColorKeeper.getColoredDrawable(context, R.drawable.vd_calendar, courseColor);
holder.icon.setImageDrawable(drawable);
holder.title.setText(item.getTitle());
holder.date.setText(item.getStartString(context));
String description = getHtmlAsText(item.getDescription());
setupDescription(description, holder.description);
break;
}
case TYPE_ASSIGNMENT:
holder.title.setText(item.getTitle());
Drawable drawable;
Assignment assignment = item.getAssignment();
if (assignment != null) {
final int drawableResId = getAssignmentIcon(assignment);
drawable = ColorKeeper.getColoredDrawable(context, drawableResId, courseColor);
holder.icon.setImageDrawable(drawable);
Date dueDate = assignment.getDueAt();
if (dueDate != null) {
String dateString = DateHelper.createPrefixedDateTimeString(context, R.string.toDoDue, dueDate);
holder.date.setText(dateString);
} else {
holder.date.setText(context.getResources().getString(R.string.toDoNoDueDate));
}
String description = getHtmlAsText(assignment.getDescription());
setupDescription(description, holder.description);
// submissions aren't included with the assignments in the api call, so we don't get grades
// so we'll never see the grade
setInvisible(holder.points);
} else {
drawable = ColorKeeper.getColoredDrawable(context, R.drawable.vd_calendar, courseColor);
holder.icon.setImageDrawable(drawable);
holder.date.setText(item.getStartString(context));
String description = getHtmlAsText(item.getDescription());
setupDescription(description, holder.description);
}
break;
}
}
use of com.instructure.canvasapi2.models.Assignment in project instructure-android by instructure.
the class AssignmentManager method getFirstPageAssignments.
public static void getFirstPageAssignments(CanvasContext canvasContext, final boolean forceNetwork, StatusCallback<List<Assignment>> callback) {
if (isTesting() || mTesting) {
} else {
final RestBuilder adapter = new RestBuilder(callback);
AssignmentAPI.getFirstPageAssignments(canvasContext.getId(), forceNetwork, adapter, callback);
}
}
Aggregations