Search in sources :

Example 11 with DiscussionTopicHeader

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

the class DiscussionTopicHeaderTest method convertToDiscussionEntryTest_NullParent.

@Test
public void convertToDiscussionEntryTest_NullParent() throws Exception {
    DiscussionTopicHeader header = new DiscussionTopicHeader();
    DiscussionEntry entry = header.convertToDiscussionEntry("grade", "points");
    assertEquals(null, entry.getParent());
}
Also used : DiscussionTopicHeader(com.instructure.canvasapi2.models.DiscussionTopicHeader) DiscussionEntry(com.instructure.canvasapi2.models.DiscussionEntry) Test(org.junit.Test)

Example 12 with DiscussionTopicHeader

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

the class DiscussionTopicHeaderTest method getTypeTest_Unknown.

@Test
public void getTypeTest_Unknown() throws Exception {
    DiscussionTopicHeader discussionTopicHeader = new DiscussionTopicHeader();
    discussionTopicHeader.setDiscussionType("other");
    assertEquals(DiscussionTopicHeader.DiscussionType.UNKNOWN, discussionTopicHeader.getType());
}
Also used : DiscussionTopicHeader(com.instructure.canvasapi2.models.DiscussionTopicHeader) Test(org.junit.Test)

Example 13 with DiscussionTopicHeader

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

the class DiscussionTopicHeaderTest method getStatusTest_Unread.

@Test
public void getStatusTest_Unread() throws Exception {
    DiscussionTopicHeader discussionTopicHeader = new DiscussionTopicHeader();
    discussionTopicHeader.setReadState("unread");
    assertEquals(DiscussionTopicHeader.ReadState.UNREAD, discussionTopicHeader.getStatus());
}
Also used : DiscussionTopicHeader(com.instructure.canvasapi2.models.DiscussionTopicHeader) Test(org.junit.Test)

Example 14 with DiscussionTopicHeader

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

the class AnnouncementManager method getAnnouncements.

/**
 * Get announcements for the given context codes and date range. Currently this only works for
 * courses. All non-course context codes will be ignored.
 * @param contextCodes List of context_codes to retrieve announcements for (for example,
 *                     course_123). Only courses are presently supported and all non-course
 *                     context codes will be ignored.
 * @param startDate Only return announcements posted since the start_date (inclusive). May be null,
 *                  defaults to 14 days ago. The value should be formatted as: yyyy-mm-dd
 *                  or ISO 8601 YYYY-MM-DDTHH:MM:SSZ.
 * @param endDate Only return announcements posted before the end_date (inclusive). May be null,
 *                defaults to 28 days from start_date. The value should be formatted as: yyyy-mm-dd
 *                or ISO 8601 YYYY-MM-DDTHH:MM:SSZ. Announcements scheduled for future posting
 *                will only be returned to course administrators.
 * @param forceNetwork Force network
 * @param callback StatusCallback
 */
public static void getAnnouncements(@NonNull List<String> contextCodes, String startDate, String endDate, boolean forceNetwork, @NonNull StatusCallback<List<DiscussionTopicHeader>> callback) {
    // Use only course context codes
    ArrayList<String> courseContextCodes = new ArrayList<>();
    for (String code : contextCodes) {
        if (code != null && code.startsWith("course")) {
            courseContextCodes.add(code);
        }
    }
    // noinspection PointlessBooleanExpression
    if (isTesting() || mTesting) {
        AnnouncementManager_Test.getAnnouncements(courseContextCodes, startDate, endDate, callback);
    } else {
        RestBuilder adapter = new RestBuilder(callback);
        RestParams params = new RestParams.Builder().withForceReadFromNetwork(forceNetwork).build();
        AnnouncementAPI.getAnnouncements(courseContextCodes, startDate, endDate, adapter, callback, params);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) ArrayList(java.util.ArrayList) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 15 with DiscussionTopicHeader

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

the class AnnouncementManager method getAllAnnouncements.

public static void getAllAnnouncements(@NonNull CanvasContext canvasContext, boolean forceNetwork, StatusCallback<List<DiscussionTopicHeader>> callback) {
    if (isTesting() || mTesting) {
    // TODO:
    } else {
        final RestBuilder adapter = new RestBuilder(callback);
        final RestParams params = new RestParams.Builder().withForceReadFromNetwork(forceNetwork).withPerPageQueryParam(true).build();
        StatusCallback<List<DiscussionTopicHeader>> depaginatedCallback = new ExhaustiveListCallback<DiscussionTopicHeader>(callback) {

            @Override
            public void getNextPage(@NotNull StatusCallback<List<DiscussionTopicHeader>> callback, @NotNull String nextUrl, boolean isCached) {
                AnnouncementAPI.getNextPage(nextUrl, adapter, callback, params);
            }
        };
        adapter.setStatusCallback(depaginatedCallback);
        AnnouncementAPI.getFirstPageAnnouncements(canvasContext, adapter, depaginatedCallback, params);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) List(java.util.List) ArrayList(java.util.ArrayList) StatusCallback(com.instructure.canvasapi2.StatusCallback) DiscussionTopicHeader(com.instructure.canvasapi2.models.DiscussionTopicHeader) ExhaustiveListCallback(com.instructure.canvasapi2.utils.ExhaustiveListCallback) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DiscussionTopicHeader (com.instructure.canvasapi2.models.DiscussionTopicHeader)24 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)20 RestParams (com.instructure.canvasapi2.builders.RestParams)19 Test (org.junit.Test)17 List (java.util.List)6 StatusCallback (com.instructure.canvasapi2.StatusCallback)4 DiscussionEntry (com.instructure.canvasapi2.models.DiscussionEntry)4 ExhaustiveListCallback (com.instructure.canvasapi2.utils.ExhaustiveListCallback)4 ArrayList (java.util.ArrayList)4 NotNull (org.jetbrains.annotations.NotNull)4 DateTime (hirondelle.date4j.DateTime)3 Date (java.util.Date)3 Assignment (com.instructure.canvasapi2.models.Assignment)2 Course (com.instructure.canvasapi2.models.Course)2 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)2 Response (okhttp3.Response)2 ViewGroup (android.view.ViewGroup)1 AccountNotification (com.instructure.canvasapi2.models.AccountNotification)1 Group (com.instructure.canvasapi2.models.Group)1 ScheduleItem (com.instructure.canvasapi2.models.ScheduleItem)1