Search in sources :

Example 1 with TopicList

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("获取主题列表失败");
    }
}
Also used : Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) TopicList(org.mazhuang.guanggoo.data.entity.TopicList) IOException(java.io.IOException) Topic(org.mazhuang.guanggoo.data.entity.Topic) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Example 2 with TopicList

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);
}
Also used : GetTopicListTask(org.mazhuang.guanggoo.data.task.GetTopicListTask) OnResponseListener(org.mazhuang.guanggoo.data.OnResponseListener) TopicList(org.mazhuang.guanggoo.data.entity.TopicList)

Example 3 with TopicList

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);
}
Also used : GetTopicListTask(org.mazhuang.guanggoo.data.task.GetTopicListTask) OnResponseListener(org.mazhuang.guanggoo.data.OnResponseListener) TopicList(org.mazhuang.guanggoo.data.entity.TopicList)

Aggregations

TopicList (org.mazhuang.guanggoo.data.entity.TopicList)3 OnResponseListener (org.mazhuang.guanggoo.data.OnResponseListener)2 GetTopicListTask (org.mazhuang.guanggoo.data.task.GetTopicListTask)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Document (org.jsoup.nodes.Document)1 Element (org.jsoup.nodes.Element)1 Elements (org.jsoup.select.Elements)1 Topic (org.mazhuang.guanggoo.data.entity.Topic)1