Skip to content

Commit

Permalink
✨ 캘린더 연도 표시 추가 및 운동하지 않은 날짜에 콩찍히는 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-j0y committed Dec 8, 2022
1 parent dad7daa commit 2ae0d0e
Showing 1 changed file with 2 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import com.kizitonwose.calendarview.ui.DayBinder
import com.kizitonwose.calendarview.ui.ViewContainer
import com.whyranoid.presentation.R
import com.whyranoid.presentation.databinding.ItemCalendarDayBinding
import java.time.LocalDate

class CalendarDayBinder(
private val calendarView: CalendarView,
private val runningDays: List<List<String>>
) : DayBinder<CalendarDayBinder.DayContainer> {
private var calendar: CalendarRange = CalendarRange(null, null)

class DayContainer(
val binding: ItemCalendarDayBinding
Expand All @@ -34,7 +32,7 @@ class CalendarDayBinder(
R.color.gray
)
)
// day.day와 day.date.monthValue를 지정해서 특정 월, 일에 달렸다는 콩 표시 가능
container.binding.root.background = null
} else {
container.binding.tvCalendarDay.setTextColor(
ContextCompat.getColor(
Expand All @@ -45,19 +43,10 @@ class CalendarDayBinder(
container.binding.root.background = null
}

if (isInRange(day.date)) {
container.binding.root.setBackgroundColor(
ContextCompat.getColor(
calendarView.context,
R.color.gray
)
)
}

runningDays.forEach { runningDay ->
val (runningDayYear, runningDayMonth, runningDayDay) = runningDay.map { it.toInt() }

if (runningDayYear == day.date.year && runningDayMonth == day.date.monthValue && runningDayDay == day.day) {
if (runningDayYear == day.date.year && runningDayMonth == day.date.monthValue && runningDayDay == day.date.dayOfMonth) {
container.binding.root.background =
ContextCompat.getDrawable(
calendarView.context,
Expand All @@ -66,14 +55,4 @@ class CalendarDayBinder(
}
}
}

private fun isInRange(date: LocalDate): Boolean {
val (startDate, endDate) = this.calendar
return startDate == date || endDate == date || (startDate != null && endDate != null && startDate < date && date < endDate)
}
}

data class CalendarRange(
val startDate: LocalDate?,
val endDate: LocalDate?
)

0 comments on commit 2ae0d0e

Please sign in to comment.