Search in sources :

Example 1 with SyncStateRealm

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];
}
Also used : SyncStateRealm(com.xabber.android.data.database.realm.SyncStateRealm) EmailRealm(com.xabber.android.data.database.realm.EmailRealm) SyncStateRealm(com.xabber.android.data.database.realm.SyncStateRealm) SocialBindingRealm(com.xabber.android.data.database.realm.SocialBindingRealm) Realm(io.realm.Realm) XabberAccountRealm(com.xabber.android.data.database.realm.XabberAccountRealm) XMPPUserRealm(com.xabber.android.data.database.realm.XMPPUserRealm)

Example 2 with SyncStateRealm

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");
}
Also used : RealmList(io.realm.RealmList) SyncStateRealm(com.xabber.android.data.database.realm.SyncStateRealm) HashMap(java.util.HashMap) Map(java.util.Map) EmailRealm(com.xabber.android.data.database.realm.EmailRealm) SyncStateRealm(com.xabber.android.data.database.realm.SyncStateRealm) SocialBindingRealm(com.xabber.android.data.database.realm.SocialBindingRealm) Realm(io.realm.Realm) XabberAccountRealm(com.xabber.android.data.database.realm.XabberAccountRealm) XMPPUserRealm(com.xabber.android.data.database.realm.XMPPUserRealm)

Example 3 with SyncStateRealm

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;
}
Also used : HashMap(java.util.HashMap) SyncStateRealm(com.xabber.android.data.database.realm.SyncStateRealm) EmailRealm(com.xabber.android.data.database.realm.EmailRealm) SyncStateRealm(com.xabber.android.data.database.realm.SyncStateRealm) SocialBindingRealm(com.xabber.android.data.database.realm.SocialBindingRealm) Realm(io.realm.Realm) XabberAccountRealm(com.xabber.android.data.database.realm.XabberAccountRealm) XMPPUserRealm(com.xabber.android.data.database.realm.XMPPUserRealm)

Aggregations

EmailRealm (com.xabber.android.data.database.realm.EmailRealm)3 SocialBindingRealm (com.xabber.android.data.database.realm.SocialBindingRealm)3 SyncStateRealm (com.xabber.android.data.database.realm.SyncStateRealm)3 XMPPUserRealm (com.xabber.android.data.database.realm.XMPPUserRealm)3 XabberAccountRealm (com.xabber.android.data.database.realm.XabberAccountRealm)3 Realm (io.realm.Realm)3 HashMap (java.util.HashMap)2 RealmList (io.realm.RealmList)1 Map (java.util.Map)1