From c10a955c452752684d76230822729a2b31336e08 Mon Sep 17 00:00:00 2001 From: BatLeDev Date: Sun, 9 Jun 2024 00:06:38 +0200 Subject: [PATCH] feat: pre-select the date for date pickers --- .../main/java/com/batledev/bluetask/CreateTaskActivity.kt | 4 ++-- app/src/main/java/com/batledev/bluetask/TaskUtils.kt | 6 ++++-- .../main/java/com/batledev/bluetask/UpdateTaskActivity.kt | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/batledev/bluetask/CreateTaskActivity.kt b/app/src/main/java/com/batledev/bluetask/CreateTaskActivity.kt index a2ca0e9..1520763 100644 --- a/app/src/main/java/com/batledev/bluetask/CreateTaskActivity.kt +++ b/app/src/main/java/com/batledev/bluetask/CreateTaskActivity.kt @@ -75,12 +75,12 @@ class CreateTaskActivity : AppCompatActivity() { } } buttonStartDatePicker.setOnClickListener { - TaskUtils.showStartDatePicker(this, buttonStartDatePicker, endDate) { date -> + TaskUtils.showStartDatePicker(this, buttonStartDatePicker, startDate, endDate) { date -> startDate = date } } buttonEndDatePicker.setOnClickListener { - TaskUtils.showEndDatePicker(this, buttonEndDatePicker, startDate) { date -> + TaskUtils.showEndDatePicker(this, buttonEndDatePicker, endDate, startDate) { date -> endDate = date } } diff --git a/app/src/main/java/com/batledev/bluetask/TaskUtils.kt b/app/src/main/java/com/batledev/bluetask/TaskUtils.kt index af6cd04..3fe4341 100644 --- a/app/src/main/java/com/batledev/bluetask/TaskUtils.kt +++ b/app/src/main/java/com/batledev/bluetask/TaskUtils.kt @@ -120,8 +120,9 @@ object TaskUtils { * @param endDate The end date of the task. * @param onDateSet The function to call when a date is selected. */ - fun showStartDatePicker(context: Context, button: Button, endDate: Date?, onDateSet: (Date) -> Unit) { + fun showStartDatePicker(context: Context, button: Button, initialDate: Date?, endDate: Date?, onDateSet: (Date) -> Unit) { val calendar = Calendar.getInstance() + initialDate?.let { calendar.time = it } val datePickerDialog = DatePickerDialog( context, { _, year, monthOfYear, dayOfMonth -> @@ -147,8 +148,9 @@ object TaskUtils { * @param startDate The start date of the task. * @param onDateSet The function to call when a date is selected. */ - fun showEndDatePicker(context: Context, button: Button, startDate: Date?, onDateSet: (Date) -> Unit) { + fun showEndDatePicker(context: Context, button: Button, initialDate: Date?, startDate: Date?, onDateSet: (Date) -> Unit) { val calendar = Calendar.getInstance() + initialDate?.let { calendar.time = it } val datePickerDialog = DatePickerDialog( context, { _, year, monthOfYear, dayOfMonth -> diff --git a/app/src/main/java/com/batledev/bluetask/UpdateTaskActivity.kt b/app/src/main/java/com/batledev/bluetask/UpdateTaskActivity.kt index 6a1cee3..8905e01 100644 --- a/app/src/main/java/com/batledev/bluetask/UpdateTaskActivity.kt +++ b/app/src/main/java/com/batledev/bluetask/UpdateTaskActivity.kt @@ -86,12 +86,12 @@ class UpdateTaskActivity : AppCompatActivity() { } } buttonStartDatePicker.setOnClickListener { - TaskUtils.showStartDatePicker(this, buttonStartDatePicker, endDate) { date -> + TaskUtils.showStartDatePicker(this, buttonStartDatePicker, startDate, endDate) { date -> startDate = date } } buttonEndDatePicker.setOnClickListener { - TaskUtils.showEndDatePicker(this, buttonEndDatePicker, startDate) { date -> + TaskUtils.showEndDatePicker(this, buttonEndDatePicker, endDate, startDate) { date -> endDate = date } }