hi-manshu / Kalendar

Kalendar is a powerful and customizable calendar library for Android applications. It provides a flexible and intuitive way to display and interact with calendars in your app. With Kalendar, you can easily render calendar views, handle date selection, pagination, and range selection, and customize the layout to match your app's design.
https://www.himanshoe.com
Apache License 2.0
810 stars 67 forks source link

How to change only the color of Text on a special day (Sunday) #163

Closed ParkJongJoon7128 closed 1 year ago

ParkJongJoon7128 commented 1 year ago

I am developing Android layout using jetpack compose and kotlin. I'm developing a calendar view using the Kalendar library, and I'd like to color in Text only on certain days of the week, Sunday, and all other dates in black. I implemented the code as I wanted, but when I modified the code and ran the app, Kalendar's Text was all black, and I had a problem that when I clicked on a Sunday date, all the Text colors on the calendar turned red. How do I modify the code as I want?

This is code on My Project of Part:

                   val selectedDate = LocalDate.of(
                            year.toInt(), month.toInt(), day.toInt()
                        )
                        val dayOfWeek = selectedDate.dayOfWeek

                   val dayColor: Color = when (dayOfWeek.value) {
                                   6 -> Color.Blue
                                   7 -> Color(0xFFF86B6B)
                                   else -> Color.Black }

                   Kalendar(
                    currentDay = null,
                    kalendarType = KalendarType.Firey,
                    kalendarHeaderTextKonfig = KalendarTextKonfig(
                        kalendarTextColor = Color.Black, kalendarTextSize = 22.sp
                    ),
                    kalendarColors = KalendarColors(color = List(12) {
                        KalendarColor(
                            backgroundColor = Color.White,
                            dayBackgroundColor = Color(0xFFFFDAB9),
                            headerTextColor = Color.Black
                        )
                    }),
                    kalendarDayKonfig = KalendarDayKonfig(
                        size = 56.dp,
                        textSize = 14.sp,
                        textColor = dayColor,
                        selectedTextColor = dayColor,
                        borderColor = Color.Transparent
                    ),
                    daySelectionMode = DaySelectionMode.Single,
                    onDayClick = { localDate: kotlinx.datetime.LocalDate, kalendarEvents: List<KalendarEvent> ->
                        year = localDate.year.toString()
                        month = localDate.monthNumber.toString()
                        day = localDate.dayOfMonth.toString()

                        val selectedDate = LocalDate.of(
                            localDate.year, localDate.monthNumber, localDate.dayOfMonth
                        )
                        val dayOfWeek = selectedDate.dayOfWeek

                        dayString = when (dayOfWeek.value) {
                            1 -> "월요일"
                            2 -> "화요일"
                            3 -> "수요일"
                            4 -> "목요일"
                            5 -> "금요일"
                            6 -> "토요일"
                            7 -> "일요일"
                            else -> ""
                        }
                        scope.launch {
                            readTodo(token, year, month, day) {
                                todoList.clear()
                                for (i in it!!.data) {
                                    todoList.add(i)
                                }
                            }
                        }
                    },
                    headerContent = { month, year ->
                        Row(
                            modifier = Modifier.padding(start = 20.dp, bottom = 16.dp),
                            verticalAlignment = Alignment.CenterVertically,
                            horizontalArrangement = Arrangement.Start
                        ) {
                            Image(
                                modifier = Modifier.size(22.dp), painter = painterResource(
                                    id = R.drawable.headertextemogi
                                ), contentDescription = null
                            )

                            Spacer(modifier = Modifier.width(4.dp))

                            Text(
                                text = if (month.number.toString().length < 2) {
                                    "${year}. 0${month.number}"
                                } else {
                                    "${year}. ${month.number}"
                                },
                                fontSize = 22.sp,
                                lineHeight = 28.6.sp,
                                fontWeight = FontWeight(700),
                                color = Color(0xFF000000)
                            )
                        }
                    },
                    showLabel = true
                )

untitled