use of forpdateam.ru.forpda.data.realm.qms.QmsContactBd 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.data.realm.qms.QmsContactBd in project ForPDA by RadiationX.
the class QmsHelper method handleEvent.
private void handleEvent(TabNotification event) {
Realm realm = Realm.getDefaultInstance();
RealmResults<QmsThemesBd> themes = realm.where(QmsThemesBd.class).findAll();
QmsThemeBd targetTheme = null;
QmsThemesBd targetDialog = null;
for (QmsThemesBd dialog : themes) {
for (QmsThemeBd theme : dialog.getThemes()) {
if (theme.getId() == event.getEvent().getSourceId()) {
targetDialog = dialog;
targetTheme = theme;
break;
}
}
if (targetTheme != null) {
break;
}
}
if (targetTheme != null) {
QmsThemeBd finalTargetTheme = targetTheme;
QmsThemesBd finalTargetDialog = targetDialog;
realm.executeTransaction(realm1 -> {
if (event.isWebSocket()) {
if (NotificationEvent.isRead(event.getType())) {
finalTargetTheme.setCountNew(0);
}
} else {
if (NotificationEvent.isNew(event.getType())) {
finalTargetTheme.setCountNew(event.getEvent().getMsgCount());
}
}
QmsContactBd contact = realm1.where(QmsContactBd.class).equalTo("id", finalTargetDialog.getUserId()).findFirst();
if (contact != null) {
int count = 0;
for (QmsThemeBd theme : finalTargetDialog.getThemes()) {
count += theme.getCountNew();
}
contact.setCount(count);
}
});
}
int globalCount = 0;
for (NotificationEvent ev : event.getLoadedEvents()) {
globalCount += ev.getMsgCount();
}
ClientHelper.setQmsCount(globalCount);
ClientHelper.get().notifyCountsChanged();
realm.close();
notifyQms(event);
}
use of forpdateam.ru.forpda.data.realm.qms.QmsContactBd 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);
}
use of forpdateam.ru.forpda.data.realm.qms.QmsContactBd in project ForPDA by RadiationX.
the class QmsContactsFragment method addBaseToolbarMenu.
@Override
protected void addBaseToolbarMenu(Menu menu) {
super.addBaseToolbarMenu(menu);
toolbar.inflateMenu(R.menu.qms_contacts_menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) searchItem.getActionView();
SearchManager searchManager = (SearchManager) getMainActivity().getSystemService(Context.SEARCH_SERVICE);
if (null != searchManager) {
searchView.setSearchableInfo(searchManager.getSearchableInfo(getMainActivity().getComponentName()));
}
searchView.setIconifiedByDefault(true);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
private ArrayList<QmsContactBd> searchContacts = new ArrayList<>();
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
searchContacts.clear();
if (!newText.isEmpty()) {
for (QmsContactBd contact : results) {
if (contact.getNick().toLowerCase().contains(newText.toLowerCase()))
searchContacts.add(contact);
}
adapter.addAll(searchContacts);
} else {
adapter.addAll(results);
}
return false;
}
});
searchView.setQueryHint(getString(R.string.user));
menu.add(R.string.blacklist).setOnMenuItemClickListener(item -> {
TabManager.get().add(QmsBlackListFragment.class);
return false;
});
}
use of forpdateam.ru.forpda.data.realm.qms.QmsContactBd in project ForPDA by RadiationX.
the class QmsContactsFragment method bindView.
private void bindView() {
if (realm.isClosed())
return;
results = realm.where(QmsContactBd.class).findAll();
if (results.isEmpty()) {
if (!contentController.contains(ContentController.TAG_NO_DATA)) {
FunnyContent funnyContent = new FunnyContent(getContext()).setImage(R.drawable.ic_contacts).setTitle(R.string.funny_contacts_nodata_title);
contentController.addContent(funnyContent, ContentController.TAG_NO_DATA);
}
contentController.showContent(ContentController.TAG_NO_DATA);
} else {
contentController.hideContent(ContentController.TAG_NO_DATA);
}
ArrayList<QmsContact> currentItems = new ArrayList<>();
for (QmsContactBd qmsContactBd : results) {
QmsContact contact = new QmsContact(qmsContactBd);
currentItems.add(contact);
}
int count = 0;
for (QmsContact contact : currentItems) {
if (contact.getCount() > 0) {
count += contact.getCount();
}
}
ClientHelper.setQmsCount(count);
ClientHelper.get().notifyCountsChanged();
adapter.addAll(currentItems);
}
Aggregations