use of com.instructure.candroid.model.EventData 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();
}
use of com.instructure.candroid.model.EventData in project instructure-android by instructure.
the class CanvasCalendarGridAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View cellView = convertView;
// Grabs list of ExtraData objects for events
ArrayList<EventData> eventList = (ArrayList<EventData>) extraData.get(Const.EVENT_LIST);
if (convertView == null) {
cellView = inflater.inflate(R.layout.calendar_grid_textview, null);
}
TextView tv1 = (TextView) cellView.findViewById(R.id.tv1);
// Get dateTime of this cell
DateTime dateTime = this.datetimeList.get(position);
boolean noEvent = false;
boolean notSelected = false;
EventData.EventCount eventCount = EventData.EventCount.NONE;
// Customize for dates with events
if (eventList != null && eventList.size() > 0) {
EventData eventData = getExtraData(eventList, dateTime);
if (eventData != null) {
eventCount = eventData.getEventCount();
switch(eventCount) {
case MIN:
tv1.setBackgroundResource(R.drawable.calendar_min_events);
break;
case MID:
tv1.setBackgroundResource(R.drawable.calendar_mid_events);
break;
case MAX:
tv1.setBackgroundResource(R.drawable.calendar_max_events);
break;
}
} else {
noEvent = true;
}
} else {
noEvent = true;
}
// Customize for selected dates
if (selectedDates != null && selectedDates.indexOf(dateTime) != -1) {
switch(eventCount) {
case NONE:
tv1.setBackgroundResource(R.drawable.calendar_selected_event);
break;
case MIN:
tv1.setBackgroundResource(R.drawable.calendar_selected_min_events);
break;
case MID:
tv1.setBackgroundResource(R.drawable.calendar_selected_mid_events);
break;
case MAX:
tv1.setBackgroundResource(R.drawable.calendar_selected_max_events);
break;
}
} else {
notSelected = true;
}
// If a date is not selected or has no events we will reset the background resource
if (noEvent && notSelected) {
tv1.setBackgroundResource(0);
}
// select "today"
if (dateTime.equals(getToday())) {
if (!notSelected && !noEvent) {
switch(eventCount) {
case NONE:
tv1.setBackgroundResource(R.drawable.calendar_today_selected);
break;
case MIN:
tv1.setBackgroundResource(R.drawable.calendar_today_selected_min_events);
break;
case MID:
tv1.setBackgroundResource(R.drawable.calendar_today_selected_mid_events);
break;
case MAX:
tv1.setBackgroundResource(R.drawable.calendar_today_selected_max_events);
break;
}
} else if (!notSelected) {
tv1.setBackgroundResource(R.drawable.calendar_today_selected);
} else if (!noEvent) {
switch(eventCount) {
case MIN:
tv1.setBackgroundResource(R.drawable.calendar_today_min_events);
break;
case MID:
tv1.setBackgroundResource(R.drawable.calendar_today_mid_events);
break;
case MAX:
tv1.setBackgroundResource(R.drawable.calendar_today_max_events);
break;
}
} else {
tv1.setBackgroundResource(R.drawable.calendar_today);
}
}
// Set color of the dates in previous / next month
// if (dateTime.getMonth() != month) {
// tv1.setTextColor(resources
// .getColor(com.caldroid.R.color.caldroid_darker_gray));
// }
tv1.setText("" + dateTime.getDay());
return cellView;
}
Aggregations