use of com.codeest.geeknews.model.bean.TopicListBean in project GeekNews by codeestX.
the class TopicAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
TopicListBean bean = mList.get(position);
ImageLoader.load(mContext, bean.getImgUrl(), holder.ivTopicFace);
holder.tvTopicName.setText(bean.getName());
holder.tvTopicTips.setText(bean.getUpdateTime() + " • 最后回复 " + bean.getLastUser());
holder.tvTopicComment.setText(String.valueOf(bean.getCommentNum()));
holder.tvTopicNode.setText(bean.getNode());
holder.tvTopicTitle.setText(bean.getTitle());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setClass(mContext, RepliesActivity.class);
intent.putExtra(Constants.IT_VTEX_TOPIC_ID, mList.get(holder.getAdapterPosition()).getTopicId());
mContext.startActivity(intent);
}
});
}
use of com.codeest.geeknews.model.bean.TopicListBean in project GeekNews by codeestX.
the class VtexPresenter method getContent.
@Override
public void getContent(String type) {
Observable.just(VtexApis.TAB_HOST + type).subscribeOn(Schedulers.io()).map(new Func1<String, Document>() {
@Override
public Document call(String s) {
try {
return Jsoup.connect(s).timeout(10000).get();
} catch (IOException e) {
LogUtil.d(e.toString());
e.printStackTrace();
}
return null;
}
}).filter(new Func1<Document, Boolean>() {
@Override
public Boolean call(Document document) {
return document != null;
}
}).map(new Func1<Document, List<TopicListBean>>() {
@Override
public List<TopicListBean> call(Document doc) {
List<TopicListBean> mList = new ArrayList<>();
//item根节点
Elements itemElements = doc.select("div.cell.item");
int count = itemElements.size();
for (int i = 0; i < count; i++) {
//标题
Elements titleElements = itemElements.get(i).select("div.cell.item table tr td span.item_title > a");
//头像
Elements imgElements = itemElements.get(i).select("div.cell.item table tr td img.avatar");
//节点
Elements nodeElements = itemElements.get(i).select("div.cell.item table tr span.small.fade a.node");
//评论数
Elements commentElements = itemElements.get(i).select("div.cell.item table tr a.count_livid");
//作者 & 最后回复
Elements nameElements = itemElements.get(i).select("div.cell.item table tr span.small.fade strong a");
//更新时间
Elements timeElements = itemElements.get(i).select("div.cell.item table tr span.small.fade");
TopicListBean bean = new TopicListBean();
if (titleElements.size() > 0) {
bean.setTitle(titleElements.get(0).text());
bean.setTopicId(parseId(titleElements.get(0).attr("href")));
}
if (imgElements.size() > 0) {
bean.setImgUrl(parseImg(imgElements.get(0).attr("src")));
}
if (nodeElements.size() > 0) {
bean.setNode(nodeElements.get(0).text());
}
if (nameElements.size() > 0) {
bean.setName(nameElements.get(0).text());
}
//存在没有 最后回复者、评论数、更新时间的情况
if (nameElements.size() > 1) {
bean.setLastUser(nameElements.get(1).text());
}
if (commentElements.size() > 0) {
bean.setCommentNum(Integer.valueOf(commentElements.get(0).text()));
}
if (timeElements.size() > 1) {
bean.setUpdateTime(parseTime(timeElements.get(1).text()));
}
mList.add(bean);
}
return mList;
}
}).observeOn(AndroidSchedulers.mainThread()).subscribe(new CommonSubscriber<List<TopicListBean>>(mView) {
@Override
public void onNext(List<TopicListBean> mList) {
mView.showContent(mList);
}
});
}
Aggregations