Search in sources :

Example 26 with Submission

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

the class AssignmentAPI method getNextPageSubmissions.

public static void getNextPageSubmissions(@NonNull String nextUrl, @NonNull RestBuilder adapter, boolean forceNetwork, @NonNull StatusCallback<List<Submission>> callback) {
    RestParams params = new RestParams.Builder().withShouldIgnoreToken(false).withPerPageQueryParam(true).withForceReadFromNetwork(forceNetwork).build();
    callback.addCall(adapter.build(AssignmentInterface.class, params).getNextPageSubmissions(nextUrl)).enqueue(callback);
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 27 with Submission

use of com.instructure.canvasapi2.models.Submission 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 28 with Submission

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

the class AssignmentBinder method bind.

public static void bind(Context context, final AssignmentViewHolder holder, final Assignment assignment, final int courseColor, final AdapterToFragmentCallback adapterToFragmentCallback) {
    holder.title.setText(assignment.getName());
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            adapterToFragmentCallback.onRowClicked(assignment, holder.getAdapterPosition(), true);
        }
    });
    long courseId = assignment.getCourseId();
    int color = ColorKeeper.getOrGenerateColor(CanvasContext.makeContextId(CanvasContext.Type.COURSE, courseId));
    Submission submission = assignment.getSubmission();
    if (assignment.isMuted()) {
        // mute that score
        holder.points.setVisibility(View.GONE);
    } else {
        holder.points.setVisibility(View.VISIBLE);
        setupGradeText(context, holder.points, assignment, submission, courseColor);
    }
    final int drawable = getAssignmentIcon(assignment);
    holder.icon.setImageDrawable(ColorKeeper.getColoredDrawable(context, drawable, color));
    if (assignment.getDueAt() != null) {
        holder.date.setText(DateHelper.createPrefixedDateTimeString(context, R.string.toDoDue, assignment.getDueAt()));
    } else {
        holder.date.setText(context.getResources().getString(R.string.toDoNoDueDate));
    }
    // set description to assignment description or excused
    String description;
    if (submission != null && submission.isExcused()) {
        description = context.getString(R.string.excusedAssignment);
        holder.description.setTypeface(null, Typeface.BOLD);
    } else {
        description = getHtmlAsText(assignment.getDescription());
        holder.description.setTypeface(null, Typeface.NORMAL);
    }
    setCleanText(holder.description, description);
    if (TextUtils.isEmpty(description)) {
        setGone(holder.description);
    } else {
        setVisible(holder.description);
    }
}
Also used : Submission(com.instructure.canvasapi2.models.Submission) View(android.view.View)

Example 29 with Submission

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

the class AssignmentManager method getAllSubmissionsForAssignment.

public static void getAllSubmissionsForAssignment(long courseId, long assignmentId, final boolean forceNetwork, StatusCallback<List<Submission>> callback) {
    if (isTesting() || mTesting) {
        AssignmentManager_Test.getAllSubmissionsForAssignment(courseId, assignmentId, callback);
    } else {
        final RestBuilder adapter = new RestBuilder(callback);
        StatusCallback<List<Submission>> depaginatedCallback = new ExhaustiveListCallback<Submission>(callback) {

            @Override
            public void getNextPage(@NonNull StatusCallback<List<Submission>> callback, @NonNull String nextUrl, boolean isCached) {
                AssignmentAPI.getNextPageSubmissions(nextUrl, adapter, forceNetwork, callback);
            }
        };
        adapter.setStatusCallback(depaginatedCallback);
        AssignmentAPI.getFirstPageSubmissionsForAssignment(courseId, assignmentId, forceNetwork, adapter, depaginatedCallback);
    }
}
Also used : Submission(com.instructure.canvasapi2.models.Submission) NonNull(android.support.annotation.NonNull) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) List(java.util.List) StatusCallback(com.instructure.canvasapi2.StatusCallback) ExhaustiveListCallback(com.instructure.canvasapi2.utils.ExhaustiveListCallback)

Example 30 with Submission

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

the class AssignmentUtils2Test method getAssignmentState_stateExcused.

@Test
public void getAssignmentState_stateExcused() throws Exception {
    Assignment assignment = new Assignment();
    Submission submission = new Submission();
    submission.setExcused(true);
    assignment.setSubmission(submission);
    int testValue = AssignmentUtils2.getAssignmentState(assignment, submission);
    assertEquals("", testValue, AssignmentUtils2.ASSIGNMENT_STATE_EXCUSED);
}
Also used : Assignment(com.instructure.canvasapi2.models.Assignment) Submission(com.instructure.canvasapi2.models.Submission) Test(org.junit.Test)

Aggregations

Submission (com.instructure.canvasapi2.models.Submission)33 Assignment (com.instructure.canvasapi2.models.Assignment)20 Test (org.junit.Test)17 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)14 RestParams (com.instructure.canvasapi2.builders.RestParams)13 ArrayList (java.util.ArrayList)8 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)7 Date (java.util.Date)7 List (java.util.List)5 Request (okhttp3.Request)4 Response (okhttp3.Response)4 NonNull (android.support.annotation.NonNull)3 View (android.view.View)3 StatusCallback (com.instructure.canvasapi2.StatusCallback)3 GradeableStudentSubmission (com.instructure.canvasapi2.models.GradeableStudentSubmission)3 ApiType (com.instructure.canvasapi2.utils.ApiType)3 Navigation (com.instructure.interactions.Navigation)3 Response (retrofit2.Response)3 Intent (android.content.Intent)2 Paint (android.graphics.Paint)2