Search in sources :

Example 1 with TopicItem

use of forpdateam.ru.forpda.api.topcis.models.TopicItem 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 TopicItem

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

the class TopicsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(BaseSectionedViewHolder holder, int section, int relativePosition, int absolutePosition) {
    TopicItem item = getItem(section, relativePosition);
    int viewType = getItemViewType(section, relativePosition, absolutePosition);
    if (viewType == VIEW_TYPE_ANNOUNCE) {
        ((AnnounceHolder) holder).bind(item);
    } else {
        ((ItemHolder) holder).bind(item);
    }
}
Also used : TopicItem(forpdateam.ru.forpda.api.topcis.models.TopicItem)

Example 3 with TopicItem

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

the class TopicsFragment method markRead.

public void markRead(int topicId) {
    Log.d("SUKA", "markRead " + topicId);
    for (TopicItem item : data.getTopicItems()) {
        if (item.getId() == topicId) {
            item.setNew(false);
        }
    }
    adapter.notifyDataSetChanged();
}
Also used : TopicItem(forpdateam.ru.forpda.api.topcis.models.TopicItem)

Aggregations

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