Skip to content

Commit

Permalink
Fix background drawable (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
kizitonwose authored Jan 14, 2025
1 parent d3d19ac commit 0e1b654
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,18 @@ class Example4Fragment : BaseFragment(R.layout.example_4_fragment), HasToolbar,
}

private fun configureBinders() {
val clipLevelHalf = 5000
val ctx = requireContext()
val rangeStartBackground =
ctx.getDrawableCompat(R.drawable.example_4_continuous_selected_bg_start).also {
class DayViewContainer(view: View) : ViewContainer(view) {
val clipLevelHalf = 5000
val rangeStartBackground = view.context.getDrawableCompat(R.drawable.example_4_continuous_selected_bg_start).also {
it.level = clipLevelHalf // Used by ClipDrawable
}
val rangeEndBackground =
ctx.getDrawableCompat(R.drawable.example_4_continuous_selected_bg_end).also {
val rangeEndBackground = view.context.getDrawableCompat(R.drawable.example_4_continuous_selected_bg_end).also {
it.level = clipLevelHalf // Used by ClipDrawable
}
val rangeMiddleBackground =
ctx.getDrawableCompat(R.drawable.example_4_continuous_selected_bg_middle)
val singleBackground = ctx.getDrawableCompat(R.drawable.example_4_single_selected_bg)
val todayBackground = ctx.getDrawableCompat(R.drawable.example_4_today_bg)
val rangeMiddleBackground = view.context.getDrawableCompat(R.drawable.example_4_continuous_selected_bg_middle)
val singleBackground = view.context.getDrawableCompat(R.drawable.example_4_single_selected_bg)
val todayBackground = view.context.getDrawableCompat(R.drawable.example_4_today_bg)

class DayViewContainer(view: View) : ViewContainer(view) {
lateinit var day: CalendarDay // Will be set when this container is bound.
val binding = Example4CalendarDayBinding.bind(view)

Expand Down Expand Up @@ -200,26 +196,31 @@ class Example4Fragment : BaseFragment(R.layout.example_4_fragment), HasToolbar,
when {
startDate == data.date && endDate == null -> {
textView.setTextColorRes(R.color.white)
roundBgView.applyBackground(singleBackground)
roundBgView.applyBackground(container.singleBackground)
}

data.date == startDate -> {
textView.setTextColorRes(R.color.white)
continuousBgView.applyBackground(rangeStartBackground)
roundBgView.applyBackground(singleBackground)
continuousBgView.applyBackground(container.rangeStartBackground)
roundBgView.applyBackground(container.singleBackground)
}

startDate != null && endDate != null && (data.date > startDate && data.date < endDate) -> {
textView.setTextColorRes(R.color.example_4_grey)
continuousBgView.applyBackground(rangeMiddleBackground)
continuousBgView.applyBackground(container.rangeMiddleBackground)
}

data.date == endDate -> {
textView.setTextColorRes(R.color.white)
continuousBgView.applyBackground(rangeEndBackground)
roundBgView.applyBackground(singleBackground)
continuousBgView.applyBackground(container.rangeEndBackground)
roundBgView.applyBackground(container.singleBackground)
}

data.date == today -> {
textView.setTextColorRes(R.color.example_4_grey)
roundBgView.applyBackground(todayBackground)
roundBgView.applyBackground(container.todayBackground)
}

else -> textView.setTextColorRes(R.color.example_4_grey)
}
}
Expand All @@ -231,14 +232,15 @@ class Example4Fragment : BaseFragment(R.layout.example_4_fragment), HasToolbar,
endDate != null &&
isInDateBetweenSelection(data.date, startDate, endDate)
) {
continuousBgView.applyBackground(rangeMiddleBackground)
continuousBgView.applyBackground(container.rangeMiddleBackground)
}

DayPosition.OutDate ->
if (startDate != null &&
endDate != null &&
isOutDateBetweenSelection(data.date, startDate, endDate)
) {
continuousBgView.applyBackground(rangeMiddleBackground)
continuousBgView.applyBackground(container.rangeMiddleBackground)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,20 @@ internal class DayHolder<Day>(private val config: DayConfig<Day>) {
return parent.inflate(config.dayViewRes).apply {
dayView = this
layoutParams = DayLinearLayoutParams(layoutParams).apply {
weight = 1f // The parent's wightSum is set to 7.
if (config.daySize.parentDecidesWidth) {
width = 0
weight = 1f
}
when (config.daySize) {
DaySize.Square -> {
width = MATCH_PARENT
height = MATCH_PARENT
}

DaySize.Rectangle -> {
width = MATCH_PARENT
DaySize.Square,
DaySize.Rectangle,
-> {
height = MATCH_PARENT
}

DaySize.SeventhWidth -> {
width = MATCH_PARENT
}

DaySize.FreeForm -> {}
DaySize.SeventhWidth,
DaySize.FreeForm,
-> Unit
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ internal class WeekHolder<Day>(
return WidthDivisorLinearLayout(parent.context).apply {
weekContainer = this
val width = if (daySize.parentDecidesWidth) MATCH_PARENT else WRAP_CONTENT
val height = if (daySize.parentDecidesHeight) MATCH_PARENT else WRAP_CONTENT
val height = if (daySize.parentDecidesHeight) 0 else WRAP_CONTENT
val weight = if (daySize.parentDecidesHeight) 1f else 0f
layoutParams = LinearLayout.LayoutParams(width, height, weight)
orientation = LinearLayout.HORIZONTAL
weightSum = dayHolders.count().toFloat()
widthDivisorForHeight = if (daySize == DaySize.Square) dayHolders.count() else 0
for (holder in dayHolders) {
addView(holder.inflateDayView(this))
Expand Down

0 comments on commit 0e1b654

Please sign in to comment.