Esempio n. 1
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) {}
                    }));
      }
    }
  }
Esempio n. 2
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() {}
                }));
  }