Rxjava 优雅的实现短信验证码发送
生活随笔
收集整理的這篇文章主要介紹了
Rxjava 优雅的实现短信验证码发送
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
廢話不多說直接上代碼
private fun countDown() {btn_send_code_activity_login.isEnabled = falsedisPose = Flowable.intervalRange(0,120,0,1,TimeUnit.SECONDS).observeOn(AndroidSchedulers.mainThread()).doOnNext {btn_send_code_activity_login.text = String.format(getString(R.string.label_code_time), 120 - it)}.doOnComplete {btn_send_code_activity_login.isEnabled = truebtn_send_code_activity_login.text = getString(R.string.label_get_code)}.`as`(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(this))).subscribe()}這里利用intervalRange參數意思如下
/*** Signals a range of long values, the first after some initial delay and the rest periodically after.* <p>* The sequence completes immediately after the last value (start + count - 1) has been reached.* <dl>* <dt><b>Backpressure:</b></dt>* <dd>The operator signals a {@code MissingBackpressureException} if the downstream can't keep up.</dd>* <dt><b>Scheduler:</b></dt>* <dd>{@code intervalRange} by default operates on the {@link Schedulers#computation() computation} {@link Scheduler}.</dd>* </dl>* @param start that start value of the range* @param count the number of values to emit in total, if zero, the operator emits an onComplete after the initial delay.* @param initialDelay the initial delay before signaling the first value (the start)* @param period the period between subsequent values* @param unit the unit of measure of the initialDelay and period amounts* @return the new Flowable instance*/@CheckReturnValue@BackpressureSupport(BackpressureKind.ERROR)@SchedulerSupport(SchedulerSupport.COMPUTATION)public static Flowable<Long> intervalRange(long start, long count, long initialDelay, long period, TimeUnit unit) { return intervalRange(start, count, initialDelay, period, unit, Schedulers.computation());}總結
以上是生活随笔為你收集整理的Rxjava 优雅的实现短信验证码发送的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Flutter快速入门 五步搞定Flut
- 下一篇: Deepin15.7 Android8.