use of com.xabber.android.data.database.realm.SyncStateRealm in project xabber-android by redsolution.
the class XabberAccountManager method deleteSyncStatesFromRealm.
public boolean deleteSyncStatesFromRealm() {
final boolean[] success = new boolean[1];
Realm realm = RealmManager.getInstance().getNewBackgroundRealm();
final RealmResults<SyncStateRealm> results = realm.where(SyncStateRealm.class).findAll();
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
success[0] = results.deleteAllFromRealm();
}
});
realm.close();
return success[0];
}
use of com.xabber.android.data.database.realm.SyncStateRealm in project xabber-android by redsolution.
the class XabberAccountManager method saveSyncStatesToRealm.
public void saveSyncStatesToRealm(Map<String, Boolean> syncStateMap) {
RealmList<SyncStateRealm> realmItems = new RealmList<>();
for (Map.Entry<String, Boolean> entry : syncStateMap.entrySet()) {
SyncStateRealm realmItem = new SyncStateRealm();
realmItem.setJid(entry.getKey());
realmItem.setSync(entry.getValue());
realmItems.add(realmItem);
}
// TODO: 13.03.18 ANR - WRITE
final long startTime = System.currentTimeMillis();
Realm realm = RealmManager.getInstance().getNewRealm();
realm.beginTransaction();
List<SyncStateRealm> oldItems = realm.where(SyncStateRealm.class).findAll();
for (SyncStateRealm item : oldItems) item.deleteFromRealm();
List<SyncStateRealm> resultRealm = realm.copyToRealmOrUpdate(realmItems);
realm.commitTransaction();
realm.close();
LogManager.d("REALM", Thread.currentThread().getName() + " save sync state: " + (System.currentTimeMillis() - startTime));
Log.d(LOG_TAG, resultRealm.size() + " syncState items was saved to Realm");
}
use of com.xabber.android.data.database.realm.SyncStateRealm in project xabber-android by redsolution.
the class XabberAccountManager method loadSyncStatesFromRealm.
public Map<String, Boolean> loadSyncStatesFromRealm() {
Map<String, Boolean> resultMap = new HashMap<>();
Realm realm = RealmManager.getInstance().getNewBackgroundRealm();
RealmResults<SyncStateRealm> realmItems = realm.where(SyncStateRealm.class).findAll();
for (SyncStateRealm realmItem : realmItems) {
resultMap.put(realmItem.getJid(), realmItem.isSync());
}
realm.close();
return resultMap;
}
Aggregations