use of com.instructure.canvasapi2.models.Assignment in project instructure-android by instructure.
the class SubmissionDetailsFragment method showFileList.
/**
* this will display a dialog list of the attachments for the assignment. Tapping on one will open it.
*
* @param attachments
*/
private void showFileList(ArrayList<Attachment> attachments) {
// create a new dialog
Dialog dlg = new Dialog(getActivity());
LayoutInflater li = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// inflate the view
View v = li.inflate(R.layout.dialog_listview, null, false);
dlg.setContentView(v);
ListView lv = (ListView) v.findViewById(R.id.listview);
// create the adapter
SubmissionFileAdapter fileAdapter = new SubmissionFileAdapter(getActivity(), R.layout.listview_item_row_attachedfiles, attachments);
dlg.setTitle(getString(R.string.myFiles));
lv.setAdapter(fileAdapter);
// when they tap an item, open it
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
Attachment attachment = (Attachment) adapter.getAdapter().getItem(position);
// If this is a pdf, we want to make sure we disable annotations/etc
if (attachment.getContentType().contains("pdf")) {
openMedia(true, attachment.getContentType(), attachment.getUrl(), attachment.getFilename());
} else {
openMedia(attachment.getContentType(), attachment.getUrl(), attachment.getFilename());
}
}
});
dlg.show();
}
use of com.instructure.canvasapi2.models.Assignment in project instructure-android by instructure.
the class SubmissionDetailsFragment method setupCallbacks.
// /////////////////////////////////////////////////////////////////////////
// CallBack
// /////////////////////////////////////////////////////////////////////////
public void setupCallbacks() {
notoriousConfigCallback = new StatusCallback<NotoriousConfig>() {
@Override
public void onResponse(@NonNull Response<NotoriousConfig> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (!apiCheck()) {
return;
}
NotoriousConfig notoriousConfig = response.body();
if (notoriousConfig.isEnabled()) {
mediaComment.setEnabled(true);
}
}
};
// We use a NoNetworkErrorDelegate because sometimes old submissions are deleted.
// We don't want to display unnecessary croutons.
canvasCallbackSubmission = new StatusCallback<Submission>() {
@Override
public void onResponse(@NonNull Response<Submission> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (!apiCheck()) {
return;
}
if (response.body() != null) {
populateAdapter(response.body());
}
}
};
canvasCallbackMessage = new StatusCallback<Submission>() {
@Override
public void onResponse(@NonNull Response<Submission> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (!apiCheck()) {
return;
}
// See if it was successful.
Submission submission = response.body();
if (submission != null) {
SubmissionComment comment = submission.getSubmissionComments().get(submission.getSubmissionComments().size() - 1);
// Our list is a list of Submission, so add the comment to a SubmissionGrade object
Submission newSub = new Submission();
ArrayList<SubmissionComment> comments = new ArrayList<>();
comments.add(comment);
newSub.setSubmittedAt(comment.getCreatedAt());
newSub.setSubmissionComments(comments);
adapter.subList.add(0, newSub);
message.setText("");
} else {
showToast(R.string.errorPostingComment);
}
adapter.notifyDataSetChanged();
// Close the keyboard
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(message.getWindowToken(), 0);
// Enable the send message button again
submitComment.setVisibility(View.VISIBLE);
sendingProgressBar.setVisibility(View.GONE);
// Clear the attachments list
attachmentsList.clear();
attachmentIds.clear();
attachments.clear();
refreshAttachments();
}
@Override
public void onFail(@Nullable Call<Submission> call, @NonNull Throwable error, @Nullable Response response) {
// Enable the send message button again if there was an Error
submitComment.setVisibility(View.VISIBLE);
sendingProgressBar.setVisibility(View.GONE);
// Clear the attachments list
attachmentsList.clear();
attachmentIds.clear();
attachments.clear();
refreshAttachments();
}
};
canvasCallbackLTITool = new StatusCallback<LTITool>() {
@Override
public void onResponse(@NonNull Response<LTITool> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (!apiCheck()) {
return;
}
LTITool ltiTool = response.body();
String url = ltiTool.getUrl();
// Append platform for quizzes 2 lti tool
Uri uri = Uri.parse(url).buildUpon().appendQueryParameter("platform", "android").build();
// Do NOT authenticate or the LTI tool won't load.
InternalWebviewFragment.Companion.loadInternalWebView(getActivity(), ((Navigation) getActivity()), InternalWebviewFragment.Companion.createBundle(getCanvasContext(), uri.toString(), ltiTool.getName(), false, false, true, assignment.getUrl()));
}
@Override
public void onFail(@Nullable Call<LTITool> call, @NonNull Throwable error, @Nullable Response response) {
// If it wasn't a network Error, then the LTI tool must be expired or invalid.
if (APIHelper.hasNetworkConnection() && (response == null || (response != null && response.code() != 504))) {
showToast(R.string.invalidExternal);
}
}
};
canvasCallbackAssignment = new StatusCallback<Assignment>() {
@Override
public void onResponse(@NonNull Response<Assignment> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (!apiCheck()) {
return;
}
Assignment newAssignment = response.body();
String authenticationURL;
if (newAssignment == null) {
authenticationURL = null;
} else {
authenticationURL = newAssignment.getUrl();
}
// Now get the LTITool
// This API call handles url being null
SubmissionManager.getLtiFromAuthenticationUrl(authenticationURL, canvasCallbackLTITool, true);
}
};
}
use of com.instructure.canvasapi2.models.Assignment in project instructure-android by instructure.
the class ToDoListFragment method onRowClick.
private void onRowClick(ToDo toDo) {
if (toDo == null) {
return;
}
Bundle bundle = new Bundle();
bundle.putParcelable(Const.SELECTED_ITEM, toDo);
Navigation navigation = getNavigation();
if (navigation != null) {
if (toDo.getAssignment() != null) {
// Launch assignment details fragment.
navigation.addFragment(FragUtils.getFrag(AssignmentFragment.class, createBundle(toDo.getCanvasContext(), toDo.getAssignment())));
} else if (toDo.getScheduleItem() != null) {
// It's a Calendar event from the Upcoming API.
ScheduleItem scheduleItem = toDo.getScheduleItem();
String actionBarTitle = "";
if (scheduleItem.getContextType() == CanvasContext.Type.COURSE) {
actionBarTitle = toDo.getCanvasContext().getName();
} else if (scheduleItem.getContextType() == CanvasContext.Type.USER) {
actionBarTitle = getContext().getString(R.string.PersonalCalendar);
}
navigation.addFragment(FragUtils.getFrag(CalendarEventFragment.class, createBundle(toDo.getCanvasContext(), actionBarTitle, toDo.getScheduleItem())));
}
}
}
use of com.instructure.canvasapi2.models.Assignment in project instructure-android by instructure.
the class AssignmentDateListRecyclerAdapterTest method testAreContentsTheSame_oneNullDueDate.
@Test
public void testAreContentsTheSame_oneNullDueDate() {
Assignment assignmentDueDate = new Assignment();
assignmentDueDate.setName("Assign1");
assignmentDueDate.setDueAt(APIHelper.dateToString(new Date()));
Assignment assignment1 = new Assignment();
assignment1.setName("Assign1");
assertFalse(mAdapter.createItemCallback().areContentsTheSame(assignmentDueDate, assignment1));
assertFalse(mAdapter.createItemCallback().areContentsTheSame(assignment1, assignmentDueDate));
assertTrue(mAdapter.createItemCallback().areContentsTheSame(assignmentDueDate, assignmentDueDate));
}
use of com.instructure.canvasapi2.models.Assignment in project instructure-android by instructure.
the class AssignmentGroupListRecyclerAdapterTest method testAreContentsTheSame_oneNullDueDate.
@Test
public void testAreContentsTheSame_oneNullDueDate() {
Assignment assignmentDueDate = new Assignment();
assignmentDueDate.setName("Assign1");
assignmentDueDate.setDueAt(APIHelper.dateToString(new Date()));
Assignment assignment1 = new Assignment();
assignment1.setName("Assign1");
assertFalse(mAdapter.createItemCallback().areContentsTheSame(assignmentDueDate, assignment1));
assertFalse(mAdapter.createItemCallback().areContentsTheSame(assignment1, assignmentDueDate));
assertTrue(mAdapter.createItemCallback().areContentsTheSame(assignmentDueDate, assignmentDueDate));
}
Aggregations