alamkanak / 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
3.42k stars 1.23k forks source link

Unable to display events #576

Closed madhall closed 2 years ago

madhall commented 2 years ago

Hi,

I have been able to display the view and get events from the DB to display on the calendar for the month and year asked for by the listener but nothing is being displayed onScreen

Can you please have a look at the code? to see why there is no events being shown,

Events timings are in timestamp and I am converting them and initializing the calendar with them to pass on as event start and end times

private fun getEvents(newYear: Int, newMonth: Int): ArrayList<WeekViewEvent?>{

    //Creating default events array for display in view
    val dispEventsArray = ArrayList<WeekViewEvent?>()
    dispEventsArray.clear()
    val calendar = java.util.Calendar.getInstance()

    lifecycle.coroutineScope.launch(Dispatchers.Default) {

        val db = AppDatabase.getDatabase(requireActivity())
        val events = db.eventsDao().getMnthlyEvents(newMonth,newYear)
        val calendarStart = ArrayList<java.util.Calendar?>()
        val calendarEnd = ArrayList<java.util.Calendar?>()
        var count = 0
        for (event in events) {
            var cal1 = Calendar.getInstance()
            var cal2 = Calendar.getInstance()
            cal1.timeInMillis = event.eventStart
            cal2.timeInMillis = event.eventEnd
            calendarStart.add(cal1)
            calendarEnd.add(cal2)
            val tmpEvent = WeekViewEvent(event.eventId,event.eventTitle,event.eventLocation,calendarStart[count],calendarEnd[count])
            tmpEvent.isAllDay = event.eventAllDay
            tmpEvent.color = resources.getColor(R.color.colorLightOther)
            dispEventsArray.add(tmpEvent)
            count += 1
        }
    }

    return ArrayList(dispEventsArray)
}