@OnClick(R.id.btn_start_operation)
  public void startOperation() {

    _logs.clear();
    _log("Button Clicked");

    Observable.fromIterable(
            Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l")) //
        .flatMap(
            s1 -> {
              _log(s1 + "start");

              if (s1.equalsIgnoreCase("b") && _attempt < 5) {
                _attempt++;
                return Observable.error(
                    new Throwable("b can't be processed (" + (_attempt - 1) + ")"));
              }

              if (s1.equalsIgnoreCase("c") || s1.equalsIgnoreCase("f")) {
                return Observable.just(s1);
              } else {
                return Observable.timer(2, TimeUnit.SECONDS).map(l -> s1);
              }
            })
        .retryWhen(source -> source.delay(8, TimeUnit.SECONDS))
        .doOnNext(s -> _log(s + "stop"))
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe();
  }
Ejemplo n.º 2
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Activity activity = getActivity();
    if (activity instanceof PagerActivity) {
      final PagerActivity pagerActivity = (PagerActivity) activity;

      downloadImage();

      handler.postDelayed(
          () -> new QueryPageCoordinatesTask(pagerActivity).execute(pageNumber), 1000);

      if (QuranSettings.getInstance(activity).shouldHighlightBookmarks()) {
        // Observable.timer by default runs on Schedulers.computation()
        compositeDisposable.add(
            Completable.timer(250, TimeUnit.MILLISECONDS)
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribeWith(
                    new DisposableCompletableObserver() {
                      @Override
                      public void onComplete() {
                        highlightTagsTask();
                      }

                      @Override
                      public void onError(Throwable e) {}
                    }));
      }
    }
  }
Ejemplo n.º 3
0
  private void highlightTagsTask() {
    compositeDisposable.add(
        bookmarkModel
            .getBookmarkedAyahsOnPageObservable(pageNumber)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeWith(
                new DisposableObserver<List<Bookmark>>() {
                  @Override
                  public void onNext(List<Bookmark> bookmarks) {
                    for (int i = 0, bookmarksSize = bookmarks.size(); i < bookmarksSize; i++) {
                      Bookmark taggedAyah = bookmarks.get(i);
                      mImageView.highlightAyah(
                          taggedAyah.sura, taggedAyah.ayah, HighlightType.BOOKMARK);
                    }

                    if (mCoordinatesData == null) {
                      if (mCurrentTask != null && !(mCurrentTask instanceof QueryAyahCoordsTask)) {
                        mCurrentTask.cancel(true);
                        mCurrentTask = null;
                      }

                      if (mCurrentTask == null) {
                        mCurrentTask = new GetAyahCoordsTask(getActivity()).execute(pageNumber);
                      }
                    } else {
                      mImageView.invalidate();
                    }
                  }

                  @Override
                  public void onError(Throwable e) {}

                  @Override
                  public void onComplete() {}
                }));
  }