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);
}
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;
}
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();
}
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();
}
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;
}
Aggregations