prolificinteractive / material-calendarview

A Material design back port of Android's CalendarView
https://prolificinteractive.github.io/material-calendarview/
MIT License
5.91k stars 1.32k forks source link

EventDecorator individually #1096

Open suseungiee opened 3 years ago

suseungiee commented 3 years ago

I'm trying to make calendar and what i want to do is when i click each date, the value of each date (let's say specialValue) increase individually from 0 step 1. I've made Event Decorator which get 2 parameter one is list of clicked dates and the other one is value of specialValue as i mention above..

As i understand when EventDecorator is added to Calendar which inherits DayViewDecorator, it operates function name 'decorate' when function name 'shouldDecorate' returns true. how can i operate 'decorate' function with clicked dates individually? not decorate every clicked dates same.. can you get it?..

for example when i clicked date 1, 2 times and clicked date 2, 3 times array of clicked date is date 1, 2 and array of specialValue is 2, 3

i want to decorate date1 as decorate type 2 and date 2 into decorate type 3 individually. not date 1, 2 as same decorate type 2 or either type 3.. Here is some part of my code

//EventDecorator.kt

class EventDecorator(date : MutableList, habitValue : MutableList) : DayViewDecorator { var thisDate = date //var thisHabitList = habitList var thisHabitValue = habitValue

var dayList : MutableList<CalendarDay> = mutableListOf<CalendarDay>()

override fun shouldDecorate(day: CalendarDay?): Boolean {
    //Log.d("!@#!@#@!#","-->>   ${thisDate}   ${thisHabitValue.get(0)}")
    return thisDate.equals(day)
    //Log.d("@#@#@#@#@3", "->  ${day!!.year}-${day!!.month}-${day!!.day}   ${thisDate.year}-${thisDate.month}-${thisDate.day}")

}

override fun decorate(view: DayViewFacade?) {

        if (thisHabitValue.get(0) % 4 == 0) {
                //view!!.addSpan(drawCross(Color.WHITE))
                view!!.addSpan(drawCircle(30f, Color.BLUE))
                view.addSpan(ForegroundColorSpan(Color.BLACK))

            } else if (thisHabitValue.get(0) % 4 == 1) {
                view!!.addSpan(drawCircle(30f, Color.WHITE))
                view.addSpan(drawTriangle(Color.parseColor("#346503")))
                view.addSpan(ForegroundColorSpan(Color.BLACK))
            } else if (thisHabitValue.get(0) % 4 == 2) {
                view!!.addSpan(drawTriangle(Color.WHITE))
                view.addSpan(drawCross(Color.RED))
                view.addSpan(ForegroundColorSpan(Color.BLACK))

            } else if (thisHabitValue.get(0) % 4 == 3) {
                view!!.addSpan(drawCross(Color.WHITE))
                view.addSpan(ForegroundColorSpan(Color.BLACK))
            }

        //thisHelper.updateHabitCalendarStatus(thisHabit)
        //Log.d("@#@#@#@#@#@", "${tempHabit.calendar_status.toInt()}")
    }

}

//ShowCalendar.kt

calendar.setOnDateChangedListener(object : OnDateSelectedListener { override fun onDateSelected(widget: MaterialCalendarView, date: CalendarDay, selected: Boolean) {

    /*var temp = (date.year-2021)*372 + (date.month)*31 + date.day
    calendar.addDecorator(EventDecorator(date,list.get(temp)))
    list.set(temp, list.get(temp)+1)*/
    Log.d("##########","before ${habitValue.size}   ${habitValue}")
    habitValue.clear()
    //calendarList.clear()
    calendarList.add(date)

    var title = intent.getStringExtra("itemTitle")
    var tempHabit = helper.selectHabitByTiTleAndDate(title!!,"${date.year}-${date.month}-${date.day}")
    if(tempHabit == null){  //없으면
        var temp = helper.selectHabitByTitle(title)
        temp!!.calendar_date="${date.year}-${date.month}-${date.day}"
        habitValue.add(0)
        temp!!.calendar_status++
        helper.insertHabit(temp)
    }
    else{ //있으면
        habitValue.add(tempHabit!!.calendar_status)
        tempHabit!!.calendar_status++
        helper.updateHabit(tempHabit)
    }
    Log.d("##########","after ${habitValue.size}   ${habitValue}")

    calendar.invalidateDecorators()  //refresh()

}

}) calendar.addDecorator(EventDecorator(calendarList, habitValue))