Search in sources :

Example 1 with ScheduleItem

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

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

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

the class CalendarListRecyclerAdapter method countDateInEvents.

/**
 * Small helper method for getExtraData(), determines how many events coincide with each date.
 *
 * @param d
 * @return
 */
private int countDateInEvents(Date d) {
    int count = 0;
    DateTime dateTime = DateTime.forInstant(d.getTime(), TimeZone.getDefault());
    for (ScheduleItem scheduleItem : mAllEvents) {
        DateTime compareDate = DateTime.forInstant(scheduleItem.getStartAt().getTime(), TimeZone.getDefault());
        if (dateTime.getMonth().equals(compareDate.getMonth()) && dateTime.getDay().equals(compareDate.getDay()) && dateTime.getYear().equals(compareDate.getYear())) {
            count++;
        }
    }
    return count;
}
Also used : ScheduleItem(com.instructure.canvasapi2.models.ScheduleItem) DateTime(hirondelle.date4j.DateTime)

Example 4 with ScheduleItem

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

the class CalendarListRecyclerAdapter method getExtraData.

/**
 * A small helper method used to create a data list for use in getView for the calendar grid
 * used to determine when dates have events and how many.
 */
private void getExtraData() {
    HashMap<String, Object> hashMap = mAdapterToCalendarCallback.getExtraCalendarData();
    ArrayList<EventData> eventList = new ArrayList<>();
    // flush mAllEvents
    HashSet<ScheduleItem> hs = new HashSet<>();
    hs.addAll(mAllEvents);
    mAllEvents.clear();
    mAllEvents.addAll(hs);
    // todo optimize
    for (ScheduleItem s : mAllEvents) {
        Date d = s.getStartAt();
        DateTime dateTime = DateTime.forInstant(d.getTime(), TimeZone.getDefault());
        int dateCount = countDateInEvents(d);
        if (dateCount == 1) {
            // ExtraData(date, number of events)
            eventList.add(new EventData(dateTime, EventData.EventCount.MIN));
        } else if (dateCount >= 2 && dateCount <= 5) {
            eventList.add(new EventData(dateTime, EventData.EventCount.MID));
        } else {
            eventList.add(new EventData(dateTime, EventData.EventCount.MAX));
        }
    }
    hashMap.put(Const.EVENT_LIST, eventList);
    mAdapterToCalendarCallback.refreshCalendarFragment();
    refreshListView();
    mAdapterToCalendarCallback.hidePandaLoading();
}
Also used : ScheduleItem(com.instructure.canvasapi2.models.ScheduleItem) ArrayList(java.util.ArrayList) EventData(com.instructure.candroid.model.EventData) Date(java.util.Date) DateTime(hirondelle.date4j.DateTime) HashSet(java.util.HashSet)

Example 5 with ScheduleItem

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

the class CalendarListRecyclerAdapter method onBindChildHolder.

// region ViewHolder Configuration
@Override
public void onBindChildHolder(RecyclerView.ViewHolder holder, Date date, ScheduleItem item) {
    final CanvasContext canvasContext = getCanvasContextForItem(item);
    final int courseColor = ColorKeeper.getOrGenerateColor(canvasContext);
    ScheduleItemBinder.bind((ScheduleItemViewHolder) holder, item, getContext(), courseColor, getContextName(item), mAdapterToFragmentCallback);
}
Also used : CanvasContext(com.instructure.canvasapi2.models.CanvasContext)

Aggregations

ScheduleItem (com.instructure.canvasapi2.models.ScheduleItem)29 Test (org.junit.Test)19 Date (java.util.Date)13 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)9 RestParams (com.instructure.canvasapi2.builders.RestParams)8 Assignment (com.instructure.canvasapi2.models.Assignment)7 ArrayList (java.util.ArrayList)5 View (android.view.View)3 Course (com.instructure.canvasapi2.models.Course)3 List (java.util.List)3 Drawable (android.graphics.drawable.Drawable)2 NonNull (android.support.annotation.NonNull)2 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 ToDo (com.instructure.canvasapi2.models.ToDo)2 Navigation (com.instructure.interactions.Navigation)2 DateTime (hirondelle.date4j.DateTime)2 Bundle (android.os.Bundle)1 TextView (android.widget.TextView)1 SyllabusRecyclerAdapter (com.instructure.candroid.adapter.SyllabusRecyclerAdapter)1