Search in sources :

Example 6 with Assignment

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

the class DetailViewActivity method routeFromIntent.

private void routeFromIntent(Intent intent) {
    DETAIL_FRAGMENT fragmentType = (DETAIL_FRAGMENT) intent.getExtras().getSerializable(Const.FRAGMENT_TYPE);
    if (fragmentType != null) {
        Student student = intent.getExtras().getParcelable(Const.STUDENT);
        switch(fragmentType) {
            case WEEK:
                Student user = intent.getExtras().getParcelable(Const.USER);
                Course course = (Course) intent.getExtras().getSerializable(Const.COURSE);
                if (user != null && course != null) {
                    addFragment(CourseWeekFragment.newInstance(user, course));
                }
                break;
            case ASSIGNMENT:
                Assignment assignment = intent.getExtras().getParcelable(Const.ASSIGNMENT);
                String courseName = intent.getExtras().getString(Const.NAME);
                addFragment(AssignmentFragment.newInstance(assignment, courseName, student), false);
                break;
            case ANNOUNCEMENT:
                DiscussionTopicHeader announcement = intent.getExtras().getParcelable(Const.ANNOUNCEMENT);
                String announcementCourseName = intent.getExtras().getString(Const.NAME);
                addFragment(AnnouncementFragment.newInstance(announcement, announcementCourseName, student), false);
                break;
            case EVENT:
                ScheduleItem item = intent.getExtras().getParcelable(Const.SCHEDULE_ITEM);
                addFragment(EventFragment.newInstance(item, student), false);
                break;
            case SYLLABUS:
                Course syllabusCourse = (Course) intent.getExtras().getSerializable(Const.COURSE);
                addFragment(CourseSyllabusFragment.newInstance(syllabusCourse, student), false);
                break;
            case ACCOUNT_NOTIFICATION:
                AccountNotification accountNotification = intent.getExtras().getParcelable(Const.ACCOUNT_NOTIFICATION);
                addFragment(AccountNotificationFragment.newInstance(accountNotification, student));
        }
    }
}
Also used : Assignment(com.instructure.canvasapi2.models.Assignment) ScheduleItem(com.instructure.canvasapi2.models.ScheduleItem) DiscussionTopicHeader(com.instructure.canvasapi2.models.DiscussionTopicHeader) Student(com.instructure.canvasapi2.models.Student) Course(com.instructure.canvasapi2.models.Course) AccountNotification(com.instructure.canvasapi2.models.AccountNotification)

Example 7 with Assignment

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

the class CalendarWeekBinder method bind.

public static void bind(final Context context, final CalendarWeekViewHolder holder, final int courseColor, final ScheduleItem item, final AdapterToFragmentCallback<ScheduleItem> adapterToFragmentCallback, final Map<Long, Course> courseMap) {
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            adapterToFragmentCallback.onRowClicked(item, holder.getAdapterPosition(), false);
        }
    });
    if (item.hasAssignmentOverrides()) {
        String title = String.format(context.getResources().getString(R.string.week_assignment_override_title), item.getTitle(), item.getAssignmentOverrides().get(0).title);
        holder.title.setText(title);
    } else {
        holder.title.setText(item.getTitle());
    }
    switch(item.getItemType()) {
        case TYPE_CALENDAR:
        case TYPE_ASSIGNMENT:
            holder.title.setText(item.getTitle());
            Assignment assignment = item.getAssignment();
            // need to reset drawables
            holder.icon.setImageDrawable(null);
            holder.status.setBackgroundDrawable(null);
            holder.background.setBackgroundDrawable(null);
            setGone(holder.date);
            setVisible(holder.status);
            int drawable;
            if (assignment != null) {
                int assignmentState = AssignmentUtils2.getAssignmentState(assignment, assignment.getSubmission());
                holder.icon.setContentDescription(context.getString(R.string.assignment));
                switch(assignmentState) {
                    // Looks like: Submitted 95%, Color - Light blue
                    case (AssignmentUtils2.ASSIGNMENT_STATE_GRADED):
                        String gradeText = ViewUtils.getGradeText(AssignmentUtils2.ASSIGNMENT_STATE_GRADED, assignment.getSubmission().getScore(), assignment.getPointsPossible(), context);
                        holder.icon.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_done_white_18dp));
                        holder.status.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.assignment_graded_background));
                        holder.background.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.circle_background));
                        holder.status.setText(gradeText);
                        break;
                    // Looks like: Late 95%, Color - Orange-ish yellow
                    case (AssignmentUtils2.ASSIGNMENT_STATE_GRADED_LATE):
                        String lateGradeText = ViewUtils.getGradeText(AssignmentUtils2.ASSIGNMENT_STATE_GRADED_LATE, assignment.getSubmission().getScore(), assignment.getPointsPossible(), context);
                        holder.icon.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_done_white_18dp));
                        holder.status.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.late_assignment_background));
                        holder.background.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.orange_circle_background));
                        holder.status.setText(lateGradeText);
                        break;
                    // Looks like: Submitted, Color - Light blue
                    case (AssignmentUtils2.ASSIGNMENT_STATE_SUBMITTED):
                        holder.icon.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_done_white_18dp));
                        holder.status.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.assignment_submitted_background));
                        holder.background.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.light_blue_circle_background));
                        holder.status.setText(context.getString(R.string.submitted));
                        break;
                    // Looks like: Late, Color - Orange-ish yellow
                    case (AssignmentUtils2.ASSIGNMENT_STATE_SUBMITTED_LATE):
                        holder.icon.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_done_white_18dp));
                        holder.status.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.late_assignment_background));
                        holder.background.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.orange_circle_background));
                        holder.status.setText(context.getString(R.string.late));
                        break;
                    // Looks like: Missing, Color - Red!
                    case (AssignmentUtils2.ASSIGNMENT_STATE_MISSING):
                        holder.icon.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_warning_white_18dp));
                        holder.date.setVisibility(View.GONE);
                        holder.status.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.submission_missing_background));
                        holder.background.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.red_circle_background));
                        holder.status.setText(context.getString(R.string.missing));
                        break;
                    // Looks like: no status, assignment icon/grey
                    case (AssignmentUtils2.ASSIGNMENT_STATE_DUE):
                        // match assignment type icon
                        drawable = ViewUtils.getAssignmentIcon(assignment);
                        holder.icon.setImageDrawable(ColorKeeper.getColoredDrawable(context, drawable, context.getResources().getColor(R.color.gray)));
                        holder.background.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.read_circle_background));
                        setGone(holder.status);
                        break;
                    // Looks like: Excused, color, light blue
                    case (AssignmentUtils2.ASSIGNMENT_STATE_EXCUSED):
                        holder.icon.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_done_white_18dp));
                        holder.status.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.assignment_graded_background));
                        holder.background.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.circle_background));
                        holder.status.setText(context.getString(R.string.excused));
                        break;
                    // Looks like: In-Class, color, light green
                    case (AssignmentUtils2.ASSIGNMENT_STATE_IN_CLASS):
                        drawable = ViewUtils.getAssignmentIcon(assignment);
                        holder.icon.setImageDrawable(ColorKeeper.getColoredDrawable(context, drawable, context.getResources().getColor(R.color.gray)));
                        holder.status.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.assignment_in_class_background));
                        holder.background.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.read_circle_background));
                        holder.status.setText(context.getString(R.string.in_class));
                }
                setCleanText(holder.description, getCourseNameById(courseMap, item.getAssignment().getCourseId()));
            } else {
                // Calendar Event
                holder.icon.setImageDrawable(context.getResources().getDrawable(R.drawable.vd_calendar_month));
                holder.icon.setContentDescription(context.getString(R.string.calendar_event));
                holder.background.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.circle_background));
                holder.title.setText(item.getTitle());
                holder.date.setVisibility(View.VISIBLE);
                holder.date.setText(getStartString(context, item));
                setGone(holder.status);
                setCleanText(holder.description, getCourseNameById(courseMap, item.getCourseId()));
            }
            // We want to set this at the end so we get the a11y values
            com.instructure.pandautils.utils.Utils.testSafeContentDescription(holder.title, String.format(context.getString(R.string.calendar_title_content_desc), holder.getAdapterPosition()), holder.title.getText().toString(), BuildConfig.IS_TESTING);
            com.instructure.pandautils.utils.Utils.testSafeContentDescription(holder.description, String.format(context.getString(R.string.description_text_content_desc), holder.getAdapterPosition()), holder.description.getText().toString(), BuildConfig.IS_TESTING);
            com.instructure.pandautils.utils.Utils.testSafeContentDescription(holder.status, String.format(context.getString(R.string.status_text_content_desc), holder.getAdapterPosition()), holder.status.getText().toString(), BuildConfig.IS_TESTING);
            break;
        default:
            Logger.d("UNSUPPORTED TYPE FOUND IN SYLLABUS BINDER");
            break;
    }
}
Also used : Assignment(com.instructure.canvasapi2.models.Assignment) View(android.view.View)

Example 8 with Assignment

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

the class FileUploadAssignmentsAdapter method getOnlineUploadAssignmentsList.

public static ArrayList<Assignment> getOnlineUploadAssignmentsList(Context context, List<Assignment> newAssignments) {
    ArrayList<Assignment> onlineUploadAssignments = new ArrayList<>();
    Date currentDate = new Date();
    for (Assignment assignment : newAssignments) {
        if (assignment.getSubmissionTypes().contains(Assignment.SUBMISSION_TYPE.ONLINE_UPLOAD) && (assignment.getLockAt() == null || (assignment.getLockAt() != null && currentDate.before(assignment.getLockAt())))) {
            onlineUploadAssignments.add(assignment);
        }
    }
    // if empty, add no assignments assignment. Else add a selection prompt.
    if (onlineUploadAssignments.size() == 0) {
        Assignment noAssignments = new Assignment();
        noAssignments.setId(Long.MIN_VALUE);
        noAssignments.setName(context.getString(R.string.noAssignmentsWithFileUpload));
        onlineUploadAssignments.add(noAssignments);
    }
    return onlineUploadAssignments;
}
Also used : Assignment(com.instructure.canvasapi2.models.Assignment) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 9 with Assignment

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

the class GradesListRecyclerAdapter method compareAssignments.

private boolean compareAssignments(Assignment oldItem, Assignment newItem) {
    boolean isSameName = oldItem.getName().equals(newItem.getName());
    boolean isSameScore = oldItem.getPointsPossible() == newItem.getPointsPossible();
    boolean isSameSubmission = true;
    boolean isSameGrade = true;
    Submission oldSubmission = oldItem.getSubmission();
    Submission newSubmission = newItem.getSubmission();
    if (oldSubmission != null && newSubmission != null) {
        if (oldSubmission.getGrade() != null && newSubmission.getGrade() != null) {
            isSameGrade = oldSubmission.getGrade().equals(newSubmission.getGrade());
        } else if (isNullableChanged(oldSubmission.getGrade(), newSubmission.getGrade())) {
            isSameGrade = false;
        }
    } else if (isNullableChanged(oldSubmission, newSubmission)) {
        isSameSubmission = false;
    }
    return isSameName && isSameGrade && isSameScore && isSameSubmission;
}
Also used : Submission(com.instructure.canvasapi2.models.Submission)

Example 10 with Assignment

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

the class SyllabusRecyclerAdapter method populateAdapter.

private void populateAdapter(List<ScheduleItem> scheduleItems) {
    if (mCanvasContext.getType() == CanvasContext.Type.COURSE) {
        Course course = (Course) mCanvasContext;
        ScheduleItem syllabus = ScheduleItem.createSyllabus(course.getName(), course.getSyllabusBody());
        addOrUpdateItem(mSyllabus, syllabus);
    }
    Date curDate = new Date();
    // set a future date 7 days in the future, make it the end of the day to include every assignment within the next 7 days,
    // including assignments that are due at the end of the 7th day
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, 7);
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    Date weekFutureDate = calendar.getTime();
    for (ScheduleItem scheduleItem : scheduleItems) {
        // if it is hidden we don't want to show it. This can happen when an event has multiple sections
        if ((scheduleItem.isHidden())) {
            continue;
        }
        Date dueDate = scheduleItem.getStartAt();
        if (dueDate == null) {
            addOrUpdateItem(mNoDate, scheduleItem);
        } else if (dueDate.before(curDate)) {
            addOrUpdateItem(mPast, scheduleItem);
        } else if (((dueDate.after(curDate) && (dueDate.before(weekFutureDate))) || dueDate.equals(weekFutureDate))) {
            addOrUpdateItem(mNext7Days, scheduleItem);
        } else if (dueDate.after(weekFutureDate)) {
            addOrUpdateItem(mFuture, scheduleItem);
        }
    }
}
Also used : ScheduleItem(com.instructure.canvasapi2.models.ScheduleItem) Calendar(java.util.Calendar) Course(com.instructure.canvasapi2.models.Course) Date(java.util.Date)

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