use of com.instructure.canvasapi2.models.Attachment 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.Attachment in project instructure-android by instructure.
the class SubmissionDetailsFragment method getMessageExtras.
private void getMessageExtras(final LinearLayout extras, SubmissionComment message) {
// Assume there are no media comments or attachments.
extras.removeAllViews();
// If there is a media comment, add it.
final MediaComment mc = message.getMediaComment();
if (mc != null) {
populateMediaComments(extras, message, mc);
}
// If there are attachments, add them.
final List<Attachment> atts = message.getAttachments();
if (atts != null) {
populateAttachments(extras, atts);
}
if (extras.getChildCount() > 0) {
populateExtras(extras);
}
}
use of com.instructure.canvasapi2.models.Attachment in project instructure-android by instructure.
the class SubmissionDetailsFragment method getAllUploadsCompleted.
// Creates new discussion reply with attachments for the user
private BroadcastReceiver getAllUploadsCompleted() {
return new BroadcastReceiver() {
@Override
public void onReceive(final Context context, final Intent intent) {
if (!isAdded()) {
return;
}
showToast(R.string.filesUploadedSuccessfully);
if (intent != null && intent.hasExtra(Const.ATTACHMENTS)) {
ArrayList<Attachment> intentAttachments = intent.getExtras().getParcelableArrayList(Const.ATTACHMENTS);
if (intentAttachments != null && intentAttachments.size() > 0) {
for (int i = 0; i < intentAttachments.size(); i++) {
Attachment attachment = intentAttachments.get(i);
attachments.add(attachment);
attachmentIds.add(attachment.getId());
}
refreshAttachments();
}
}
}
};
}
use of com.instructure.canvasapi2.models.Attachment in project instructure-android by instructure.
the class AddSubmissionFragment method setUpCallback.
// /////////////////////////////////////////////////////////////////////////
// CallBack
// /////////////////////////////////////////////////////////////////////////
public void setUpCallback() {
canvasCallbackSubmission = new StatusCallback<Submission>() {
@Override
public void onResponse(@NonNull Response<Submission> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (!apiCheck()) {
return;
}
Submission result = response.body();
if (result.getBody() != null || result.getUrl() != null) {
Toast.makeText(getActivity(), R.string.successPostingSubmission, Toast.LENGTH_LONG).show();
// clear text fields because they are saved
textSubmission.setText("");
urlSubmission.setText("");
// Send broadcast so list is updated.
EventBus.getDefault().post(new FileUploadEvent(new FileUploadNotification(null, new ArrayList<Attachment>())));
Navigation navigation = getNavigation();
if (navigation != null)
navigation.popCurrentFragment();
} else {
Toast.makeText(getActivity(), R.string.errorPostingSubmission, Toast.LENGTH_LONG).show();
}
}
};
mLTIToolCallback = new StatusCallback<List<LTITool>>() {
@Override
public void onResponse(@NonNull Response<List<LTITool>> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
for (LTITool ltiTool : response.body()) {
final String url = ltiTool.getUrl();
if (url != null && url.contains("instructuremedia.com/lti/launch")) {
mArcUpload.setVisibility(View.VISIBLE);
mArcLTITool = ltiTool;
break;
}
}
// check to see if we should automatically show the file upload dialog
showFileUploadDialog();
}
@Override
public void onFail(@Nullable Call<List<LTITool>> call, @NonNull Throwable error, @Nullable Response response) {
// we don't want to show it if this failed due to there being no cache
if (response != null && response.code() != 504) {
showFileUploadDialog();
}
}
};
}
use of com.instructure.canvasapi2.models.Attachment in project instructure-android by instructure.
the class DiscussionManager method replyToDiscussionEntry.
public static void replyToDiscussionEntry(CanvasContext canvasContext, long topicId, long entryId, String message, File attachment, String mimeType, StatusCallback<DiscussionEntry> callback) {
if (isTesting() || mTesting) {
// TODO:
} else {
RestBuilder adapter = new RestBuilder(callback);
RestParams params = new RestParams.Builder().build();
DiscussionAPI.replyToDiscussionEntryWithAttachment(adapter, canvasContext, topicId, entryId, message, attachment, mimeType, callback, params);
}
}
Aggregations