GithubHelp home page GithubHelp logo

axdeveloper / persiandatepicker Goto Github PK

View Code? Open in Web Editor NEW
12.0 1.0 2.0 1.75 MB

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

License: Apache License 2.0

Kotlin 100.00%
picker shamsi googles-material persiandatepicker jalali kotlin android android-datepicker material-design date

persiandatepicker's Introduction

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.

persiandatepicker's People

Contributors

axdeveloper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

persiandatepicker's Issues

.aar File Request

Hey, how's it going?

I was wandering around and saw here that there is a new version, but since jcenter is down I couldn't download the aar file and I really need it, is there any way you could upload it?

Thanks in advance :)

PersianCalendar

when convert long date to PersianCalendar month of persion date isnot correct

gradle error

Could not find com.xdev.arch.persiancalendar.datepicker:datepicker:0.3.2.

Failed to resolve: com.xdev.arch.persiancalendar.datepicker:datepicker:0.3.2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.