Skip to content

Shamsi/Jalali date picker with material design (rewritten from Googls's material-components for android in Kotlin)

License

Notifications You must be signed in to change notification settings

axdeveloper/PersianDatePicker

Repository files navigation

PersianDatePicker Download

Shamsi/Jalali date picker with material design (Google Material Components Date Picker)

Single Selection Demo PortraitRange Selection Demo PortraitRange Selection Year Demo Portrait

Single Selection Demo LandRange Selection Demo Land

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 'com.xdev.arch.persiancalendar.datepicker:datepicker:0.3.2'

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.

About

Shamsi/Jalali date picker with material design (rewritten from Googls's material-components for android in Kotlin)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages