Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void startDurationUpdate() {
- if (subscription != null && !subscription.isUnsubscribed()) {
- subscription.unsubscribe();
- }
- subscription = getTimerObservable()
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .doOnNext(new Action1<Long>() {
- @Override
- public void call(Long integer) {
- }
- })
- .subscribe(new Action1<Long>() {
- @Override
- public void call(Long seconds) {
- getMVPView().onDurationUpdate(seconds * 1000);
- }
- }, new Action1<Throwable>() {
- @Override
- public void call(Throwable throwable) {
- throwable.printStackTrace();
- }
- });
- subscriptions.add(subscription);
- }
- private Observable<Long> getTimerObservable() {
- return Observable.timer(ONE_SECOND, TimeUnit.SECONDS);
- // Observable.interval(ONE_SECOND, TimeUnit.SECONDS);
- // return Observable.create(new Observable.OnSubscribe<Integer>() {
- // @Override
- // public void call(final Subscriber<? super Integer> subscriber) {
- //
- // try {
- // int counter = 0;
- // while (!subscriber.isUnsubscribed()) {
- // TimeUnit.SECONDS.sleep(ONE_SECOND);
- //
- // if (!subscriber.isUnsubscribed()) {
- // subscriber.onNext(counter++);
- // }
- // }
- // } catch (Exception e) {
- // if (!subscriber.isUnsubscribed()) {
- // subscriber.onError(e);
- // }
- // }
- // }
- // });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement