Search in sources :

Example 1 with ForumItemTree

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

the class Forum method transformToList.

public void transformToList(List<ForumItemFlat> list, ForumItemTree rootForum) {
    if (rootForum.getForums() == null)
        return;
    for (ForumItemTree item : rootForum.getForums()) {
        list.add(new ForumItemFlat(item));
        transformToList(list, item);
    }
}
Also used : ForumItemTree(forpdateam.ru.forpda.api.forum.models.ForumItemTree) IForumItemFlat(forpdateam.ru.forpda.api.forum.interfaces.IForumItemFlat) ForumItemFlat(forpdateam.ru.forpda.api.forum.models.ForumItemFlat)

Example 2 with ForumItemTree

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

the class Forum method getForums.

// Для обхода по страницам, но чет там через попу всё работает - не все элементы находит
// private final static Pattern rootPattern = Pattern.compile("<div[^>]*?id=[\"']fo_(\\d+)[\"'][^>]*?>[^<]*?<div[^>]*?cat_name[^>]*?>[^<]*?<div[\\s\\S]*?\\/div>[^<]*?<a[^>]*?>([\\s\\S]*?)<\\/a>[^<]*?<\\/div>([\\s\\S]*?)<\\/div>[^<]*?(?=<div id=['\"]fc|<div class=[\"']stat)");
// private final static Pattern boardsPattern = Pattern.compile("<div[^>]*?board_forum_row[^>]*><div[^>]*?forum_name[^>]*?>[\\s\\S]*?<a[^>]*?showforum=(\\d+)[^>]*?>([^<]*?)<\\/a>[^<]*?<\\/div>");
public ForumItemTree getForums() throws Exception {
    NetworkResponse response = Api.getWebClient().get("https://4pda.ru/forum/index.php?act=search");
    Matcher matcher = forumsFromSearch.matcher(response.getBody());
    final ForumItemTree root = new ForumItemTree();
    if (matcher.find()) {
        matcher = forumItemFromSearch.matcher(matcher.group(1));
        List<ForumItemTree> parentsList = new ArrayList<>();
        ForumItemTree lastParent = root;
        parentsList.add(lastParent);
        while (matcher.find()) {
            ForumItemTree item = new ForumItemTree();
            item.setId(Integer.parseInt(matcher.group(1)));
            item.setLevel(matcher.group(2).length() / 2);
            item.setTitle(ApiUtils.fromHtml(matcher.group(3)));
            if (item.getLevel() <= lastParent.getLevel()) {
                // Удаление элементов, учитывая случай с резким скачком уровня вложенности
                for (int i = 0; i < (lastParent.getLevel() - item.getLevel() + 1); i++) parentsList.remove(parentsList.size() - 1);
                lastParent = parentsList.get(parentsList.size() - 1);
            }
            item.setParentId(lastParent.getId());
            lastParent.addForum(item);
            if (item.getLevel() > lastParent.getLevel()) {
                lastParent = item;
                parentsList.add(lastParent);
            }
        }
        parentsList.clear();
    }
    return root;
}
Also used : ForumItemTree(forpdateam.ru.forpda.api.forum.models.ForumItemTree) Matcher(java.util.regex.Matcher) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) ArrayList(java.util.ArrayList)

Example 3 with ForumItemTree

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

the class Forum method transformToTree.

public void transformToTree(Collection<? extends IForumItemFlat> list, ForumItemTree rootForum) {
    List<ForumItemTree> parentsList = new ArrayList<>();
    ForumItemTree lastParent = rootForum;
    parentsList.add(lastParent);
    for (IForumItemFlat item : list) {
        ForumItemTree newItem = new ForumItemTree(item);
        if (item.getLevel() <= lastParent.getLevel()) {
            // Удаление элементов, учитывая случай с резким скачком уровня вложенности
            for (int i = 0; i < (lastParent.getLevel() - item.getLevel() + 1); i++) parentsList.remove(parentsList.size() - 1);
            lastParent = parentsList.get(parentsList.size() - 1);
        }
        lastParent.addForum(newItem);
        if (item.getLevel() > lastParent.getLevel()) {
            lastParent = newItem;
            parentsList.add(lastParent);
        }
    }
    parentsList.clear();
}
Also used : ForumItemTree(forpdateam.ru.forpda.api.forum.models.ForumItemTree) ArrayList(java.util.ArrayList) IForumItemFlat(forpdateam.ru.forpda.api.forum.interfaces.IForumItemFlat)

Example 4 with ForumItemTree

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

the class ForumFragment method transformToList.

public void transformToList(List<ForumItemFlatBd> list, ForumItemTree rootForum) {
    if (rootForum.getForums() == null)
        return;
    for (ForumItemTree item : rootForum.getForums()) {
        list.add(new ForumItemFlatBd(item));
        transformToList(list, item);
    }
}
Also used : ForumItemTree(forpdateam.ru.forpda.api.forum.models.ForumItemTree) ForumItemFlatBd(forpdateam.ru.forpda.data.realm.forum.ForumItemFlatBd)

Example 5 with ForumItemTree

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

the class ForumFragment method bindView.

private void bindView() {
    // adapter.addAll(results);
    ForumItemTree rootForum = new ForumItemTree();
    Api.Forum().transformToTree(results, rootForum);
    tView = new AndroidTreeView(getContext());
    root = TreeNode.root();
    recourse(rootForum, root);
    tView.setRoot(root);
    tView.setDefaultContainerStyle(R.style.TreeNodeStyleCustom);
    tView.setDefaultViewHolder(DefaultForumHolder.class);
    tView.setDefaultNodeClickListener(nodeClickListener);
    tView.setDefaultNodeLongClickListener(nodeLongClickListener);
    treeContainer.removeAllViews();
    treeContainer.addView(tView.getView());
    // int id = 269;
    if (forumId != -1) {
        scrollToForum(forumId);
        forumId = -1;
    }
}
Also used : ForumItemTree(forpdateam.ru.forpda.api.forum.models.ForumItemTree) AndroidTreeView(com.unnamed.b.atv.view.AndroidTreeView)

Aggregations

ForumItemTree (forpdateam.ru.forpda.api.forum.models.ForumItemTree)7 IForumItemFlat (forpdateam.ru.forpda.api.forum.interfaces.IForumItemFlat)2 ArrayList (java.util.ArrayList)2 AlertDialog (android.support.v7.app.AlertDialog)1 TreeNode (com.unnamed.b.atv.model.TreeNode)1 AndroidTreeView (com.unnamed.b.atv.view.AndroidTreeView)1 NetworkResponse (forpdateam.ru.forpda.api.NetworkResponse)1 ForumItemFlat (forpdateam.ru.forpda.api.forum.models.ForumItemFlat)1 ForumItemFlatBd (forpdateam.ru.forpda.data.realm.forum.ForumItemFlatBd)1 Matcher (java.util.regex.Matcher)1