Search in sources :

Example 1 with ChapterRead

use of com.justwayward.reader.bean.ChapterRead in project BookReader by JustWayward.

the class BookReadPresenter method getChapterRead.

@Override
public void getChapterRead(String url, final int chapter) {
    Subscription rxSubscription = bookApi.getChapterRead(url).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<ChapterRead>() {

        @Override
        public void onNext(ChapterRead data) {
            if (data.chapter != null && mView != null) {
                mView.showChapterRead(data.chapter, chapter);
            } else {
                mView.netError(chapter);
            }
        }

        @Override
        public void onCompleted() {
        }

        @Override
        public void onError(Throwable e) {
            LogUtils.e("onError: " + e);
            mView.netError(chapter);
        }
    });
    addSubscrebe(rxSubscription);
}
Also used : Subscription(rx.Subscription) ChapterRead(com.justwayward.reader.bean.ChapterRead)

Example 2 with ChapterRead

use of com.justwayward.reader.bean.ChapterRead in project BookReader by JustWayward.

the class DownloadBookService method download.

private int download(String url, final String bookId, final String title, final int chapter, final int chapterSize) {
    final int[] result = { -1 };
    Subscription subscription = bookApi.getChapterRead(url).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<ChapterRead>() {

        @Override
        public void onNext(ChapterRead data) {
            if (data.chapter != null) {
                post(new DownloadProgress(bookId, String.format(getString(R.string.book_read_download_progress), title, chapter, chapterSize), true));
                CacheManager.getInstance().saveChapterFile(bookId, chapter, data.chapter);
                result[0] = 1;
            } else {
                result[0] = 0;
            }
        }

        @Override
        public void onCompleted() {
            result[0] = 1;
        }

        @Override
        public void onError(Throwable e) {
            result[0] = 0;
        }
    });
    addSubscrebe(subscription);
    while (result[0] == -1) {
        try {
            Thread.sleep(350);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    return result[0];
}
Also used : DownloadProgress(com.justwayward.reader.bean.support.DownloadProgress) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription) ChapterRead(com.justwayward.reader.bean.ChapterRead)

Aggregations

ChapterRead (com.justwayward.reader.bean.ChapterRead)2 Subscription (rx.Subscription)2 DownloadProgress (com.justwayward.reader.bean.support.DownloadProgress)1 CompositeSubscription (rx.subscriptions.CompositeSubscription)1