Quivr / Android-Week-View

Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.
Apache License 2.0
258 stars 64 forks source link

Events Not loading after asynchronous call #108

Open williamkibira opened 6 years ago

williamkibira commented 6 years ago

Hello , i have my network call set up to add events as shown below Event Loading

@Override
    public void onSchedulesLoaded(int month, List<AntenatalSchedule> schedules) {
        scheduleLoader(schedules);
        weekView.notifyDatasetChanged();
    }
private void scheduleLoader(List<AntenatalSchedule> schedules) {
        weekViewEvents.clear();
        for (AntenatalSchedule schedule : schedules) {
            weekViewEvents.add(toWeekViewEvent(schedule));
            Log.d("APP", schedule.toString());
        }
    }
private WeekViewEvent toWeekViewEvent(AntenatalSchedule schedule) {
        Calendar now = Calendar.getInstance();
        Calendar startTime = (Calendar) now.clone();
        startTime.setTimeInMillis(schedule.getFrom().getMillis());
        startTime.set(Calendar.YEAR, now.get(Calendar.YEAR));
        startTime.set(Calendar.MONTH, now.get(Calendar.MONTH));
        startTime.set(Calendar.DAY_OF_MONTH, schedule.getFrom().getMonthOfYear());
        Calendar endTime = (Calendar) startTime.clone();
        endTime.setTimeInMillis(schedule.getTo().getMillis());
        endTime.set(Calendar.YEAR, endTime.get(Calendar.YEAR));
        endTime.set(Calendar.MONTH, endTime.get(Calendar.MONTH));
        endTime.set(Calendar.DAY_OF_MONTH, endTime.get(Calendar.DAY_OF_MONTH));
        // Create an week view event.
        WeekViewEvent weekViewEvent = new WeekViewEvent();
        weekViewEvent.setIdentifier(schedule.getId().toString());
        weekViewEvent.setName(schedule.getPatientName());
        weekViewEvent.setStartTime(startTime);
        weekViewEvent.setEndTime(endTime);
        weekViewEvent.setColor(Color.parseColor(schedule.getColorCode()));
        weekViewEvent.setLocation("");
        Log.d("APP",weekViewEvent.getStartTime().toString());
        Log.d("APP",weekViewEvent.getEndTime().toString());
        Log.d("APP",weekViewEvent.getName());
        Log.d("APP", weekViewEvent.toString());
        return weekViewEvent;
    }
weekView.setMonthChangeListener((newYear, newMonth) ->
        {
            Log.d("APP", "SCHEDULES ADDED TO VIEW");
            Log.d("APP", String.format("EVENT SIZE %d", weekViewEvents.size()));
            return weekViewEvents;
        });

i notice that the onMonthChange listener is triggered when a call to weekView.notifyDatasetChanged(); is called but, the events are not loaded . I have also tried weekView.invalidate(); and nothing happens either . Any advice on how to fix this problem would be greatly appreciated .