From b1143656ce63f4794e5f6a48d734d5adc0d5ee1f Mon Sep 17 00:00:00 2001 From: Gerrit Vermeulen Date: Wed, 21 Dec 2022 14:51:54 +0200 Subject: [PATCH] Make Month view type configurable on OneScreenMonthYear --- .../CalendarMonthViewOneColumn.kt | 16 ++++++++++++++-- .../com/dt/composedatepicker/ComposeCalendar.kt | 6 ++++-- .../dt/composedatepicker/OneScreenMonthYear.kt | 2 ++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/library/src/main/java/com/dt/composedatepicker/CalendarMonthViewOneColumn.kt b/library/src/main/java/com/dt/composedatepicker/CalendarMonthViewOneColumn.kt index abf23bb..efdafc3 100644 --- a/library/src/main/java/com/dt/composedatepicker/CalendarMonthViewOneColumn.kt +++ b/library/src/main/java/com/dt/composedatepicker/CalendarMonthViewOneColumn.kt @@ -35,6 +35,7 @@ fun CalendarMonthViewOneColumn( .fillMaxHeight(0.85f) .fillMaxWidth() .padding(10.dp), + monthViewType: MonthViewType?, ) { LazyColumn( @@ -55,7 +56,8 @@ fun CalendarMonthViewOneColumn( setShowMonths = setShowMonths, showOnlyMonth = showOnlyMonth, themeColor = themeColor, - unselectedColor = unselectedColor + unselectedColor = unselectedColor, + monthViewType = monthViewType ) } } @@ -76,6 +78,7 @@ fun MonthItemOneColumn( showOnlyMonth: Boolean, themeColor: Color, unselectedColor: Color, + monthViewType: MonthViewType?, ) { val enabled = checkDate( minYear = minYear, @@ -88,6 +91,15 @@ fun MonthItemOneColumn( val monthAsNumber = String.format("%02d", index.plus(1)) + val monthText: String = when (monthViewType) { + MonthViewType.ONLY_MONTH -> month.name.uppercase() + MonthViewType.ONLY_NUMBER -> monthAsNumber + MonthViewType.BOTH_NUMBER_AND_MONTH -> month.name.uppercase() + " " + "(${ + monthAsNumber + })" + else -> month.name.uppercase() + } + Box(modifier = Modifier .padding(vertical = 6.dp) .clickable( @@ -101,7 +113,7 @@ fun MonthItemOneColumn( } }) { Text( - text = monthAsNumber, + text = monthText, fontSize = if (month.name == selectedMonth) 35.sp else 30.sp, color = if (enabled && month.name == selectedMonth) themeColor else if (enabled) unselectedColor diff --git a/library/src/main/java/com/dt/composedatepicker/ComposeCalendar.kt b/library/src/main/java/com/dt/composedatepicker/ComposeCalendar.kt index 77cb370..801216c 100644 --- a/library/src/main/java/com/dt/composedatepicker/ComposeCalendar.kt +++ b/library/src/main/java/com/dt/composedatepicker/ComposeCalendar.kt @@ -143,7 +143,8 @@ fun ComposeCalendar( showOnlyMonth = calendarType == CalendarType.ONLY_MONTH, themeColor = themeColor, unselectedColor = unselectedColor, - setYear = setYear + setYear = setYear, + monthViewType = monthViewType ) } else { Crossfade(targetState = showMonths) { @@ -162,7 +163,8 @@ fun ComposeCalendar( monthList = monthList, showOnlyMonth = calendarType == CalendarType.ONLY_MONTH, themeColor = themeColor, - unselectedColor = unselectedColor + unselectedColor = unselectedColor, + monthViewType = monthViewType ) } else { CalendarMonthView( diff --git a/library/src/main/java/com/dt/composedatepicker/OneScreenMonthYear.kt b/library/src/main/java/com/dt/composedatepicker/OneScreenMonthYear.kt index 6c1b381..120811c 100644 --- a/library/src/main/java/com/dt/composedatepicker/OneScreenMonthYear.kt +++ b/library/src/main/java/com/dt/composedatepicker/OneScreenMonthYear.kt @@ -24,6 +24,7 @@ fun OneScreenMonthYear( themeColor: Color, unselectedColor: Color, setYear: (Int) -> Unit, + monthViewType: MonthViewType?, ) { Row() { CalendarMonthViewOneColumn( @@ -43,6 +44,7 @@ fun OneScreenMonthYear( .fillMaxHeight(0.85f) .fillMaxWidth(0.5f) .padding(vertical = 10.dp), + monthViewType = monthViewType, ) CalendarYearView( selectedYear = selectedYear,