RxJava 短信验证码倒计时器, 支持暂停和恢复

2,500 阅读1分钟
原文链接: github.com

This is a simple rxjava2 timer. 

I copy this class into all the little apps I make. I'm tired of doing it. Now it's a library.

Usage

timer = Rx2Timer.builder()
                .initialDelay(0) //default is 0
                .period(1) //default is 1
                .take(30) //default is 60
                .unit(TimeUnit.SECONDS) // default is TimeUnit.SECONDS
                .onCount(count -> {
                    if (count < 10) {
                        binding.text.setText("0" + count + " s");
                    } else {
                        binding.text.setText(count + " s");
                    }
                })
                .onError(e -> binding.text.setText(R.string.count))
                .onComplete(() -> binding.text.setText(R.string.count))
                .build();

timer.start();
timer.stop();
timer.restart();
timer.pause();
timer.resume();
                

Gradle

compile 'com.github.thepacific:rx2timer:0.0.1'

License

The MIT License