Search in sources :

Example 6 with Attachment

use of com.instructure.canvasapi2.models.Attachment in project instructure-android by instructure.

the class DiscussionAttachmentTest method shouldShowToUser_unlockedAndVisible.

@Test
public void shouldShowToUser_unlockedAndVisible() {
    DiscussionAttachment attachment = new DiscussionAttachment();
    attachment.setHidden(false);
    attachment.setHiddenForUser(false);
    attachment.setLocked(false);
    attachment.setLockedForUser(false);
    assertEquals(true, attachment.shouldShowToUser());
}
Also used : DiscussionAttachment(com.instructure.canvasapi2.models.DiscussionAttachment) Test(org.junit.Test)

Example 7 with Attachment

use of com.instructure.canvasapi2.models.Attachment in project instructure-android by instructure.

the class DiscussionAttachmentTest method shouldShowToUser_lockedForUser_unlockDateNotPassed.

@Test
public void shouldShowToUser_lockedForUser_unlockDateNotPassed() {
    Date lockDate = new Date(System.currentTimeMillis() + MILLIS_PER_DAY);
    DiscussionAttachment attachment = new DiscussionAttachment();
    attachment.setUnlockAt(APIHelper.dateToString(lockDate));
    attachment.setLockedForUser(true);
    assertEquals(false, attachment.shouldShowToUser());
}
Also used : DiscussionAttachment(com.instructure.canvasapi2.models.DiscussionAttachment) Date(java.util.Date) Test(org.junit.Test)

Example 8 with Attachment

use of com.instructure.canvasapi2.models.Attachment in project instructure-android by instructure.

the class DiscussionManager method postToDiscussionTopic.

public static void postToDiscussionTopic(CanvasContext canvasContext, long topicId, 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.postToDiscussionTopicWithAttachment(adapter, canvasContext, topicId, message, attachment, mimeType, callback, params);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 9 with Attachment

use of com.instructure.canvasapi2.models.Attachment in project instructure-android by instructure.

the class DiscussionManager method createDiscussion.

public static void createDiscussion(CanvasContext canvasContext, DiscussionTopicHeader newDiscussionHeader, @Nullable MultipartBody.Part attachment, StatusCallback<DiscussionTopicHeader> callback) {
    if (isTesting() || mTesting) {
    // TODO
    } else {
        RestBuilder adapter = new RestBuilder(callback);
        RestParams params = new RestParams.Builder().withPerPageQueryParam(false).withShouldIgnoreToken(false).build();
        DiscussionAPI.createDiscussion(adapter, params, canvasContext, newDiscussionHeader, attachment, callback);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 10 with Attachment

use of com.instructure.canvasapi2.models.Attachment in project instructure-android by instructure.

the class QuizQuestionsFragment method onFileUploadEvent.

@Subscribe(threadMode = ThreadMode.MAIN)
public void onFileUploadEvent(FileUploadEvent event) {
    // update the adapter item
    event.get(new Function1<FileUploadNotification, Unit>() {

        @Override
        public Unit invoke(FileUploadNotification notification) {
            final Intent statusIntent = notification.getIntent();
            if (statusIntent != null) {
                if (FileUploadService.QUIZ_UPLOAD_COMPLETE.equals(statusIntent.getAction())) {
                    if (statusIntent.hasExtra(Const.ATTACHMENT)) {
                        long questionId = statusIntent.getLongExtra(Const.QUIZ_ANSWER_ID, -1);
                        int position = statusIntent.getIntExtra(Const.POSITION, -1);
                        Attachment attachment = (Attachment) statusIntent.getExtras().get(Const.ATTACHMENT);
                        if (attachment != null && questionId != -1) {
                            quizQuestionAdapter.setFileUploadForQuiz(questionId, attachment, position);
                        }
                    }
                } else if (FileUploadService.UPLOAD_ERROR.equals(statusIntent.getAction())) {
                    final Bundle bundle = statusIntent.getExtras();
                    if (bundle != null && bundle.containsKey(Const.MESSAGE)) {
                        String errorMessage = bundle.getString(Const.MESSAGE);
                        if (null == errorMessage || "".equals(errorMessage)) {
                            errorMessage = getString(R.string.errorUploadingFile);
                        }
                        showToast(errorMessage);
                    }
                    final long questionId = statusIntent.getLongExtra(Const.QUIZ_ANSWER_ID, -1);
                    if (questionId != -1) {
                        final int position = statusIntent.getIntExtra(Const.POSITION, -1);
                        quizQuestionAdapter.setIsLoading(questionId, false, position);
                    }
                }
            }
            return null;
        }
    });
}
Also used : FileUploadNotification(com.instructure.pandautils.utils.FileUploadNotification) Bundle(android.os.Bundle) Intent(android.content.Intent) Attachment(com.instructure.canvasapi2.models.Attachment) Unit(kotlin.Unit) Subscribe(org.greenrobot.eventbus.Subscribe)

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