Search in sources :

Example 36 with Assignment

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

the class AssignmentManager method getAssignmentAirwolf.

public static void getAssignmentAirwolf(@NonNull String airwolfDomain, @NonNull String parentId, @NonNull String studentId, @NonNull String courseId, @NonNull String assignmentId, @NonNull StatusCallback<Assignment> callback) {
    RestBuilder adapter = new RestBuilder(callback);
    RestParams params = new RestParams.Builder().withShouldIgnoreToken(false).withPerPageQueryParam(false).withDomain(airwolfDomain).withAPIVersion("").build();
    AssignmentAPI.getAssignmentAirwolf(parentId, studentId, courseId, assignmentId, adapter, callback, params);
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 37 with Assignment

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

the class GradesListFragment method configureViews.

public void configureViews(View rootView) {
    // Not handled automatically as we cast from canvasContext;
    if (course == null) {
        return;
    }
    termSpinner = rootView.findViewById(R.id.termSpinner);
    AppBarLayout appBarLayout = rootView.findViewById(R.id.appbar);
    totalGradeView = rootView.findViewById(R.id.txtOverallGrade);
    showBasedOnGradedAssignmentsCB = rootView.findViewById(R.id.showTotalCheckBox);
    showWhatIfCheckbox = rootView.findViewById(R.id.showWhatIfCheckBox);
    toggleGradeView = rootView.findViewById(R.id.grade_toggle_view);
    toggleWhatIfScores = rootView.findViewById(R.id.what_if_view);
    Drawable lockDrawable = ColorKeeper.getColoredDrawable(getContext(), R.drawable.vd_lock, getResources().getColor(R.color.canvasTextDark));
    lockedGradeImage = rootView.findViewById(R.id.lockedGradeImage);
    lockedGradeImage.setImageDrawable(lockDrawable);
    setupListeners();
    lockGrade(course.isHideFinalGrades());
    dialogStyled = new WhatIfDialogStyled.WhatIfDialogCallback() {

        @Override
        public void onOkayClick(String whatIf, double total, Assignment assignment, int position) {
            // Create dummy submission for what if grade
            Submission s = new Submission();
            // check to see if grade is empty for reset
            if (TextUtils.isEmpty(whatIf)) {
                assignment.setSubmission(null);
                recyclerAdapter.getAssignmentsHash().get(assignment.getId()).setSubmission(null);
            } else {
                s.setScore(Double.parseDouble(whatIf));
                s.setGrade(whatIf);
                recyclerAdapter.getAssignmentsHash().get(assignment.getId()).setSubmission(s);
            }
            recyclerAdapter.notifyItemChanged(position);
            // Compute new overall grade
            new ComputeGradesTask(showBasedOnGradedAssignmentsCB.isChecked()).execute();
        }
    };
    appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int i) {
            // workaround for Toolbar not showing with swipe to refresh
            if (i == 0) {
                setRefreshingEnabled(true);
            } else {
                setRefreshingEnabled(false);
            }
        }
    });
}
Also used : WhatIfDialogStyled(com.instructure.candroid.dialog.WhatIfDialogStyled) Assignment(com.instructure.canvasapi2.models.Assignment) Submission(com.instructure.canvasapi2.models.Submission) Drawable(android.graphics.drawable.Drawable) AppBarLayout(android.support.design.widget.AppBarLayout)

Example 38 with Assignment

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

the class NotificationListFragment method addFragmentForStreamItem.

public static DialogFragment addFragmentForStreamItem(StreamItem streamItem, FragmentActivity activity, boolean fromWidget) {
    ParentFragment fragment = null;
    if (streamItem == null || activity == null) {
        return null;
    }
    String unsupportedLabel = null;
    switch(streamItem.getType()) {
        case SUBMISSION:
            if (streamItem.getAssignment() == null && streamItem.getCanvasContext() instanceof Course) {
                fragment = FragUtils.getFrag(AssignmentFragment.class, AssignmentFragment.Companion.createBundle(streamItem.getCanvasContext(), streamItem.getAssignmentId()));
            } else if (streamItem.getAssignment() != null && streamItem.getCanvasContext() instanceof Course) {
                // add an empty submission with the grade to the assignment so that we can see the score.
                Submission emptySubmission = new Submission();
                emptySubmission.setGrade(streamItem.getGrade());
                streamItem.getAssignment().setSubmission(emptySubmission);
                fragment = FragUtils.getFrag(AssignmentFragment.class, AssignmentFragment.Companion.createBundle((Course) streamItem.getCanvasContext(), streamItem.getAssignment()));
            }
            break;
        case ANNOUNCEMENT:
            if (streamItem.getCanvasContext() != null) {
                fragment = FragUtils.getFrag(DiscussionDetailsFragment.class, DiscussionDetailsFragment.makeBundle(streamItem.getCanvasContext(), streamItem.getDiscussionTopicId(), true));
            }
            break;
        case CONVERSATION:
            Conversation conversation = streamItem.getConversation();
            if (conversation != null) {
                // Check to see if the conversation has been deleted.
                if (conversation.isDeleted()) {
                    Toast.makeText(activity, R.string.deleteConversation, Toast.LENGTH_SHORT).show();
                    return null;
                }
                Bundle extras = InboxConversationFragment.createBundle(conversation, 0, null);
                fragment = FragUtils.getFrag(InboxConversationFragment.class, extras);
            }
            break;
        case DISCUSSION_TOPIC:
            if (streamItem.getCanvasContext() != null) {
                fragment = FragUtils.getFrag(DiscussionDetailsFragment.class, DiscussionDetailsFragment.makeBundle(streamItem.getCanvasContext(), streamItem.getDiscussionTopicId(), false));
            }
            break;
        case MESSAGE:
            if (streamItem.getAssignmentId() > 0) {
                if (streamItem.getCanvasContext() != null) {
                    fragment = FragUtils.getFrag(AssignmentFragment.class, AssignmentFragment.Companion.createBundle(activity, streamItem.getCanvasContext(), streamItem.getAssignmentId(), streamItem));
                }
            } else {
                fragment = FragUtils.getFrag(UnknownItemFragment.class, UnknownItemFragment.createBundle(streamItem.getCanvasContext(), streamItem));
            }
            break;
        case COLLABORATION:
            if (streamItem.getCanvasContext() != null) {
                unsupportedLabel = activity.getString(R.string.collaborations);
                fragment = UnSupportedTabFragment.createFragment(UnSupportedTabFragment.class, UnSupportedTabFragment.createBundle(streamItem.getCanvasContext(), Tab.COLLABORATIONS_ID, R.string.collaborations));
            }
            break;
        case CONFERENCE:
            if (streamItem.getCanvasContext() != null) {
                unsupportedLabel = activity.getString(R.string.conferences);
                fragment = UnSupportedTabFragment.createFragment(UnSupportedTabFragment.class, UnSupportedTabFragment.createBundle(streamItem.getCanvasContext(), Tab.CONFERENCES_ID, R.string.conferences));
            }
            break;
        default:
            if (streamItem.getCanvasContext() != null) {
                unsupportedLabel = streamItem.getType().toString();
                fragment = FragUtils.getFrag(UnSupportedFeatureFragment.class, UnSupportedFeatureFragment.createBundle(streamItem.getCanvasContext(), unsupportedLabel, streamItem.getUrl()));
            }
            break;
    }
    if (unsupportedLabel != null) {
        if (activity instanceof Navigation) {
            ((Navigation) activity).addFragment(fragment);
        }
    } else {
        if (activity instanceof Navigation && fragment != null) {
            ((Navigation) activity).addFragment(fragment);
        }
        if (fromWidget) {
            if (streamItem.getUrl() != null) {
                RouterUtils.routeUrl(activity, streamItem.getUrl(), false);
            } else {
                RouterUtils.routeUrl(activity, streamItem.getHtmlUrl(), false);
            }
        }
    }
    return null;
}
Also used : Navigation(com.instructure.interactions.Navigation) Submission(com.instructure.canvasapi2.models.Submission) Bundle(android.os.Bundle) Conversation(com.instructure.canvasapi2.models.Conversation) Course(com.instructure.canvasapi2.models.Course)

Example 39 with Assignment

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

the class AssignmentManager_Test method getAllAssignments.

public static void getAllAssignments(long courseId, StatusCallback<List<Assignment>> callback) {
    // TODO:
    Response httpResponse = new Response.Builder().request(new Request.Builder().url("https://test.com").build()).code(200).message("todo").protocol(Protocol.HTTP_1_0).body(ResponseBody.create(MediaType.parse("application/json"), "todo".getBytes())).addHeader("content-type", "application/json").build();
    List<Assignment> assignments = new ArrayList<>();
    retrofit2.Response<List<Assignment>> response = retrofit2.Response.success(assignments, httpResponse);
    callback.onResponse(response, new LinkHeaders(), ApiType.CACHE);
}
Also used : Response(okhttp3.Response) Assignment(com.instructure.canvasapi2.models.Assignment) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) Request(okhttp3.Request) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 40 with Assignment

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

the class AssignmentManager_Test method getAssignment.

public static void getAssignment(long assignmentId, long courseId, StatusCallback<Assignment> callback) {
    // TODO:
    Response httpResponse = new Response.Builder().request(new Request.Builder().url("https://test.com").build()).code(200).message("todo").protocol(Protocol.HTTP_1_0).body(ResponseBody.create(MediaType.parse("application/json"), "todo".getBytes())).addHeader("content-type", "application/json").build();
    Assignment assignment = new Assignment();
    retrofit2.Response<Assignment> response = retrofit2.Response.success(assignment, httpResponse);
    callback.onResponse(response, new LinkHeaders(), ApiType.CACHE);
}
Also used : Response(okhttp3.Response) Assignment(com.instructure.canvasapi2.models.Assignment) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) Request(okhttp3.Request)

Aggregations

Assignment (com.instructure.canvasapi2.models.Assignment)62 Test (org.junit.Test)46 Submission (com.instructure.canvasapi2.models.Submission)25 Date (java.util.Date)18 ArrayList (java.util.ArrayList)15 View (android.view.View)10 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)10 Course (com.instructure.canvasapi2.models.Course)9 RestParams (com.instructure.canvasapi2.builders.RestParams)7 Bundle (android.os.Bundle)6 ScheduleItem (com.instructure.canvasapi2.models.ScheduleItem)6 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)6 Navigation (com.instructure.interactions.Navigation)5 DrawableRes (android.support.annotation.DrawableRes)4 AdapterView (android.widget.AdapterView)4 TextView (android.widget.TextView)4 Request (okhttp3.Request)4 Response (okhttp3.Response)4 Paint (android.graphics.Paint)3 Drawable (android.graphics.drawable.Drawable)3