Search in sources :

Example 31 with ScheduleItem

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

the class SyllabusRecyclerAdapterTest method areContentsTheSame_NullDate.

@Test
public void areContentsTheSame_NullDate() {
    ScheduleItem item = new ScheduleItem();
    item.setTitle("item");
    item.setStartAt(new Date());
    ScheduleItem item1 = new ScheduleItem();
    item1.setTitle("item");
    item1.setStartAt(null);
    assertFalse(mAdapter.createItemCallback().areContentsTheSame(item, item1));
}
Also used : ScheduleItem(com.instructure.canvasapi2.models.ScheduleItem) Date(java.util.Date) Test(org.junit.Test)

Example 32 with ScheduleItem

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

the class SyllabusBinder method bind.

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

        @Override
        public void onClick(View view) {
            adapterToFragmentCallback.onRowClicked(item, holder.getAdapterPosition(), false);
        }
    });
    switch(item.getItemType()) {
        case TYPE_CALENDAR:
        case TYPE_ASSIGNMENT:
            holder.title.setText(item.getTitle());
            Drawable drawable;
            Assignment assignment = item.getAssignment();
            if (assignment != null) {
                int drawableResId = getAssignmentIcon(assignment);
                drawable = ColorKeeper.getColoredDrawable(context, drawableResId, courseColor);
                holder.icon.setImageDrawable(drawable);
                Date dueDate = assignment.getDueAt();
                holder.date.setTextColor(context.getResources().getColor(R.color.secondaryText));
                if (dueDate != null) {
                    String dateString = DateHelper.createPrefixedDateTimeString(context, R.string.toDoDue, dueDate);
                    holder.date.setText(dateString);
                } else {
                    holder.date.setText(context.getResources().getString(R.string.toDoNoDueDate));
                }
                String description = getHtmlAsText(assignment.getDescription());
                setCleanText(holder.description, description);
                if (TextUtils.isEmpty(description))
                    holder.description.setVisibility(View.GONE);
                else
                    holder.description.setVisibility(View.VISIBLE);
                // currently submissions aren't returned for the syllabus fragment, so points will be null.
                setGone(holder.points);
            } else {
                drawable = ColorKeeper.getColoredDrawable(context, R.drawable.vd_calendar, courseColor);
                holder.icon.setImageDrawable(drawable);
                setCleanText(holder.date, item.getStartDateString(context));
                String description = getHtmlAsText(item.getDescription());
                setCleanText(holder.description, description);
                if (TextUtils.isEmpty(description))
                    holder.description.setVisibility(View.GONE);
                else
                    holder.description.setVisibility(View.VISIBLE);
                holder.points.setText("");
            }
            break;
        default:
            Logger.d("UNSUPPORTED TYPE FOUND IN SYLLABUS BINDER");
            break;
    }
}
Also used : Assignment(com.instructure.canvasapi2.models.Assignment) Drawable(android.graphics.drawable.Drawable) View(android.view.View) Date(java.util.Date)

Example 33 with ScheduleItem

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

the class ScheduleItemBinder method bind.

public static void bind(final ScheduleItemViewHolder holder, final ScheduleItem item, final Context context, final int courseColor, final String contextName, final AdapterToFragmentCallback<ScheduleItem> adapterToFragmentCallback) {
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            adapterToFragmentCallback.onRowClicked(item, holder.getAdapterPosition(), false);
        }
    });
    switch(item.getItemType()) {
        case TYPE_SYLLABUS:
            {
                holder.title.setText(context.getString(R.string.syllabus));
                Drawable drawable = ColorKeeper.getColoredDrawable(context, R.drawable.vd_syllabus, courseColor);
                holder.icon.setImageDrawable(drawable);
                break;
            }
        case TYPE_CALENDAR:
            {
                Drawable drawable = ColorKeeper.getColoredDrawable(context, R.drawable.vd_calendar, courseColor);
                holder.icon.setImageDrawable(drawable);
                holder.title.setText(item.getTitle());
                holder.date.setText(item.getStartString(context));
                String description = getHtmlAsText(item.getDescription());
                setupDescription(description, holder.description);
                break;
            }
        case TYPE_ASSIGNMENT:
            holder.title.setText(item.getTitle());
            Drawable drawable;
            Assignment assignment = item.getAssignment();
            if (assignment != null) {
                final int drawableResId = getAssignmentIcon(assignment);
                drawable = ColorKeeper.getColoredDrawable(context, drawableResId, courseColor);
                holder.icon.setImageDrawable(drawable);
                Date dueDate = assignment.getDueAt();
                if (dueDate != null) {
                    String dateString = DateHelper.createPrefixedDateTimeString(context, R.string.toDoDue, dueDate);
                    holder.date.setText(dateString);
                } else {
                    holder.date.setText(context.getResources().getString(R.string.toDoNoDueDate));
                }
                String description = getHtmlAsText(assignment.getDescription());
                setupDescription(description, holder.description);
                // submissions aren't included with the assignments in the api call, so we don't get grades
                // so we'll never see the grade
                setInvisible(holder.points);
            } else {
                drawable = ColorKeeper.getColoredDrawable(context, R.drawable.vd_calendar, courseColor);
                holder.icon.setImageDrawable(drawable);
                holder.date.setText(item.getStartString(context));
                String description = getHtmlAsText(item.getDescription());
                setupDescription(description, holder.description);
            }
            break;
    }
}
Also used : Assignment(com.instructure.canvasapi2.models.Assignment) Drawable(android.graphics.drawable.Drawable) TextView(android.widget.TextView) View(android.view.View) Date(java.util.Date)

Example 34 with ScheduleItem

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

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

the class CalendarEventManager method getUpcomingEvents.

public static void getUpcomingEvents(StatusCallback<List<ScheduleItem>> callback, boolean forceNetwork) {
    if (isTesting() || mTesting) {
    // TODO
    } else {
        final RestBuilder adapter = new RestBuilder(callback);
        final RestParams params = new RestParams.Builder().withForceReadFromNetwork(forceNetwork).build();
        CalendarEventAPI.getUpcomingEvents(adapter, params, callback);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

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