Search in sources :

Example 1 with PixivIllustBean

use of pri.weiqiang.liyujapanese.mvp.bean.pixivIllust.PixivIllustBean in project MyJapanese by 54wall.

the class PixivIllustFragmentModelImpl method getIllusts.

@Override
public void getIllusts(final String mode, Consumer<List<PixivIllustBean>> consumer) {
    Disposable disposable = Observable.create(new ObservableOnSubscribe<List<PixivIllustBean>>() {

        @Override
        public void subscribe(final ObservableEmitter<List<PixivIllustBean>> emitter) throws Exception {
            service.getIllusts(mode, new Consumer<ResponseBody>() {

                @Override
                public void accept(ResponseBody responseBody) throws Exception {
                    List<PixivIllustBean> list = handleResponseBody(responseBody);
                    if (list == null) {
                        emitter.onError(new Exception());
                    } else {
                        emitter.onNext(list);
                    }
                }
            });
            emitter.onComplete();
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(consumer);
    mCompositeDisposable.add(disposable);
}
Also used : Disposable(io.reactivex.disposables.Disposable) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) ArrayList(java.util.ArrayList) List(java.util.List) PixivIllustBean(pri.weiqiang.liyujapanese.mvp.bean.pixivIllust.PixivIllustBean) ObservableEmitter(io.reactivex.ObservableEmitter) IOException(java.io.IOException) ResponseBody(okhttp3.ResponseBody)

Example 2 with PixivIllustBean

use of pri.weiqiang.liyujapanese.mvp.bean.pixivIllust.PixivIllustBean in project MyJapanese by 54wall.

the class PixivIllustFragmentModelImpl method handleResponseBody.

private static List<PixivIllustBean> handleResponseBody(ResponseBody responseBody) {
    List<PixivIllustBean> list = new ArrayList<>();
    Document document = null;
    try {
        document = Jsoup.parse(responseBody.string());
    } catch (IOException e) {
        e.printStackTrace();
    }
    responseBody.close();
    if (document != null) {
        Elements elements = document.getElementsByClass("ranking-item");
        for (int i = 0; i < elements.size(); i++) {
            final PixivIllustBean bean = new PixivIllustBean();
            Element element = elements.get(i);
            bean.setId(Integer.parseInt(element.attr("data-id")));
            bean.setTitle(element.attr("data-title"));
            bean.setAuthor(element.attr("data-user-name"));
            bean.setDate(element.attr("data-date"));
            Element link_element = element.getElementsByClass("ranking-image-item").first().select("a").first();
            if (link_element != null) {
                bean.setLink(Constants.PIXIV_URL + "/" + link_element.attr("href"));
            }
            Element thumbnail_element = element.getElementsByClass("_layout-thumbnail").first().select("img").first();
            if (thumbnail_element != null) {
                bean.setImg_240x480(thumbnail_element.attr("data-src"));
                if (bean.getImg_240x480() != null) {
                    bean.setImg_600x600(bean.getImg_240x480().replace("/c/240x480/", "/c/600x600/"));
                    bean.setImg_1200x1200(bean.getImg_240x480().replace("/c/240x480/", "/c/1200x1200/"));
                    bean.setImg_original(bean.getImg_240x480().replace("/c/240x480/img-master/", "/img-original/").replace("_master1200", ""));
                }
            }
            list.add(bean);
        }
    }
    return list;
}
Also used : Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) PixivIllustBean(pri.weiqiang.liyujapanese.mvp.bean.pixivIllust.PixivIllustBean) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Example 3 with PixivIllustBean

use of pri.weiqiang.liyujapanese.mvp.bean.pixivIllust.PixivIllustBean in project MyJapanese by 54wall.

the class PixivIllustFragment method setData.

@Override
public void setData(List<PixivIllustBean> data) {
    PixivIllustRecyclerAdapter adapter = new PixivIllustRecyclerAdapter(getContext(), data);
    adapter.setOnItemClickListener(new PixivIllustRecyclerAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(PixivIllustBean bean) {
            presenter.onItemClick(bean);
        }
    });
    mRecyclerView.setAdapter(adapter);
    mRecyclerView.refreshDrawableState();
}
Also used : PixivIllustRecyclerAdapter(pri.weiqiang.liyujapanese.ui.adapter.PixivIllustRecyclerAdapter) PixivIllustBean(pri.weiqiang.liyujapanese.mvp.bean.pixivIllust.PixivIllustBean)

Example 4 with PixivIllustBean

use of pri.weiqiang.liyujapanese.mvp.bean.pixivIllust.PixivIllustBean in project LiYuJapanese by 54wall.

the class PixivIllustFragment method setData.

@Override
public void setData(List<PixivIllustBean> data) {
    PixivIllustRecyclerAdapter adapter = new PixivIllustRecyclerAdapter(getContext(), data);
    adapter.setOnItemClickListener(new PixivIllustRecyclerAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(PixivIllustBean bean) {
            presenter.onItemClick(bean);
        }
    });
    mRecyclerView.setAdapter(adapter);
    mRecyclerView.refreshDrawableState();
}
Also used : PixivIllustRecyclerAdapter(pri.weiqiang.liyujapanese.ui.adapter.PixivIllustRecyclerAdapter) PixivIllustBean(pri.weiqiang.liyujapanese.mvp.bean.pixivIllust.PixivIllustBean)

Example 5 with PixivIllustBean

use of pri.weiqiang.liyujapanese.mvp.bean.pixivIllust.PixivIllustBean in project LiYuJapanese by 54wall.

the class PixivIllustFragmentModelImpl method handleResponseBody.

private static List<PixivIllustBean> handleResponseBody(ResponseBody responseBody) {
    List<PixivIllustBean> list = new ArrayList<>();
    Document document = null;
    try {
        document = Jsoup.parse(responseBody.string());
    } catch (IOException e) {
        e.printStackTrace();
    }
    responseBody.close();
    if (document != null) {
        Elements elements = document.getElementsByClass("ranking-item");
        for (int i = 0; i < elements.size(); i++) {
            final PixivIllustBean bean = new PixivIllustBean();
            Element element = elements.get(i);
            bean.setId(Integer.parseInt(element.attr("data-id")));
            bean.setTitle(element.attr("data-title"));
            bean.setAuthor(element.attr("data-user-name"));
            bean.setDate(element.attr("data-date"));
            Element link_element = element.getElementsByClass("ranking-image-item").first().select("a").first();
            if (link_element != null) {
                bean.setLink(Constants.PIXIV_URL + "/" + link_element.attr("href"));
            }
            Element thumbnail_element = element.getElementsByClass("_layout-thumbnail").first().select("img").first();
            if (thumbnail_element != null) {
                bean.setImg_240x480(thumbnail_element.attr("data-src"));
                if (bean.getImg_240x480() != null) {
                    bean.setImg_600x600(bean.getImg_240x480().replace("/c/240x480/", "/c/600x600/"));
                    bean.setImg_1200x1200(bean.getImg_240x480().replace("/c/240x480/", "/c/1200x1200/"));
                    bean.setImg_original(bean.getImg_240x480().replace("/c/240x480/img-master/", "/img-original/").replace("_master1200", ""));
                }
            }
            list.add(bean);
        }
    }
    return list;
}
Also used : Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) PixivIllustBean(pri.weiqiang.liyujapanese.mvp.bean.pixivIllust.PixivIllustBean) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Aggregations

PixivIllustBean (pri.weiqiang.liyujapanese.mvp.bean.pixivIllust.PixivIllustBean)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ObservableEmitter (io.reactivex.ObservableEmitter)2 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)2 Disposable (io.reactivex.disposables.Disposable)2 List (java.util.List)2 ResponseBody (okhttp3.ResponseBody)2 Document (org.jsoup.nodes.Document)2 Element (org.jsoup.nodes.Element)2 Elements (org.jsoup.select.Elements)2 PixivIllustRecyclerAdapter (pri.weiqiang.liyujapanese.ui.adapter.PixivIllustRecyclerAdapter)2