prolificinteractive / material-calendarview

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

Saving and accessing decorators #1127

Open dexter-ops opened 2 years ago

dexter-ops commented 2 years ago

I have implemented code through which a user can add decorators through a button click. But how do I permanently save it. Here is my decorator class:

class RedMarkDecorator(context: MainActivity?, currentDay: CalendarDay?) : DayViewDecorator {
        var myDay = currentDay
        var color = RED
        override fun shouldDecorate(day: CalendarDay?): Boolean {
            return day == myDay
        }

        override fun decorate(view: DayViewFacade) {
            view.addSpan(DotSpan(7f, color))
        }
    }

onDateSelected:

 override fun onDateSelected(
        widget: MaterialCalendarView,
        date: CalendarDay,
        selected: Boolean
    ) {
        // Toast.makeText(context,"$date",Toast.LENGTH_SHORT).show()
        redButton.isVisible = true
        greenButton.isVisible = true
        clearButton.isVisible = true
        val thisDate = calendarView.selectedDate?.date
        val date: CalendarDay = CalendarDay.from(thisDate)
        redButton.setOnClickListener {
            calendarView.addDecorator(RedMarkDecorator(myActivity, date))
        }

        greenButton.setOnClickListener {
            calendarView.addDecorator(GreenMarkDecorator(myActivity, date))
        }

        clearButton.setOnClickListener {
            calendarView.removeDecorator(RedMarkDecorator(myActivity,date))
            Toast.makeText(context,"cancel clicked",Toast.LENGTH_SHORT).show()
        }
    }