@@ -98,19 +98,19 @@ private fun DatePickerBottomSheetContent(
9898 val lastDaysOfPrevMonth = remember(currentYear, currentMonth) {
9999 CalendarUtils .lastDaysOfPrevMonth(currentYear, currentMonth)
100100 }
101- val firstDaysOfNextMonth = remember(currentYear, currentMonth) {
102- CalendarUtils .firstDaysOfNextMonth(currentYear, currentMonth)
103- }
104101 val currentDaysOfMonth = remember(currentYear, currentMonth) {
105102 CalendarUtils .getDayAmountOfMonth(currentYear, currentMonth)
106103 }
107104
108- val prevMonthButtonEnabled by remember(availableStartDate) {
105+ val totalCells = 42
106+ val firstDaysOfNextMonthCount = totalCells - lastDaysOfPrevMonth.size - currentDaysOfMonth
107+
108+ val prevMonthButtonEnabled by remember(availableStartDate, currentYear, currentMonth) {
109109 derivedStateOf {
110110 (availableStartDate == null ) || (availableStartDate.year < currentYear) || (availableStartDate.month < currentMonth)
111111 }
112112 }
113- val nextMonthButtonEnabled by remember(availableEndDate) {
113+ val nextMonthButtonEnabled by remember(availableEndDate, currentYear, currentMonth ) {
114114 derivedStateOf {
115115 (availableEndDate == null ) || (availableEndDate.year > currentYear) || (availableEndDate.month > currentMonth)
116116 }
@@ -186,13 +186,31 @@ private fun DatePickerBottomSheetContent(
186186 }
187187
188188 itemsIndexed(lastDaysOfPrevMonth) { _, day ->
189+ val prevMonth = if (currentMonth == 1 ) 12 else currentMonth - 1
190+ val prevYear = if (currentMonth == 1 ) currentYear - 1 else currentYear
191+ val prevDate = Date (prevYear, prevMonth, day)
192+ val available = prevDate.checkInRange(availableStartDate, availableEndDate)
193+
189194 Box (
190- modifier = Modifier .aspectRatio(1f ),
195+ modifier = Modifier
196+ .aspectRatio(1f )
197+ .clickableWithoutRipple {
198+ if (! available) return @clickableWithoutRipple
199+ if (currentMonth == 1 ) {
200+ currentMonth = 12
201+ currentYear - = 1
202+ } else {
203+ currentMonth - = 1
204+ }
205+ selectedDate = prevDate
206+ },
191207 contentAlignment = Alignment .Center ,
192208 ) {
193209 Text (
194210 " $day " ,
195- style = BitnagilTheme .typography.subtitle1Regular.copy(color = BitnagilTheme .colors.coolGray80),
211+ style = BitnagilTheme .typography.subtitle1Regular.copy(
212+ color = if (available) BitnagilTheme .colors.coolGray80 else BitnagilTheme .colors.coolGray95,
213+ ),
196214 )
197215 }
198216 }
@@ -202,13 +220,16 @@ private fun DatePickerBottomSheetContent(
202220 val currentDate = Date (year = currentYear, month = currentMonth, day = index + 1 )
203221 val available = currentDate.checkInRange(startDate = availableStartDate, endDate = availableEndDate)
204222 Box (
205- modifier = Modifier .aspectRatio(1f ).background(
206- color = if (selected) { BitnagilTheme .colors.orange50 } else { Color .Transparent },
207- shape = if (selected) { RoundedCornerShape (12 .dp) } else { RectangleShape },
208- ).clickableWithoutRipple {
209- if (! available) return @clickableWithoutRipple
210- selectedDate = currentDate
211- },
223+ modifier = Modifier
224+ .aspectRatio(1f )
225+ .background(
226+ color = if (selected) BitnagilTheme .colors.orange50 else Color .Transparent ,
227+ shape = if (selected) RoundedCornerShape (12 .dp) else RectangleShape ,
228+ )
229+ .clickableWithoutRipple {
230+ if (! available) return @clickableWithoutRipple
231+ selectedDate = currentDate
232+ },
212233 contentAlignment = Alignment .Center ,
213234 ) {
214235 Text (
@@ -224,14 +245,33 @@ private fun DatePickerBottomSheetContent(
224245 }
225246 }
226247
227- itemsIndexed(firstDaysOfNextMonth) { _, day ->
248+ items(firstDaysOfNextMonthCount) { index ->
249+ val day = index + 1
250+ val nextMonth = if (currentMonth == 12 ) 1 else currentMonth + 1
251+ val nextYear = if (currentMonth == 12 ) currentYear + 1 else currentYear
252+ val nextDate = Date (nextYear, nextMonth, day)
253+ val available = nextDate.checkInRange(availableStartDate, availableEndDate)
254+
228255 Box (
229- modifier = Modifier .aspectRatio(1f ),
256+ modifier = Modifier
257+ .aspectRatio(1f )
258+ .clickableWithoutRipple {
259+ if (! available) return @clickableWithoutRipple
260+ if (currentMonth == 12 ) {
261+ currentMonth = 1
262+ currentYear + = 1
263+ } else {
264+ currentMonth + = 1
265+ }
266+ selectedDate = nextDate
267+ },
230268 contentAlignment = Alignment .Center ,
231269 ) {
232270 Text (
233271 " $day " ,
234- style = BitnagilTheme .typography.subtitle1Regular.copy(color = BitnagilTheme .colors.coolGray80),
272+ style = BitnagilTheme .typography.subtitle1Regular.copy(
273+ color = if (available) BitnagilTheme .colors.coolGray80 else BitnagilTheme .colors.coolGray95,
274+ ),
235275 )
236276 }
237277 }
0 commit comments