Search in sources :

Example 1 with ExhaustiveCallback

use of com.instructure.canvasapi2.utils.ExhaustiveCallback in project instructure-android by instructure.

the class CourseManager method getGroupsForCourse.

public static void getGroupsForCourse(long courseId, StatusCallback<List<Group>> callback, final boolean forceNetwork) {
    if (isTesting() || mTesting) {
    // TODO
    } else {
        final RestParams params = new RestParams.Builder().withForceReadFromNetwork(forceNetwork).withPerPageQueryParam(true).build();
        final RestBuilder adapter = new RestBuilder(callback);
        StatusCallback<List<Group>> exhaustiveCallback = new ExhaustiveListCallback<Group>(callback) {

            @Override
            public void getNextPage(@NonNull StatusCallback<List<Group>> callback, @NonNull String nextUrl, boolean isCached) {
                CourseAPI.getNextPageGroups(nextUrl, adapter, callback, params);
            }
        };
        adapter.setStatusCallback(exhaustiveCallback);
        CourseAPI.getFirstPageGroups(courseId, adapter, exhaustiveCallback, params);
    }
}
Also used : Group(com.instructure.canvasapi2.models.Group) RestParams(com.instructure.canvasapi2.builders.RestParams) NonNull(android.support.annotation.NonNull) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) ArrayList(java.util.ArrayList) List(java.util.List) StatusCallback(com.instructure.canvasapi2.StatusCallback) ExhaustiveListCallback(com.instructure.canvasapi2.utils.ExhaustiveListCallback)

Example 2 with ExhaustiveCallback

use of com.instructure.canvasapi2.utils.ExhaustiveCallback in project instructure-android by instructure.

the class CalendarEventManager method getCalendarEventsExhaustive.

public static void getCalendarEventsExhaustive(final boolean allEvents, @NonNull final CalendarEventAPI.CalendarEventType type, @Nullable final String startDate, @Nullable final String endDate, @NonNull final List<String> canvasContexts, @NonNull StatusCallback<List<ScheduleItem>> callback, boolean forceNetwork) {
    if (isTesting() || mTesting) {
        CalendarEventManager_Test.getCalendarEvents(callback);
    } else {
        final RestBuilder adapter = new RestBuilder(callback);
        final RestParams params = new RestParams.Builder().withPerPageQueryParam(true).withForceReadFromNetwork(forceNetwork).build();
        StatusCallback<List<ScheduleItem>> exhaustiveCallback = new ExhaustiveListCallback<ScheduleItem>(callback) {

            @Override
            public void getNextPage(@NonNull StatusCallback<List<ScheduleItem>> callback, @NonNull String nextUrl, boolean isCached) {
                CalendarEventAPI.getCalendarEvents(allEvents, type, startDate, endDate, canvasContexts, adapter, callback, params);
            }
        };
        adapter.setStatusCallback(exhaustiveCallback);
        CalendarEventAPI.getCalendarEvents(allEvents, type, startDate, endDate, canvasContexts, adapter, exhaustiveCallback, params);
    }
}
Also used : ScheduleItem(com.instructure.canvasapi2.models.ScheduleItem) RestParams(com.instructure.canvasapi2.builders.RestParams) NonNull(android.support.annotation.NonNull) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) ArrayList(java.util.ArrayList) List(java.util.List) StatusCallback(com.instructure.canvasapi2.StatusCallback) ExhaustiveListCallback(com.instructure.canvasapi2.utils.ExhaustiveListCallback)

Example 3 with ExhaustiveCallback

use of com.instructure.canvasapi2.utils.ExhaustiveCallback in project instructure-android by instructure.

the class QuizManager method getAllQuizSubmissions.

public static void getAllQuizSubmissions(final CanvasContext canvasContext, final long quizId, final boolean forceNetwork, final StatusCallback<List<QuizSubmission>> callback) {
    if (isTesting() || mTesting) {
        QuizManager_Test.getAllQuizSubmissions(callback);
    } else {
        final RestBuilder adapter = new RestBuilder(callback);
        final RestParams params = new RestParams.Builder().withPerPageQueryParam(true).withShouldIgnoreToken(false).withForceReadFromNetwork(forceNetwork).build();
        final ExhaustiveCallback<QuizSubmissionResponse, QuizSubmission> paginatedCallback = new ExhaustiveCallback<QuizSubmissionResponse, QuizSubmission>(callback) {

            @Override
            public void getNextPage(@NotNull StatusCallback<QuizSubmissionResponse> callback, @NotNull String nextUrl, boolean isCached) {
                QuizAPI.getQuizSubmissions(canvasContext, quizId, adapter, callback, params);
            }

            @NotNull
            @Override
            public List<QuizSubmission> extractItems(QuizSubmissionResponse response) {
                return response.getQuizSubmissions();
            }
        };
        adapter.setStatusCallback(paginatedCallback);
        QuizAPI.getQuizSubmissions(canvasContext, quizId, adapter, paginatedCallback, params);
    }
}
Also used : QuizSubmission(com.instructure.canvasapi2.models.QuizSubmission) RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) StatusCallback(com.instructure.canvasapi2.StatusCallback) NotNull(org.jetbrains.annotations.NotNull) ExhaustiveCallback(com.instructure.canvasapi2.utils.ExhaustiveCallback) QuizSubmissionResponse(com.instructure.canvasapi2.models.QuizSubmissionResponse)

Aggregations

StatusCallback (com.instructure.canvasapi2.StatusCallback)3 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)3 RestParams (com.instructure.canvasapi2.builders.RestParams)3 NonNull (android.support.annotation.NonNull)2 ExhaustiveListCallback (com.instructure.canvasapi2.utils.ExhaustiveListCallback)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Group (com.instructure.canvasapi2.models.Group)1 QuizSubmission (com.instructure.canvasapi2.models.QuizSubmission)1 QuizSubmissionResponse (com.instructure.canvasapi2.models.QuizSubmissionResponse)1 ScheduleItem (com.instructure.canvasapi2.models.ScheduleItem)1 ExhaustiveCallback (com.instructure.canvasapi2.utils.ExhaustiveCallback)1 NotNull (org.jetbrains.annotations.NotNull)1