use of forpdateam.ru.forpda.api.qms.models.QmsTheme in project ForPDA by RadiationX.
the class Qms method parseThemes.
private QmsThemes parseThemes(String response, int id) {
QmsThemes qmsThemes = new QmsThemes();
Matcher matcher = threadPattern.matcher(response);
while (matcher.find()) {
QmsTheme thread = new QmsTheme();
thread.setId(Integer.parseInt(matcher.group(1)));
thread.setDate(matcher.group(2));
thread.setName(ApiUtils.fromHtml(matcher.group(3).trim()));
thread.setCountMessages(Integer.parseInt(matcher.group(4)));
String countNew = matcher.group(5);
thread.setCountNew(countNew == null || countNew.isEmpty() ? 0 : Integer.parseInt(countNew));
qmsThemes.addTheme(thread);
}
matcher = threadNickPattern.matcher(response);
if (matcher.find()) {
qmsThemes.setNick(ApiUtils.fromHtml(matcher.group(1)));
}
qmsThemes.setUserId(id);
return qmsThemes;
}
use of forpdateam.ru.forpda.api.qms.models.QmsTheme in project ForPDA by RadiationX.
the class QmsThemesFragment method bindView.
private void bindView() {
if (realm.isClosed())
return;
refreshToolbarMenuItems(true);
RealmResults<QmsThemesBd> results = realm.where(QmsThemesBd.class).equalTo("userId", currentThemes.getUserId()).findAll();
QmsThemesBd qmsThemesBd = results.last(null);
if (qmsThemesBd == null) {
return;
}
ArrayList<QmsTheme> currentItems = new ArrayList<>();
for (QmsThemeBd qmsThemeBd : qmsThemesBd.getThemes()) {
QmsTheme qmsTheme = new QmsTheme(qmsThemeBd);
currentItems.add(qmsTheme);
}
adapter.addAll(currentItems);
adapter.notifyDataSetChanged();
}
use of forpdateam.ru.forpda.api.qms.models.QmsTheme in project ForPDA by RadiationX.
the class QmsThemesFragment method handleEvent.
private void handleEvent(TabNotification event) {
if (realm.isClosed())
return;
bindView();
if (true)
return;
RealmResults<QmsThemesBd> results = realm.where(QmsThemesBd.class).equalTo("userId", currentThemes.getUserId()).findAll();
QmsThemesBd qmsThemesBdLast = results.last(null);
if (qmsThemesBdLast == null) {
return;
}
ArrayList<QmsTheme> currentItems = new ArrayList<>();
for (QmsThemeBd qmsThemeBd : qmsThemesBdLast.getThemes()) {
QmsTheme qmsTheme = new QmsTheme(qmsThemeBd);
currentItems.add(qmsTheme);
}
if (event.getType() == NotificationEvent.Type.READ) {
for (QmsTheme item : currentItems) {
if (item.getId() == event.getEvent().getSourceId()) {
item.setCountNew(0);
break;
}
}
} else {
SparseIntArray sparseArray = new SparseIntArray();
for (NotificationEvent loadedEvent : event.getLoadedEvents()) {
int count = sparseArray.get(loadedEvent.getSourceId());
count += loadedEvent.getMsgCount();
sparseArray.put(loadedEvent.getSourceId(), count);
}
for (int i = sparseArray.size() - 1; i >= 0; i--) {
int id = sparseArray.keyAt(i);
int count = sparseArray.valueAt(i);
for (QmsTheme item : currentItems) {
if (item.getId() == id) {
item.setCountMessages(item.getCountMessages() + count);
item.setCountNew(count);
Collections.swap(currentItems, currentItems.indexOf(item), 0);
break;
}
}
}
}
QmsContactsFragment contactsFragment = (QmsContactsFragment) TabManager.get().getByClass(QmsContactsFragment.class);
if (contactsFragment != null) {
int count = 0;
for (QmsTheme qmsTheme : currentItems) {
count += qmsTheme.getCountNew();
}
contactsFragment.updateCount(currentThemes.getUserId(), count);
}
if (realm.isClosed())
return;
realm.executeTransactionAsync(r -> {
r.where(QmsThemesBd.class).equalTo("userId", currentThemes.getUserId()).findAll().deleteAllFromRealm();
currentThemes.getThemes().clear();
currentThemes.getThemes().addAll(currentItems);
QmsThemesBd qmsThemesBd = new QmsThemesBd(currentThemes);
r.copyToRealmOrUpdate(qmsThemesBd);
qmsThemesBd.getThemes().clear();
}, this::bindView);
}
Aggregations