PersianDatePicker
Shamsi/Jalali date picker with material design (rewritten from Googls's material-components for android in Kotlin)
Install / Use
/learn @axdeveloper/PersianDatePickerREADME
PersianDatePicker 
Shamsi/Jalali date picker with material design (Google Material Components Date Picker)
<p> <img src="screenshots/date_picker_portrait.png" alt="Single Selection Demo Portrait" width="275"/>  <img src="screenshots/range_picker_portrait.png" alt="Range Selection Demo Portrait" width="275"/>  <img src="screenshots/range_picker_year_portrait.png" alt="Range Selection Year Demo Portrait" width="275"/> </p> <p> <img src="screenshots/date_picker_land.png" alt="Single Selection Demo Land" width="422" />  <img src="screenshots/range_picker_land.png" alt="Range Selection Demo Land" width="422" /> </p>This library is based on Googles Material Date Picker. I reimplemented everything in Kotlin.
How To Use
Minimum SDK: 21
Add this to your gradle file
implementation("io.github.axdeveloper.persiancalendar:datepicker:0.5.0")
Customization
The picker can be customized via the MaterialDatePicker.Builder and the CalendarConstraints.Builder. These classes allow you to
- Select the mode: single date or range of dates.
- Select the bounds: bounds can be restricted to any contiguous set of months. Defaults Farvardin, 1388. to Esfand, 1409.
- Select valid days: valid days can restrict selections to weekdays only. Defaults to all days as valid.
- Set a title.
- Set the month to which the picker opens (defaults to the current month if within the bounds otherwise the earliest month within the bounds).
- Set a default selection (defaults to no selection).
Examples
First you can define a CalendarConstraints to limit dates You can use PersianCalendar class to set a Persian/Shamsi date or a java.util.Calendar instance
val calendar = PersianCalendar()
calendar.setPersian(1340, Month.FARVARDIN, 1)
val start = calendar.timeInMillis
calendar.setPersian(1409, Month.ESFAND, 29)
val end = calendar.timeInMillis
val openAt = PersianCalendar.getToday().timeInMillis
val constraints = CalendarConstraints.Builder()
.setStart(start)
.setEnd(end)
.setOpenAt(openAt)
.setValidator(DateValidatorPointForward.from(start)).build()
Then we should create MaterialDatePicker
Single Date Picker
val datePicker = MaterialDatePicker.Builder
.datePicker()
.setTitleText("تاریخ را انتخاب کنید.")
.setCalendarConstraints(constraints).build()
Range Date Picker
val rangePicker = MaterialDatePicker.Builder
.dateRangePicker()
.setTitleText("محدوده را انتخاب کنید.")
.setCalendarConstraints(constraints).build()
And finaly call show()
datepicker.show(supportFragmentManager, "aTag")
rangePicker.show(supportFragmentManager, "aTag")
Listeners
There are 4 listeners:
- OnPositiveButtonClickListener
- OnNegetiveButtonClickListener
- OnCancelListener
- OnDismissListener
Styling and Attributes
Refer to Sample's styles.xml
Contributors
Rahman Mohammadi @axdeveloper
License
2020 Rahman Mohammadi (@axdeveloper). See the LICENSE file.
