use of org.mazhuang.guanggoo.data.entity.TopicList in project guanggoo-android by mzlogin.
the class GetTopicListTask method run.
@Override
public void run() {
List<Topic> topics = new ArrayList<>();
boolean succeed = false;
boolean hasMore = false;
try {
Document doc = get(mUrl);
Elements elements = doc.select("div.topic-item");
for (Element element : elements) {
Topic topic = createTopicFromElement(element);
topics.add(topic);
}
succeed = true;
Elements paginationElements = doc.select("ul.pagination");
if (!paginationElements.isEmpty()) {
Elements disabledElements = paginationElements.select("li.disabled");
if (disabledElements.isEmpty()) {
hasMore = true;
} else if (disabledElements.last() != null) {
Elements disableLinkElements = disabledElements.last().select("a");
if (!ConstantUtil.NEXT_PAGE.equals(disableLinkElements.text())) {
hasMore = true;
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
if (succeed) {
TopicList topicList = new TopicList();
topicList.setTopics(topics);
topicList.setHasMore(hasMore);
successOnUI(topicList);
} else {
failedOnUI("获取主题列表失败");
}
}
use of org.mazhuang.guanggoo.data.entity.TopicList in project guanggoo-android by mzlogin.
the class TopicListPresenter method getMoreTopic.
@Override
public void getMoreTopic(int page) {
if (mCurrentTask != null) {
mCurrentTask.cancel();
}
mCurrentTask = new GetTopicListTask(UrlUtil.appendPage(mView.getUrl(), page), new OnResponseListener<TopicList>() {
@Override
public void onSucceed(TopicList data) {
mView.onGetMoreTopicSucceed(data);
mCurrentTask = null;
}
@Override
public void onFailed(String msg) {
mView.onGetMoreTopicFailed(msg);
mCurrentTask = null;
}
});
NetworkTaskScheduler.getInstance().execute(mCurrentTask);
}
use of org.mazhuang.guanggoo.data.entity.TopicList in project guanggoo-android by mzlogin.
the class TopicListPresenter method getTopicList.
@Override
public void getTopicList() {
if (mCurrentTask != null) {
mCurrentTask.cancel();
}
mCurrentTask = new GetTopicListTask(mView.getUrl(), new OnResponseListener<TopicList>() {
@Override
public void onSucceed(TopicList data) {
mView.onGetTopicListSucceed(data);
mCurrentTask = null;
}
@Override
public void onFailed(String msg) {
mView.onGetTopicListFailed(msg);
mCurrentTask = null;
}
});
NetworkTaskScheduler.getInstance().execute(mCurrentTask);
}
Aggregations