Skip to content

Commit

Permalink
feat: pre-select the date for date pickers
Browse files Browse the repository at this point in the history
  • Loading branch information
BatLeDev committed Jun 8, 2024
1 parent 08aef13 commit c10a955
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/batledev/bluetask/CreateTaskActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/batledev/bluetask/TaskUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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 ->
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/batledev/bluetask/UpdateTaskActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit c10a955

Please sign in to comment.