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;
}
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());
}
}
}
});
}
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;
}
}
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("节点列表为空");
}
}
Aggregations