Search in sources :

Example 6 with NetworkResponse

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);
}
Also used : NetworkRequest(forpdateam.ru.forpda.api.NetworkRequest) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse)

Example 7 with NetworkResponse

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;
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) NetworkRequest(forpdateam.ru.forpda.api.NetworkRequest) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) QmsMessage(forpdateam.ru.forpda.api.qms.models.QmsMessage)

Example 8 with NetworkResponse

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;
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) NetworkRequest(forpdateam.ru.forpda.api.NetworkRequest) QmsContact(forpdateam.ru.forpda.api.qms.models.QmsContact)

Example 9 with NetworkResponse

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());
}
Also used : NetworkRequest(forpdateam.ru.forpda.api.NetworkRequest) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse)

Example 10 with NetworkResponse

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

Aggregations

NetworkResponse (forpdateam.ru.forpda.api.NetworkResponse)44 Matcher (java.util.regex.Matcher)27 NetworkRequest (forpdateam.ru.forpda.api.NetworkRequest)25 ArrayList (java.util.ArrayList)8 AttachmentItem (forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)6 Bundle (android.os.Bundle)3 RequestFile (forpdateam.ru.forpda.api.RequestFile)3 Context (android.content.Context)2 Uri (android.net.Uri)2 App (forpdateam.ru.forpda.App)2 R (forpdateam.ru.forpda.R)2 QmsMessage (forpdateam.ru.forpda.api.qms.models.QmsMessage)2 Client (forpdateam.ru.forpda.client.Client)2 Observable (io.reactivex.Observable)2 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)2 Schedulers (io.reactivex.schedulers.Schedulers)2 Activity (android.app.Activity)1 DownloadManager (android.app.DownloadManager)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1