Search in sources :

Example 1 with ForumRules

use of forpdateam.ru.forpda.api.forum.models.ForumRules in project ForPDA by RadiationX.

the class Forum method getRules.

public ForumRules getRules() throws Exception {
    ForumRules rules = new ForumRules();
    String response = Api.getWebClient().get("https://4pda.ru/forum/index.php?act=boardrules").getBody();
    Matcher headerMatcher = rulesHeaders.matcher(response);
    Matcher itemMatcher = null;
    while (headerMatcher.find()) {
        ForumRules.Item header = new ForumRules.Item();
        header.setHeader(true);
        header.setNumber(headerMatcher.group(1));
        header.setText(headerMatcher.group(2));
        String itemContent = headerMatcher.group(3);
        itemMatcher = itemMatcher == null ? rulesItems.matcher(itemContent) : itemMatcher.reset(itemContent);
        rules.addItem(header);
        while (itemMatcher.find()) {
            ForumRules.Item item = new ForumRules.Item();
            item.setNumber(itemMatcher.group(1));
            item.setText(itemMatcher.group(2));
            rules.addItem(item);
        }
    }
    return rules;
}
Also used : Matcher(java.util.regex.Matcher) ForumRules(forpdateam.ru.forpda.api.forum.models.ForumRules)

Example 2 with ForumRules

use of forpdateam.ru.forpda.api.forum.models.ForumRules in project ForPDA by RadiationX.

the class ForumRx method transform.

public static ForumRules transform(ForumRules rules, boolean withHtml) throws Exception {
    if (withHtml) {
        MiniTemplator t = App.get().getTemplate(App.TEMPLATE_FORUM_RULES);
        App.setTemplateResStrings(t);
        t.setVariableOpt("style_type", App.get().getCssStyleType());
        for (ForumRules.Item item : rules.getItems()) {
            t.setVariableOpt("type", item.isHeader() ? "header" : "");
            t.setVariableOpt("number", item.getNumber());
            t.setVariableOpt("text", item.getText());
            t.addBlockOpt("rules_item");
        }
        rules.setHtml(t.generateOutput());
        t.reset();
    }
    return rules;
}
Also used : ForumRules(forpdateam.ru.forpda.api.forum.models.ForumRules) MiniTemplator(biz.source_code.miniTemplator.MiniTemplator)

Example 3 with ForumRules

use of forpdateam.ru.forpda.api.forum.models.ForumRules in project ForPDA by RadiationX.

the class ForumRulesFragment method loadData.

@Override
public boolean loadData() {
    if (!super.loadData()) {
        return false;
    }
    setRefreshing(true);
    subscribe(RxApi.Forum().getRules(true), this::onLoad, new ForumRules(), view1 -> loadData());
    return true;
}
Also used : ForumRules(forpdateam.ru.forpda.api.forum.models.ForumRules)

Aggregations

ForumRules (forpdateam.ru.forpda.api.forum.models.ForumRules)3 MiniTemplator (biz.source_code.miniTemplator.MiniTemplator)1 Matcher (java.util.regex.Matcher)1