项目作者: thesalah

项目描述 :
RxJava extension for Android to pick date and time
高级语言: Java
项目地址: git://github.com/thesalah/RxDateTimePicker.git
创建时间: 2018-01-15T19:58:20Z
项目社区:https://github.com/thesalah/RxDateTimePicker

开源协议:

下载


Download

RxDateTimePicker

An easy way to pick date and time on Android using RxJava2

Setup

To use this library your minSdkVersion must be >= 16.

In your build.gradle :

  1. dependencies {
  2. implementation 'com.salah.rxdatetimepicker:rxdatetimepicker:1.0.1'
  3. }

Usage

Kotlin :

  1. RxDateTimePicker
  2. .with(this)
  3. .show()
  4. .subscribe { date -> Log.d("Date",date.toString()) }

Java :

  1. RxDateTimePicker
  2. .with(this)
  3. .show()
  4. .subscribe(new Consumer<Date>() {
  5. @Override
  6. public void accept(@NonNull Date date) throws Exception {
  7. Log.d("Date",date.toString());
  8. }
  9. });

By default both date and time picker dialog will show. You can specify date only or time only picker as shown below

  1. RxDateTimePicker
  2. .with(this)
  3. .pickTimeOnly() // or .pickDateOnly()
  4. .show()
  5. .subscribe { date -> Log.d("Date",date.toString()) }

Converters

Be default Java Date object are being emitted. You can convert this to String in required format.

Kotlin :

  1. RxDateTimePicker
  2. .with(this)
  3. .pickDateOnly()
  4. .show()
  5. .flatMap { date -> RxDateConverters.toString(date,"dd-MM-yyyy") }
  6. .subscribe { date -> Log.d("Date",date) }

Java :

  1. RxDateTimePicker
  2. .with(this)
  3. .pickTimeOnly()
  4. .is24HourView(false)
  5. .show()
  6. .flatMap(new Function<Date, MaybeSource<String>>() {
  7. @Override
  8. public MaybeSource<String> apply(@NonNull Date date) throws Exception {
  9. return RxDateConverters.toString(date,"mm-hh");
  10. }
  11. })
  12. .subscribe(new Consumer<String>() {
  13. @Override
  14. public void accept(@NonNull String date) throws Exception {
  15. Log.d("Date",date);
  16. }
  17. });

Converting to Calender object

  1. RxDateTimePicker
  2. .with(this)
  3. .show()
  4. .flatMap { date -> RxDateConverters.toCalender(date) }
  5. .subscribe { calender -> Log.d("Date",calender.getDisplayName(Calendar.MONTH, LONG,Locale.US)) }

License

  1. Copyright (C) 2018 Salah
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.