@@ -142,22 +142,18 @@ class Example4Fragment : BaseFragment(R.layout.example_4_fragment), HasToolbar,
142
142
}
143
143
144
144
private fun configureBinders () {
145
- val clipLevelHalf = 5000
146
- val ctx = requireContext()
147
- val rangeStartBackground =
148
- ctx.getDrawableCompat(R .drawable.example_4_continuous_selected_bg_start).also {
145
+ class DayViewContainer (view : View ) : ViewContainer(view) {
146
+ val clipLevelHalf = 5000
147
+ val rangeStartBackground = view.context.getDrawableCompat(R .drawable.example_4_continuous_selected_bg_start).also {
149
148
it.level = clipLevelHalf // Used by ClipDrawable
150
149
}
151
- val rangeEndBackground =
152
- ctx.getDrawableCompat(R .drawable.example_4_continuous_selected_bg_end).also {
150
+ val rangeEndBackground = view.context.getDrawableCompat(R .drawable.example_4_continuous_selected_bg_end).also {
153
151
it.level = clipLevelHalf // Used by ClipDrawable
154
152
}
155
- val rangeMiddleBackground =
156
- ctx.getDrawableCompat(R .drawable.example_4_continuous_selected_bg_middle)
157
- val singleBackground = ctx.getDrawableCompat(R .drawable.example_4_single_selected_bg)
158
- val todayBackground = ctx.getDrawableCompat(R .drawable.example_4_today_bg)
153
+ val rangeMiddleBackground = view.context.getDrawableCompat(R .drawable.example_4_continuous_selected_bg_middle)
154
+ val singleBackground = view.context.getDrawableCompat(R .drawable.example_4_single_selected_bg)
155
+ val todayBackground = view.context.getDrawableCompat(R .drawable.example_4_today_bg)
159
156
160
- class DayViewContainer (view : View ) : ViewContainer(view) {
161
157
lateinit var day: CalendarDay // Will be set when this container is bound.
162
158
val binding = Example4CalendarDayBinding .bind(view)
163
159
@@ -200,26 +196,31 @@ class Example4Fragment : BaseFragment(R.layout.example_4_fragment), HasToolbar,
200
196
when {
201
197
startDate == data.date && endDate == null -> {
202
198
textView.setTextColorRes(R .color.white)
203
- roundBgView.applyBackground(singleBackground)
199
+ roundBgView.applyBackground(container. singleBackground)
204
200
}
201
+
205
202
data.date == startDate -> {
206
203
textView.setTextColorRes(R .color.white)
207
- continuousBgView.applyBackground(rangeStartBackground)
208
- roundBgView.applyBackground(singleBackground)
204
+ continuousBgView.applyBackground(container. rangeStartBackground)
205
+ roundBgView.applyBackground(container. singleBackground)
209
206
}
207
+
210
208
startDate != null && endDate != null && (data.date > startDate && data.date < endDate) -> {
211
209
textView.setTextColorRes(R .color.example_4_grey)
212
- continuousBgView.applyBackground(rangeMiddleBackground)
210
+ continuousBgView.applyBackground(container. rangeMiddleBackground)
213
211
}
212
+
214
213
data.date == endDate -> {
215
214
textView.setTextColorRes(R .color.white)
216
- continuousBgView.applyBackground(rangeEndBackground)
217
- roundBgView.applyBackground(singleBackground)
215
+ continuousBgView.applyBackground(container. rangeEndBackground)
216
+ roundBgView.applyBackground(container. singleBackground)
218
217
}
218
+
219
219
data.date == today -> {
220
220
textView.setTextColorRes(R .color.example_4_grey)
221
- roundBgView.applyBackground(todayBackground)
221
+ roundBgView.applyBackground(container. todayBackground)
222
222
}
223
+
223
224
else -> textView.setTextColorRes(R .color.example_4_grey)
224
225
}
225
226
}
@@ -231,14 +232,15 @@ class Example4Fragment : BaseFragment(R.layout.example_4_fragment), HasToolbar,
231
232
endDate != null &&
232
233
isInDateBetweenSelection(data.date, startDate, endDate)
233
234
) {
234
- continuousBgView.applyBackground(rangeMiddleBackground)
235
+ continuousBgView.applyBackground(container. rangeMiddleBackground)
235
236
}
237
+
236
238
DayPosition .OutDate ->
237
239
if (startDate != null &&
238
240
endDate != null &&
239
241
isOutDateBetweenSelection(data.date, startDate, endDate)
240
242
) {
241
- continuousBgView.applyBackground(rangeMiddleBackground)
243
+ continuousBgView.applyBackground(container. rangeMiddleBackground)
242
244
}
243
245
}
244
246
}
0 commit comments