From 9a98ed3b9ffa0727e87ba6ae12f85681cf714fa1 Mon Sep 17 00:00:00 2001 From: norhanadel Date: Fri, 27 Jun 2025 04:46:25 +0300 Subject: [PATCH 1/2] solve issue in datePicker --- .../presentation/components/TaskContent.kt | 114 ++++++++++++------ 1 file changed, 74 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/com/example/tudee/presentation/components/TaskContent.kt b/app/src/main/java/com/example/tudee/presentation/components/TaskContent.kt index 41f0fe4f..b4d722b1 100644 --- a/app/src/main/java/com/example/tudee/presentation/components/TaskContent.kt +++ b/app/src/main/java/com/example/tudee/presentation/components/TaskContent.kt @@ -2,10 +2,14 @@ package com.example.tudee.presentation.components import android.util.Log import androidx.compose.foundation.background +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.heightIn @@ -293,54 +297,84 @@ fun DatePickerDialogComponent( DatePickerDialog( onDismissRequest = onDismiss, colors = DatePickerDefaults.colors( - containerColor = TudeeTheme.color.surface - , titleContentColor = TudeeTheme.color.textColors.title + containerColor = TudeeTheme.color.surface, + titleContentColor = TudeeTheme.color.textColors.title ), - confirmButton = { - Button(onClick = { - val selectedDateMillis = datePickerState.selectedDateMillis - if (selectedDateMillis != null) { - val instant = Instant.fromEpochMilliseconds(selectedDateMillis) - val localDateTime = instant.toLocalDateTime(TimeZone.currentSystemDefault()) - val localDate = LocalDate( - year = localDateTime.year, - monthNumber = localDateTime.monthNumber, - dayOfMonth = localDateTime.dayOfMonth - ) - onDateSelected(localDate) - } - }) { - Text("OK") - } - }, - dismissButton = { - Button(onClick = onDismiss) { - Text("Cancel") - } - } + confirmButton = {}, + dismissButton = {} ) { - DatePicker(state = datePickerState -, headline = { + Column( + modifier = Modifier + .fillMaxSize() + .padding(bottom = 20.dp) + ) { + DatePicker( + state = datePickerState, + headline = {}, + colors = DatePickerDefaults.colors( + navigationContentColor = TudeeTheme.color.textColors.title, + headlineContentColor = TudeeTheme.color.textColors.title, + titleContentColor = TudeeTheme.color.textColors.title, + weekdayContentColor = TudeeTheme.color.textColors.title, + dayContentColor = TudeeTheme.color.textColors.title, + containerColor = TudeeTheme.color.statusColors.greenAccent, + selectedDayContainerColor = TudeeTheme.color.primary, + selectedDayContentColor = TudeeTheme.color.textColors.onPrimary, + todayContentColor = TudeeTheme.color.primary, + todayDateBorderColor = TudeeTheme.color.primary + ) + ) - }, - colors = DatePickerDefaults.colors( - navigationContentColor =TudeeTheme.color.textColors.title , - headlineContentColor = TudeeTheme.color.textColors.title, - titleContentColor = TudeeTheme.color.textColors.title, - weekdayContentColor = TudeeTheme.color.textColors.title, - dayContentColor=TudeeTheme.color.textColors.title, - containerColor = TudeeTheme.color.statusColors.greenAccent , - selectedDayContainerColor = TudeeTheme.color.primary, - selectedDayContentColor = TudeeTheme.color.textColors.onPrimary, - todayContentColor = TudeeTheme.color.primary, - todayDateBorderColor = TudeeTheme.color.primary, + Spacer(modifier = Modifier.weight(1f)) + Row( + modifier = Modifier + .fillMaxWidth() + .padding(start = 12.dp, end = 40.dp, bottom = 10.dp), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { + Text( + modifier = Modifier.clickable { + datePickerState.selectedDateMillis = null + }, + text = stringResource(R.string.date_picker_clear_button_text), + color = TudeeTheme.color.primary, + style = TudeeTheme.textStyle.label.large ) - ) + + Row(horizontalArrangement = Arrangement.spacedBy(35.dp)) { + Text( + modifier = Modifier.clickable { onDismiss() }, + text = stringResource(R.string.date_picker_cancel_button_text), + color = TudeeTheme.color.primary, + style = TudeeTheme.textStyle.label.large + ) + + Text( + modifier = Modifier.clickable { + val selectedDateMillis = datePickerState.selectedDateMillis + if (selectedDateMillis != null) { + val instant = Instant.fromEpochMilliseconds(selectedDateMillis) + val localDateTime = instant.toLocalDateTime(TimeZone.currentSystemDefault()) + val localDate = LocalDate( + year = localDateTime.year, + monthNumber = localDateTime.monthNumber, + dayOfMonth = localDateTime.dayOfMonth + ) + onDateSelected(localDate) + } + }, + text = stringResource(R.string.date_picker_ok_button_text), + color = TudeeTheme.color.primary, + style = TudeeTheme.textStyle.label.large + ) + } + } + } } } - @Preview(showBackground = true) @Composable fun TaskContentPreview() { From adbfab39060ca0d5a940d182150ba9445c0fecbd Mon Sep 17 00:00:00 2001 From: norhanadel Date: Fri, 27 Jun 2025 05:14:13 +0300 Subject: [PATCH 2/2] solve issue in ModalBottomSheet --- .../presentation/screen/home/screen/HomeScreen.kt | 11 +++++++---- .../screen/task_screen/component/TaskButtonSheet.kt | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/example/tudee/presentation/screen/home/screen/HomeScreen.kt b/app/src/main/java/com/example/tudee/presentation/screen/home/screen/HomeScreen.kt index 0ed84af0..bc177c3f 100644 --- a/app/src/main/java/com/example/tudee/presentation/screen/home/screen/HomeScreen.kt +++ b/app/src/main/java/com/example/tudee/presentation/screen/home/screen/HomeScreen.kt @@ -5,6 +5,7 @@ import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height @@ -254,13 +255,15 @@ fun BottomSheetContent( onDismiss: () -> Unit, actions: (HomeActions) -> Unit ) { - val sheetState = rememberModalBottomSheetState() - + val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true) ModalBottomSheet( + modifier = Modifier.fillMaxHeight(fraction = 0.8f), onDismissRequest = onDismiss, sheetState = sheetState, - containerColor = TudeeTheme.color.surface - ) { + containerColor = TudeeTheme.color.surface, + shape = RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp), + + ) { TaskContent( state = state, categories = state.categories, diff --git a/app/src/main/java/com/example/tudee/presentation/screen/task_screen/component/TaskButtonSheet.kt b/app/src/main/java/com/example/tudee/presentation/screen/task_screen/component/TaskButtonSheet.kt index 2b0e806c..d6ab1ce0 100644 --- a/app/src/main/java/com/example/tudee/presentation/screen/task_screen/component/TaskButtonSheet.kt +++ b/app/src/main/java/com/example/tudee/presentation/screen/task_screen/component/TaskButtonSheet.kt @@ -208,7 +208,8 @@ fun BottomSheetContent( } item { TudeeTextField( - value = taskState.taskDueDate?.toString() ?: "2024, 1, 1", + value = taskState.taskDueDate?.toString() ?: java.time.LocalDate.now() + .format(java.time.format.DateTimeFormatter.ofPattern("dd-MM-yyyy")), onValueChange = { newValue -> val parts = newValue.split(", ") if (parts.size == 3) {