Search in sources :

Example 1 with TopicListBean

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);
        }
    });
}
Also used : Intent(android.content.Intent) TopicListBean(com.codeest.geeknews.model.bean.TopicListBean) SquareImageView(com.codeest.geeknews.widget.SquareImageView) BindView(butterknife.BindView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) RepliesActivity(com.codeest.geeknews.ui.vtex.activity.RepliesActivity)

Example 2 with TopicListBean

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);
        }
    });
}
Also used : IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) TopicListBean(com.codeest.geeknews.model.bean.TopicListBean) ArrayList(java.util.ArrayList) List(java.util.List) Func1(rx.functions.Func1)

Aggregations

TopicListBean (com.codeest.geeknews.model.bean.TopicListBean)2 Intent (android.content.Intent)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 RepliesActivity (com.codeest.geeknews.ui.vtex.activity.RepliesActivity)1 SquareImageView (com.codeest.geeknews.widget.SquareImageView)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Document (org.jsoup.nodes.Document)1 Elements (org.jsoup.select.Elements)1 Func1 (rx.functions.Func1)1