Search in sources :

Example 11 with Attachment

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();
}
Also used : ListView(android.widget.ListView) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Dialog(android.app.Dialog) AlertDialog(android.support.v7.app.AlertDialog) UploadFilesDialog(com.instructure.pandautils.dialogs.UploadFilesDialog) LayoutInflater(android.view.LayoutInflater) Attachment(com.instructure.canvasapi2.models.Attachment) ImageView(android.widget.ImageView) AttachmentView(com.instructure.candroid.view.AttachmentView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View) AdapterView(android.widget.AdapterView) BeforePageView(com.instructure.canvasapi2.utils.pageview.BeforePageView) PageView(com.instructure.canvasapi2.utils.pageview.PageView) TextView(android.widget.TextView) ListView(android.widget.ListView) Paint(android.graphics.Paint)

Example 12 with Attachment

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);
    }
}
Also used : MediaComment(com.instructure.canvasapi2.models.MediaComment) Attachment(com.instructure.canvasapi2.models.Attachment)

Example 13 with Attachment

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();
                }
            }
        }
    };
}
Also used : Context(android.content.Context) Intent(android.content.Intent) Attachment(com.instructure.canvasapi2.models.Attachment) BroadcastReceiver(android.content.BroadcastReceiver) Paint(android.graphics.Paint)

Example 14 with Attachment

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();
            }
        }
    };
}
Also used : Navigation(com.instructure.interactions.Navigation) Submission(com.instructure.canvasapi2.models.Submission) LTITool(com.instructure.canvasapi2.models.LTITool) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) ArrayList(java.util.ArrayList) FileUploadNotification(com.instructure.pandautils.utils.FileUploadNotification) Response(retrofit2.Response) ApiType(com.instructure.canvasapi2.utils.ApiType) FileUploadEvent(com.instructure.pandautils.utils.FileUploadEvent) List(java.util.List) ArrayList(java.util.ArrayList)

Example 15 with Attachment

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);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Aggregations

DiscussionAttachment (com.instructure.canvasapi2.models.DiscussionAttachment)9 Test (org.junit.Test)9 Attachment (com.instructure.canvasapi2.models.Attachment)5 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)4 RestParams (com.instructure.canvasapi2.builders.RestParams)4 Date (java.util.Date)4 Paint (android.graphics.Paint)3 Intent (android.content.Intent)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ImageView (android.widget.ImageView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 AttachmentView (com.instructure.candroid.view.AttachmentView)2 RemoteFile (com.instructure.canvasapi2.models.RemoteFile)2 BeforePageView (com.instructure.canvasapi2.utils.pageview.BeforePageView)2 PageView (com.instructure.canvasapi2.utils.pageview.PageView)2 FileUploadNotification (com.instructure.pandautils.utils.FileUploadNotification)2 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)2 Dialog (android.app.Dialog)1