Skip to content
This repository has been archived by the owner on Sep 3, 2023. It is now read-only.

Commit

Permalink
Integrate afollestad/date-picker, resolves #1820
Browse files Browse the repository at this point in the history
  • Loading branch information
afollestad committed Jun 25, 2019
1 parent 968fd57 commit 8b85e7d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.afollestad.materialdialogs.datetime

import android.R.attr
import androidx.annotation.CheckResult
import com.afollestad.date.dayOfMonth
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.WhichButton.POSITIVE
import com.afollestad.materialdialogs.actions.setActionButtonEnabled
Expand Down Expand Up @@ -68,12 +69,12 @@ fun MaterialDialog.dateTimePicker(
getDatePicker().apply {
minDateTime?.let { setMinDate(it) }
currentDateTime?.let { setDate(it) }
onDateChanged {
addOnDateChanged { previous, date ->
val futureTime = isFutureTime(getDatePicker(), getTimePicker())
setActionButtonEnabled(
POSITIVE, !requireFutureDateTime || futureTime
)
if (autoFlipToTime) {
if (autoFlipToTime && didDateChange(previous, date)) {
getPager().currentItem = 1
}
}
Expand Down Expand Up @@ -113,6 +114,14 @@ fun MaterialDialog.dateTimePicker(
return this
}

private fun didDateChange(
from: Calendar?,
to: Calendar
): Boolean {
if (from == null) return false
return from.dayOfMonth != to.dayOfMonth
}

/**
* Gets the currently selected date and time from a date/time picker dialog.
*/
Expand Down
5 changes: 4 additions & 1 deletion datetime/src/main/res/layout/md_datetime_picker_date.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<com.afollestad.date.DatePicker
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/datetimeDatePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
app:date_picker_calendar_horizontal_padding="8dp"
/>
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ ext.versions = [
// afollestad
assent : '2.3.0',
dotsIndicator : '1.0.0',
datePicker : '0.2.1'
datePicker : '0.4.1'
]

0 comments on commit 8b85e7d

Please sign in to comment.