use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class Qms method deleteTheme.
public QmsThemes deleteTheme(int id, int themeId) throws Exception {
NetworkRequest.Builder builder = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php?act=qms&mid=" + id + "&xhr=body&do=1").formHeader("xhr", "body").formHeader("action", "delete-threads").formHeader("thread-id[" + themeId + "]", "" + themeId);
NetworkResponse response = Api.getWebClient().request(builder.build());
return parseThemes(response.getBody(), id);
}
use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class Qms method getMessagesAfter.
public ArrayList<QmsMessage> getMessagesAfter(int userId, int themeId, int afterMessageId) throws Exception {
ArrayList<QmsMessage> messages = new ArrayList<>();
NetworkRequest.Builder threadMessagesBuilder = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php?act=qms-xhr&").xhrHeader().formHeader("action", "get-thread-messages").formHeader("mid", Integer.toString(userId)).formHeader("t", Integer.toString(themeId)).formHeader("after-message", Integer.toString(afterMessageId));
NetworkResponse threadMessagesResponse = Api.getWebClient().request(threadMessagesBuilder.build());
Matcher matcher = chatPattern.matcher(threadMessagesResponse.getBody());
while (matcher.find()) {
QmsMessage item = new QmsMessage();
if (matcher.group(1) == null && matcher.group(7) != null) {
item.setIsDate(true);
item.setDate(matcher.group(7).trim());
} else {
item.setMyMessage(!matcher.group(1).isEmpty());
item.setId(Integer.parseInt(matcher.group(2)));
if (item.isMyMessage()) {
item.setReadStatus(!matcher.group(3).equals("1"));
} else {
item.setReadStatus(true);
}
item.setTime(matcher.group(4));
item.setAvatar(matcher.group(5));
item.setContent(matcher.group(6).trim());
}
messages.add(item);
}
return messages;
}
use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class Qms method getContactList.
public ArrayList<QmsContact> getContactList() throws Exception {
ArrayList<QmsContact> list = new ArrayList<>();
NetworkResponse response = Api.getWebClient().request(new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php?&act=qms-xhr&action=userlist").build());
final Matcher matcher = contactsPattern.matcher(response.getBody());
QmsContact contact;
String temp;
while (matcher.find()) {
contact = new QmsContact();
contact.setId(Integer.parseInt(matcher.group(1)));
temp = matcher.group(2);
contact.setCount(temp == null || temp.isEmpty() ? 0 : Integer.parseInt(temp));
contact.setAvatar(matcher.group(3));
contact.setNick(ApiUtils.fromHtml(matcher.group(4).trim()));
list.add(contact);
}
return list;
}
use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class Favorites method delete.
public boolean delete(int favId) throws Exception {
NetworkRequest.Builder builder = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php?act=fav").xhrHeader().formHeader("selectedtids", Integer.toString(favId)).formHeader("tact", "delete");
NetworkResponse response = Api.getWebClient().request(builder.build());
return checkIsComplete(response.getBody());
}
use of forpdateam.ru.forpda.api.NetworkResponse 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;
}
Aggregations