From 05ef14c9bcf9f245805cba02964780f737fe85ee Mon Sep 17 00:00:00 2001 From: Shiva Thapa Date: Mon, 28 Oct 2024 20:27:36 +0545 Subject: [PATCH] Change title according to the date picker display mode --- .../nepalidatepickerkmp/NepaliDatePicker.kt | 6 ++- .../NepaliDatePickerWithEnglishDate.kt | 6 ++- .../NepaliDateRangePicker.kt | 3 +- .../NepaliDateRangePickerWithEnglishDate.kt | 3 +- .../NepaliDatePickerDefaults.kt | 45 +++++++++++++------ .../data/NepaliDateLocale.kt | 9 ++++ 6 files changed, 53 insertions(+), 19 deletions(-) diff --git a/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/NepaliDatePicker.kt b/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/NepaliDatePicker.kt index faecbb0..b16233e 100644 --- a/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/NepaliDatePicker.kt +++ b/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/NepaliDatePicker.kt @@ -150,14 +150,16 @@ fun NepaliDatePicker( title: (@Composable () -> Unit)? = { NepaliDatePickerDefaults.NepaliDatePickerTitle( modifier = Modifier.padding(NepaliDatePickerTitlePadding), - language = state.locale.language + language = state.locale.language, + displayMode = state.displayMode ) }, headline: (@Composable () -> Unit)? = { NepaliDatePickerDefaults.NepaliDatePickerHeadline( selectedDate = state.selectedDate, modifier = Modifier.padding(NepaliDatePickerHeadlinePadding), - locale = state.locale + locale = state.locale, + displayMode = state.displayMode ) }, showModeToggle: Boolean = true, diff --git a/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/NepaliDatePickerWithEnglishDate.kt b/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/NepaliDatePickerWithEnglishDate.kt index 4410231..6e66bcc 100644 --- a/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/NepaliDatePickerWithEnglishDate.kt +++ b/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/NepaliDatePickerWithEnglishDate.kt @@ -122,7 +122,8 @@ fun NepaliDatePickerWithEnglishDate( title: (@Composable () -> Unit)? = { NepaliDatePickerDefaults.NepaliDatePickerTitle( modifier = Modifier.padding(NepaliDatePickerTitlePadding), - language = state.locale.language + language = state.locale.language, + displayMode = state.displayMode ) }, headline: (@Composable () -> Unit)? = { @@ -131,7 +132,8 @@ fun NepaliDatePickerWithEnglishDate( selectedDate = state.selectedDate, selectedEnglishDate = state.selectedEnglishDate, locale = state.locale, - englishLocale = englishDateLocale + englishLocale = englishDateLocale, + displayMode = state.displayMode ) }, showModeToggle: Boolean = true, diff --git a/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/NepaliDateRangePicker.kt b/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/NepaliDateRangePicker.kt index 3aca747..b83baf9 100644 --- a/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/NepaliDateRangePicker.kt +++ b/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/NepaliDateRangePicker.kt @@ -120,7 +120,8 @@ fun NepaliDateRangePicker( title: (@Composable () -> Unit)? = { NepaliDatePickerDefaults.NepaliDateRangePickerTitle( modifier = Modifier.padding(NepaliDateRangePickerTitlePadding), - language = state.locale.language + language = state.locale.language, + displayMode = state.displayMode ) }, headline: (@Composable () -> Unit)? = { diff --git a/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/NepaliDateRangePickerWithEnglishDate.kt b/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/NepaliDateRangePickerWithEnglishDate.kt index fadce6e..420cd5a 100644 --- a/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/NepaliDateRangePickerWithEnglishDate.kt +++ b/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/NepaliDateRangePickerWithEnglishDate.kt @@ -105,7 +105,8 @@ fun NepaliDateRangePickerWithEnglishDate( title: (@Composable () -> Unit)? = { NepaliDatePickerDefaults.NepaliDateRangePickerTitle( modifier = Modifier.padding(NepaliDateRangePickerTitlePadding), - language = state.locale.language + language = state.locale.language, + displayMode = state.displayMode ) }, headline: (@Composable () -> Unit)? = { diff --git a/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/calendar_model/NepaliDatePickerDefaults.kt b/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/calendar_model/NepaliDatePickerDefaults.kt index f591a64..b297011 100644 --- a/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/calendar_model/NepaliDatePickerDefaults.kt +++ b/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/calendar_model/NepaliDatePickerDefaults.kt @@ -43,6 +43,7 @@ import androidx.compose.ui.graphics.takeOrElse import androidx.compose.ui.text.TextStyle import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp +import dev.shivathapaa.nepalidatepickerkmp.DisplayMode import dev.shivathapaa.nepalidatepickerkmp.NepaliSelectableDates import dev.shivathapaa.nepalidatepickerkmp.annotations.ExperimentalNepaliDatePickerApi import dev.shivathapaa.nepalidatepickerkmp.data.CustomCalendar @@ -186,27 +187,36 @@ object NepaliDatePickerDefaults { @Composable internal fun NepaliDatePickerTitle( - modifier: Modifier = Modifier, language: NepaliDatePickerLang + modifier: Modifier = Modifier, language: NepaliDatePickerLang, displayMode: DisplayMode ) { - Text( - text = language.datePickerTitle, - modifier = modifier - ) + when (displayMode) { + DisplayMode.Picker -> + Text(text = language.datePickerTitle, modifier = modifier) + + DisplayMode.Input -> + Text(text = language.dateInputTitle, modifier = modifier) + } } @Composable internal fun NepaliDateRangePickerTitle( - modifier: Modifier = Modifier, language: NepaliDatePickerLang + modifier: Modifier = Modifier, language: NepaliDatePickerLang, displayMode: DisplayMode ) { - Text( - text = language.dateRangePickerTitle, - modifier = modifier - ) + when (displayMode) { + DisplayMode.Picker -> + Text(text = language.dateRangePickerTitle, modifier = modifier) + + DisplayMode.Input -> + Text(text = language.dateRangeInputTitle, modifier = modifier) + } } @Composable internal fun NepaliDatePickerHeadline( - selectedDate: CustomCalendar?, modifier: Modifier = Modifier, locale: NepaliDateLocale + selectedDate: CustomCalendar?, + locale: NepaliDateLocale, + displayMode: DisplayMode, + modifier: Modifier = Modifier ) { val calendarModel = NepaliCalendarModel(locale) @@ -218,7 +228,11 @@ object NepaliDatePickerDefaults { dayOfWeek = date.dayOfWeek, locale = locale ) - } ?: locale.language.selectDateText + } ?: if (displayMode == DisplayMode.Input) { + locale.language.writeDateText + } else { + locale.language.selectDateText + } Text( text = formattedDate, @@ -234,6 +248,7 @@ object NepaliDatePickerDefaults { selectedEnglishDate: CustomCalendar?, locale: NepaliDateLocale, englishLocale: NepaliDateLocale, + displayMode: DisplayMode, modifier: Modifier = Modifier ) { val calendarModel = NepaliCalendarModel(locale) @@ -246,7 +261,11 @@ object NepaliDatePickerDefaults { dayOfWeek = date.dayOfWeek, locale = locale ) - } ?: locale.language.selectDateText + } ?: if (displayMode == DisplayMode.Input) { + locale.language.writeDateText + } else { + locale.language.selectDateText + } val formattedEnglishDate = selectedEnglishDate?.let { date -> diff --git a/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/data/NepaliDateLocale.kt b/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/data/NepaliDateLocale.kt index 1882b60..2517312 100644 --- a/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/data/NepaliDateLocale.kt +++ b/nepali-date-picker/src/commonMain/kotlin/dev/shivathapaa/nepalidatepickerkmp/data/NepaliDateLocale.kt @@ -91,8 +91,11 @@ enum class NepaliDatePickerLang { override val months: List = nepaliMonthsInEnglish override val englishMonths: List = englishMonthsInEnglish override val selectDateText: String = "Select Date" + override val writeDateText: String = "Write Date" override val datePickerTitle: String = "Select Nepali Date" + override val dateInputTitle: String = "Write Nepali Date" override val dateRangePickerTitle: String = "Select Nepali Dates" + override val dateRangeInputTitle: String = "Write Nepali Dates" override val cancelText: String = "Cancel" override val okText: String = "OK" override val today: String = "TODAY" @@ -115,8 +118,11 @@ enum class NepaliDatePickerLang { override val months: List = nepaliMonths override val englishMonths: List = englishMonthsInNepali override val selectDateText: String = "मिति चयन गर्नुहोस्" + override val writeDateText: String = "मिति लेख्नुहोस्" override val datePickerTitle: String = "नेपाली मिति चयन गर्नुहोस्" + override val dateInputTitle: String = "नेपाली मिति लेख्नुहोस्" override val dateRangePickerTitle: String = "नेपाली मितिहरु चयन गर्नुहोस्" + override val dateRangeInputTitle: String = "नेपाली मितिहरु लेख्नुहोस्" override val cancelText: String = "रद्द गर्नुहोस्" override val okText: String = "भयो" override val today: String = "आज" @@ -139,8 +145,11 @@ enum class NepaliDatePickerLang { abstract val months: List abstract val englishMonths: List abstract val selectDateText: String + abstract val writeDateText: String abstract val datePickerTitle: String + abstract val dateInputTitle: String abstract val dateRangePickerTitle: String + abstract val dateRangeInputTitle: String abstract val cancelText: String abstract val okText: String abstract val today: String