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