Search in sources :

Example 1 with TopicsData

use of forpdateam.ru.forpda.api.topcis.models.TopicsData in project ForPDA by RadiationX.

the class Topics method getTopics.

public TopicsData getTopics(int id, int st) throws Exception {
    TopicsData data = new TopicsData();
    NetworkResponse response = Api.getWebClient().get("https://4pda.ru/forum/index.php?showforum=".concat(Integer.toString(id)).concat("&st=").concat(Integer.toString(st)));
    Matcher matcher = titlePattern.matcher(response.getBody());
    if (matcher.find()) {
        data.setId(Integer.parseInt(matcher.group(1)));
        data.setTitle(ApiUtils.fromHtml(matcher.group(2)));
    } else {
        data.setId(id);
    }
    matcher = canNewTopicPattern.matcher(response.getBody());
    data.setCanCreateTopic(matcher.find());
    matcher = announcePattern.matcher(response.getBody());
    while (matcher.find()) {
        TopicItem item = new TopicItem();
        item.setAnnounce(true);
        item.setAnnounceUrl(matcher.group(1));
        item.setTitle(ApiUtils.fromHtml(matcher.group(2)));
        data.addAnnounceItem(item);
    }
    matcher = topicsPattern.matcher(response.getBody());
    while (matcher.find()) {
        TopicItem item = new TopicItem();
        item.setId(Integer.parseInt(matcher.group(1)));
        int p = 0;
        String tmp = matcher.group(2);
        item.setNew(tmp.contains("+"));
        item.setPoll(tmp.contains("^"));
        item.setClosed(tmp.contains("Х"));
        item.setPinned(matcher.group(3) != null);
        item.setTitle(ApiUtils.fromHtml(matcher.group(4)));
        tmp = matcher.group(5);
        if (tmp != null)
            item.setDesc(ApiUtils.fromHtml(tmp));
        item.setAuthorId(Integer.parseInt(matcher.group(6)));
        item.setAuthorNick(ApiUtils.fromHtml(matcher.group(7)));
        item.setLastUserId(Integer.parseInt(matcher.group(8)));
        item.setLastUserNick(ApiUtils.fromHtml(matcher.group(9)));
        item.setDate(matcher.group(10));
        tmp = matcher.group(11);
        if (tmp != null) {
            item.setCuratorId(Integer.parseInt(tmp));
            item.setCuratorNick(ApiUtils.fromHtml(matcher.group(12)));
        }
        if (item.isPinned()) {
            data.addPinnedItem(item);
        } else {
            data.addTopicItem(item);
        }
    }
    matcher = forumPattern.matcher(response.getBody());
    while (matcher.find()) {
        TopicItem topicItem = new TopicItem();
        topicItem.setId(Integer.parseInt(matcher.group(1)));
        topicItem.setTitle(ApiUtils.fromHtml(matcher.group(2)));
        topicItem.setForum(true);
        data.addForumItem(topicItem);
    }
    data.setPagination(Pagination.parseForum(response.getBody()));
    return data;
}
Also used : TopicItem(forpdateam.ru.forpda.api.topcis.models.TopicItem) TopicsData(forpdateam.ru.forpda.api.topcis.models.TopicsData) Matcher(java.util.regex.Matcher) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse)

Example 2 with TopicsData

use of forpdateam.ru.forpda.api.topcis.models.TopicsData in project ForPDA by RadiationX.

the class TopicsFragment method loadData.

@Override
public boolean loadData() {
    if (!super.loadData()) {
        return false;
    }
    setRefreshing(true);
    subscribe(RxApi.Topics().getTopics(id, currentSt), this::onLoadThemes, new TopicsData(), v -> loadData());
    return true;
}
Also used : TopicsData(forpdateam.ru.forpda.api.topcis.models.TopicsData)

Aggregations

TopicsData (forpdateam.ru.forpda.api.topcis.models.TopicsData)2 NetworkResponse (forpdateam.ru.forpda.api.NetworkResponse)1 TopicItem (forpdateam.ru.forpda.api.topcis.models.TopicItem)1 Matcher (java.util.regex.Matcher)1