use of com.dante.data.model.MeiZiTu in project 91Pop by DanteAndroid.
the class AppApiHelper method action.
private Observable<BaseResult<List<MeiZiTu>>> action(Observable<String> stringObservable, String tag, final int page, final boolean pullToRefresh) {
DynamicKeyGroup dynamicKeyGroup = new DynamicKeyGroup(tag, page);
EvictDynamicKeyGroup evictDynamicKeyGroup = new EvictDynamicKeyGroup(pullToRefresh);
return cacheProviders.meiZiTu(stringObservable, dynamicKeyGroup, evictDynamicKeyGroup).map(new Function<Reply<String>, String>() {
@Override
public String apply(Reply<String> stringReply) throws Exception {
return stringReply.getData();
}
}).map(new Function<String, BaseResult<List<MeiZiTu>>>() {
@Override
public BaseResult<List<MeiZiTu>> apply(String s) throws Exception {
return ParseMeiZiTu.parseMzPosts(s, page);
}
});
}
use of com.dante.data.model.MeiZiTu in project 91Pop by DanteAndroid.
the class MeiZiTuFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
unbinder = ButterKnife.bind(this, view);
swipeLayout.setOnRefreshListener(this);
AppUtils.setColorSchemeColors(context, swipeLayout);
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
recyclerView.setAdapter(meiZiTuAdapter);
meiZiTuAdapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
@Override
public void onLoadMoreRequested() {
loadData(false, false);
}
}, recyclerView);
meiZiTuAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
@Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
MeiZiTu meiZiTu = (MeiZiTu) adapter.getItem(position);
if (meiZiTu == null) {
return;
}
Intent intent = new Intent(context, PictureViewerActivity.class);
intent.putExtra(Keys.KEY_INTENT_MEI_ZI_TU_CONTENT_ID, meiZiTu.getId());
startActivityWithAnimotion(intent);
}
});
}
use of com.dante.data.model.MeiZiTu in project 91Pop by DanteAndroid.
the class ParseMeiZiTu method parseMzPosts.
public static BaseResult<List<MeiZiTu>> parseMzPosts(String html, int page) {
BaseResult<List<MeiZiTu>> baseResult = new BaseResult<>();
baseResult.setTotalPage(1);
Document doc = Jsoup.parse(html);
Element ulPins = doc.getElementById("pins");
Elements lis = ulPins.select("li");
List<MeiZiTu> meiZiTuList = new ArrayList<>();
for (Element li : lis) {
MeiZiTu meiZiTu = new MeiZiTu();
String contentUrl = li.select("a").first().attr("href");
// meiZiTu.setContentUrl(contentUrl);
int index = contentUrl.lastIndexOf("/");
if (index >= 0 && index + 1 < contentUrl.length()) {
String idStr = contentUrl.substring(index + 1, contentUrl.length());
Logger.t(TAG).d(idStr);
if (!TextUtils.isEmpty(idStr) && TextUtils.isDigitsOnly(idStr)) {
meiZiTu.setId(Integer.parseInt(idStr));
}
}
Element imageElement = li.selectFirst("img");
String name = imageElement.attr("alt");
meiZiTu.setName(name);
String thumbUrl = imageElement.attr("data-original");
meiZiTu.setThumbUrl(thumbUrl);
Logger.t(TAG).d(thumbUrl);
int height = Integer.parseInt(imageElement.attr("height"));
meiZiTu.setHeight(height);
int width = Integer.parseInt(imageElement.attr("width"));
meiZiTu.setWidth(width);
String date = li.getElementsByClass("time").first().text();
meiZiTu.setDate(date);
String viewCount = li.getElementsByClass("view").first().text();
meiZiTu.setViewCount(viewCount);
meiZiTuList.add(meiZiTu);
}
Logger.t(TAG).d("size::" + meiZiTuList.size());
if (page == 1) {
Elements pageElements = doc.getElementsByClass("page-numbers");
if (pageElements != null && pageElements.size() > 3) {
String pageStr = pageElements.get(pageElements.size() - 2).text();
Logger.t(TAG).d("totalPage::" + pageStr);
if (!TextUtils.isEmpty(pageStr) && TextUtils.isDigitsOnly(pageStr)) {
baseResult.setTotalPage(Integer.parseInt(pageStr));
}
}
}
baseResult.setData(meiZiTuList);
return baseResult;
}
Aggregations