Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. private void startDurationUpdate() {
  2. if (subscription != null && !subscription.isUnsubscribed()) {
  3. subscription.unsubscribe();
  4. }
  5. subscription = getTimerObservable()
  6. .subscribeOn(Schedulers.io())
  7. .observeOn(AndroidSchedulers.mainThread())
  8. .doOnNext(new Action1<Long>() {
  9. @Override
  10. public void call(Long integer) {
  11.  
  12. }
  13. })
  14. .subscribe(new Action1<Long>() {
  15. @Override
  16. public void call(Long seconds) {
  17. getMVPView().onDurationUpdate(seconds * 1000);
  18. }
  19. }, new Action1<Throwable>() {
  20. @Override
  21. public void call(Throwable throwable) {
  22. throwable.printStackTrace();
  23. }
  24. });
  25. subscriptions.add(subscription);
  26. }
  27.  
  28. private Observable<Long> getTimerObservable() {
  29. return Observable.timer(ONE_SECOND, TimeUnit.SECONDS);
  30. // Observable.interval(ONE_SECOND, TimeUnit.SECONDS);
  31. // return Observable.create(new Observable.OnSubscribe<Integer>() {
  32. // @Override
  33. // public void call(final Subscriber<? super Integer> subscriber) {
  34. //
  35. // try {
  36. // int counter = 0;
  37. // while (!subscriber.isUnsubscribed()) {
  38. // TimeUnit.SECONDS.sleep(ONE_SECOND);
  39. //
  40. // if (!subscriber.isUnsubscribed()) {
  41. // subscriber.onNext(counter++);
  42. // }
  43. // }
  44. // } catch (Exception e) {
  45. // if (!subscriber.isUnsubscribed()) {
  46. // subscriber.onError(e);
  47. // }
  48. // }
  49. // }
  50. // });
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement