Search in sources :

Example 1 with QmsContact

use of forpdateam.ru.forpda.api.qms.models.QmsContact in project ForPDA by RadiationX.

the class Qms method parseBlackList.

private ArrayList<QmsContact> parseBlackList(String response) {
    ArrayList<QmsContact> list = new ArrayList<>();
    Matcher matcher = blackListPattern.matcher(response);
    while (matcher.find()) {
        QmsContact contact = new QmsContact();
        contact.setId(Integer.parseInt(matcher.group(1)));
        contact.setAvatar(matcher.group(2));
        contact.setNick(ApiUtils.fromHtml(matcher.group(3)));
        list.add(contact);
    }
    return list;
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) QmsContact(forpdateam.ru.forpda.api.qms.models.QmsContact)

Example 2 with QmsContact

use of forpdateam.ru.forpda.api.qms.models.QmsContact 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 3 with QmsContact

use of forpdateam.ru.forpda.api.qms.models.QmsContact in project ForPDA by RadiationX.

the class QmsContactsFragment method handleEvent.

private void handleEvent(TabNotification event) {
    bindView();
    if (true)
        return;
    SparseIntArray sparseArray = new SparseIntArray();
    if (realm.isClosed())
        return;
    results = realm.where(QmsContactBd.class).findAll();
    ArrayList<QmsContact> currentItems = new ArrayList<>();
    for (QmsContactBd qmsContactBd : results) {
        QmsContact contact = new QmsContact(qmsContactBd);
        currentItems.add(contact);
    }
    for (NotificationEvent loadedEvent : event.getLoadedEvents()) {
        int count = sparseArray.get(loadedEvent.getUserId());
        count += loadedEvent.getMsgCount();
        sparseArray.put(loadedEvent.getUserId(), count);
    }
    for (int i = sparseArray.size() - 1; i >= 0; i--) {
        int id = sparseArray.keyAt(i);
        int count = sparseArray.valueAt(i);
        for (QmsContact item : currentItems) {
            if (item.getId() == id) {
                item.setCount(count);
                Collections.swap(currentItems, currentItems.indexOf(item), 0);
                break;
            }
        }
    }
    if (realm.isClosed())
        return;
    realm.executeTransactionAsync(r -> {
        r.delete(QmsContactBd.class);
        List<QmsContactBd> bdList = new ArrayList<>();
        for (QmsContact qmsContact : currentItems) {
            bdList.add(new QmsContactBd(qmsContact));
        }
        r.copyToRealmOrUpdate(bdList);
        bdList.clear();
    }, this::bindView);
// adapter.notifyDataSetChanged();
/*ArrayList<IFavItem> newItems = new ArrayList<>();
        newItems.addAll(currentItems);
        refreshList(newItems);*/
}
Also used : SparseIntArray(android.util.SparseIntArray) ArrayList(java.util.ArrayList) NotificationEvent(forpdateam.ru.forpda.api.events.models.NotificationEvent) IQmsContact(forpdateam.ru.forpda.api.qms.interfaces.IQmsContact) QmsContact(forpdateam.ru.forpda.api.qms.models.QmsContact) QmsContactBd(forpdateam.ru.forpda.data.realm.qms.QmsContactBd)

Example 4 with QmsContact

use of forpdateam.ru.forpda.api.qms.models.QmsContact in project ForPDA by RadiationX.

the class QmsRx method interceptContacts.

public static ArrayList<QmsContact> interceptContacts(ArrayList<QmsContact> contacts) throws Exception {
    List<ForumUser> forumUsers = new ArrayList<>();
    for (QmsContact post : contacts) {
        ForumUser forumUser = new ForumUser();
        forumUser.setId(post.getId());
        forumUser.setNick(post.getNick());
        forumUser.setAvatar(post.getAvatar());
    }
    ForumUsersCache.saveUsers(forumUsers);
    return contacts;
}
Also used : ForumUser(forpdateam.ru.forpda.api.others.user.ForumUser) ArrayList(java.util.ArrayList) QmsContact(forpdateam.ru.forpda.api.qms.models.QmsContact)

Example 5 with QmsContact

use of forpdateam.ru.forpda.api.qms.models.QmsContact in project ForPDA by RadiationX.

the class QmsContactsFragment method onLoadContacts.

private void onLoadContacts(ArrayList<QmsContact> data) {
    setRefreshing(false);
    recyclerView.scrollToPosition(0);
    if (realm.isClosed())
        return;
    realm.executeTransactionAsync(r -> {
        r.delete(QmsContactBd.class);
        List<QmsContactBd> bdList = new ArrayList<>();
        for (QmsContact contact : data) {
            bdList.add(new QmsContactBd(contact));
        }
        r.copyToRealmOrUpdate(bdList);
        bdList.clear();
    }, this::bindView);
}
Also used : ArrayList(java.util.ArrayList) QmsContactBd(forpdateam.ru.forpda.data.realm.qms.QmsContactBd) IQmsContact(forpdateam.ru.forpda.api.qms.interfaces.IQmsContact) QmsContact(forpdateam.ru.forpda.api.qms.models.QmsContact)

Aggregations

QmsContact (forpdateam.ru.forpda.api.qms.models.QmsContact)6 ArrayList (java.util.ArrayList)6 IQmsContact (forpdateam.ru.forpda.api.qms.interfaces.IQmsContact)3 QmsContactBd (forpdateam.ru.forpda.data.realm.qms.QmsContactBd)3 Matcher (java.util.regex.Matcher)2 SparseIntArray (android.util.SparseIntArray)1 NetworkRequest (forpdateam.ru.forpda.api.NetworkRequest)1 NetworkResponse (forpdateam.ru.forpda.api.NetworkResponse)1 NotificationEvent (forpdateam.ru.forpda.api.events.models.NotificationEvent)1 ForumUser (forpdateam.ru.forpda.api.others.user.ForumUser)1 FunnyContent (forpdateam.ru.forpda.ui.views.FunnyContent)1