Search in sources :

Example 1 with Node

use of org.mazhuang.guanggoo.data.entity.Node in project guanggoo-android by mzlogin.

the class GetTopicListTask method createMetaFromElement.

private static Meta createMetaFromElement(Element element) {
    Meta meta = new Meta();
    Element nodeElement = element.select("span.node").select("a").first();
    Node node = new Node();
    node.setTitle(nodeElement.text());
    node.setUrl(nodeElement.absUrl("href"));
    meta.setNode(node);
    Element userElement = element.select("span.username").select("a").first();
    User user = new User();
    user.setUsername(userElement.text());
    user.setUrl(userElement.absUrl("href"));
    meta.setAuthor(user);
    // 主题列表页
    Elements lastTouchedElement = element.select("span.last-touched");
    if (lastTouchedElement.isEmpty()) {
        // 主题详情页
        lastTouchedElement = element.select("span.last-reply-time");
    }
    meta.setLastTouched(lastTouchedElement.text());
    Elements createdTimeElement = element.select("span.created-time");
    meta.setCreatedTime(createdTimeElement.text());
    Element lastReplyUserElement = element.select("span.last-reply-username").select("a").first();
    if (lastReplyUserElement != null) {
        User lastReplyUser = new User();
        lastReplyUser.setUsername(lastReplyUserElement.select("strong").text());
        lastReplyUser.setUrl(lastReplyUserElement.absUrl("href"));
        meta.setLastReplyUser(lastReplyUser);
    }
    return meta;
}
Also used : Meta(org.mazhuang.guanggoo.data.entity.Meta) User(org.mazhuang.guanggoo.data.entity.User) Element(org.jsoup.nodes.Element) Node(org.mazhuang.guanggoo.data.entity.Node) Elements(org.jsoup.select.Elements)

Example 2 with Node

use of org.mazhuang.guanggoo.data.entity.Node in project guanggoo-android by mzlogin.

the class NodesCloudAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(NodesCloudAdapter.ViewHolder holder, int position) {
    final NodeCategory category = mData.get(position);
    holder.mTitleTextView.setText(category.getLabel());
    holder.mNodesGridView.setAdapter(new BaseAdapter() {

        @Override
        public int getCount() {
            return (category.getNodes() == null) ? 0 : category.getNodes().size();
        }

        @Override
        public Object getItem(int position) {
            return category.getNodes().get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ChildViewHolder childViewHolder;
            if (convertView == null) {
                convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.child_nodes_cloud, null);
                childViewHolder = new ChildViewHolder(convertView);
                convertView.setTag(childViewHolder);
            } else {
                childViewHolder = (ChildViewHolder) convertView.getTag();
            }
            childViewHolder.mTitleTextView.setText(category.getNodes().get(position).getTitle());
            return convertView;
        }
    });
    holder.mNodesGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (mListener != null) {
                Node node = category.getNodes().get(position);
                if (mNodeClickListener != null) {
                    mNodeClickListener.onNodeClick(node);
                } else {
                    mListener.openPage(node.getUrl(), node.getTitle());
                }
            }
        }
    });
}
Also used : ViewGroup(android.view.ViewGroup) Node(org.mazhuang.guanggoo.data.entity.Node) GridView(android.widget.GridView) BindView(butterknife.BindView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) NodeCategory(org.mazhuang.guanggoo.data.entity.NodeCategory) AdapterView(android.widget.AdapterView) BaseAdapter(android.widget.BaseAdapter)

Example 3 with Node

use of org.mazhuang.guanggoo.data.entity.Node in project guanggoo-android by mzlogin.

the class TopicDetailFragment method onClick.

@OnClick({ R.id.load_more, R.id.submit, R.id.author, R.id.avatar, R.id.node, R.id.edit, R.id.edit_text, R.id.favorite, R.id.share })
public void onClick(View v) {
    if (mTopicDetail == null) {
        return;
    }
    switch(v.getId()) {
        case R.id.load_more:
            {
                mLoadMoreTextView.setEnabled(false);
                int page = (mAdapter.getSmallestFloor() - 1) / ConstantUtil.COMMENTS_PER_PAGE;
                if (page == 0) {
                    mLoadMoreTextView.setVisibility(View.GONE);
                    return;
                }
                mPresenter.getMoreComments(page);
            }
            break;
        case R.id.submit:
            if (mListener != null && mListener.isLoading()) {
                return;
            }
            if (TextUtils.isEmpty(mCommentEditText.getText())) {
                Toast.makeText(getContext(), R.string.please_input_comment_content, Toast.LENGTH_SHORT).show();
            } else {
                mPresenter.comment(mCommentEditText.getText().toString());
            }
            break;
        case R.id.author:
        case R.id.avatar:
            if (mListener != null) {
                mListener.openPage(mTopicDetail.getTopic().getMeta().getAuthor().getUrl(), null);
            }
            break;
        case R.id.node:
            if (mListener != null) {
                Node node = mTopicDetail.getTopic().getMeta().getNode();
                mListener.openPage(node.getUrl(), node.getTitle());
            }
            break;
        case R.id.edit:
        case R.id.edit_text:
            showCommentView();
            break;
        case R.id.favorite:
            if (mTopicDetail.getFavorite().isFavorite()) {
                mPresenter.unfavorite();
            } else {
                mPresenter.favorite();
            }
            break;
        case R.id.share:
            shareCurrentLink();
            break;
        default:
            break;
    }
}
Also used : Node(org.mazhuang.guanggoo.data.entity.Node) OnClick(butterknife.OnClick)

Example 4 with Node

use of org.mazhuang.guanggoo.data.entity.Node in project guanggoo-android by mzlogin.

the class GetNodesCloudTask method run.

@Override
public void run() {
    Document doc;
    try {
        doc = get(ConstantUtil.NODES_CLOUD_URL);
    } catch (IOException e) {
        e.printStackTrace();
        failedOnUI(e.getMessage());
        return;
    }
    Elements nodesCategoryList = doc.select("div.nodes-cloud ul li");
    if (nodesCategoryList.isEmpty()) {
        failedOnUI("找不到节点列表");
        return;
    }
    List<NodeCategory> nodesCloud = new ArrayList<>();
    for (Element element : nodesCategoryList) {
        Elements labelElement = element.select("label");
        Elements nodesElement = element.select("span.nodes a");
        if (!labelElement.isEmpty() && !nodesElement.isEmpty()) {
            List<Node> nodes = new ArrayList<>();
            for (Element nodeElement : nodesElement) {
                Node node = new Node();
                node.setTitle(nodeElement.text());
                node.setUrl(nodeElement.absUrl("href"));
                nodes.add(node);
            }
            if (!nodes.isEmpty()) {
                NodeCategory category = new NodeCategory();
                category.setLabel(labelElement.text());
                category.setNodes(nodes);
                nodesCloud.add(category);
            }
        }
    }
    if (!nodesCloud.isEmpty()) {
        successOnUI(nodesCloud);
    } else {
        failedOnUI("节点列表为空");
    }
}
Also used : NodeCategory(org.mazhuang.guanggoo.data.entity.NodeCategory) Element(org.jsoup.nodes.Element) Node(org.mazhuang.guanggoo.data.entity.Node) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Aggregations

Node (org.mazhuang.guanggoo.data.entity.Node)4 Element (org.jsoup.nodes.Element)2 Elements (org.jsoup.select.Elements)2 NodeCategory (org.mazhuang.guanggoo.data.entity.NodeCategory)2 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 AdapterView (android.widget.AdapterView)1 BaseAdapter (android.widget.BaseAdapter)1 GridView (android.widget.GridView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 OnClick (butterknife.OnClick)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Document (org.jsoup.nodes.Document)1 Meta (org.mazhuang.guanggoo.data.entity.Meta)1 User (org.mazhuang.guanggoo.data.entity.User)1