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);
}
}
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;
}
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();
}
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);
}
}
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;
}
}
Aggregations