Search in sources :

Example 1 with PatreonRealm

use of com.xabber.android.data.database.realm.PatreonRealm in project xabber-android by redsolution.

the class PatreonManager method loadPatreonFromRealm.

@Nullable
private XabberComClient.Patreon loadPatreonFromRealm() {
    XabberComClient.Patreon patreon = null;
    Realm realm = RealmManager.getInstance().getNewRealm();
    RealmResults<PatreonRealm> patreonRealms = realm.where(PatreonRealm.class).findAll();
    if (patreonRealms.size() > 0)
        patreon = patreonRealmToDTO(patreonRealms.get(0));
    realm.close();
    return patreon;
}
Also used : PatreonRealm(com.xabber.android.data.database.realm.PatreonRealm) Realm(io.realm.Realm) PatreonRealm(com.xabber.android.data.database.realm.PatreonRealm) PatreonGoalRealm(com.xabber.android.data.database.realm.PatreonGoalRealm) Nullable(android.support.annotation.Nullable)

Example 2 with PatreonRealm

use of com.xabber.android.data.database.realm.PatreonRealm in project xabber-android by redsolution.

the class PatreonManager method savePatreonToRealm.

public Single<XabberComClient.Patreon> savePatreonToRealm(XabberComClient.Patreon patreon) {
    RealmList<PatreonGoalRealm> patreonGoals = new RealmList<>();
    for (XabberComClient.PatreonGoal patreonGoal : patreon.getGoals()) {
        PatreonGoalRealm patreonGoalRealm = new PatreonGoalRealm();
        patreonGoalRealm.setGoal(patreonGoal.getGoal());
        patreonGoalRealm.setTitle(patreonGoal.getTitle());
        patreonGoals.add(patreonGoalRealm);
    }
    PatreonRealm patreonRealm = new PatreonRealm("1");
    patreonRealm.setPledged(patreon.getPledged());
    patreonRealm.setString(patreon.getString());
    patreonRealm.setGoals(patreonGoals);
    // TODO: 13.03.18 ANR - WRITE
    final long startTime = System.currentTimeMillis();
    Realm realm = RealmManager.getInstance().getNewRealm();
    realm.beginTransaction();
    PatreonRealm resultRealm = realm.copyToRealmOrUpdate(patreonRealm);
    realm.commitTransaction();
    XabberComClient.Patreon result = patreonRealmToDTO(resultRealm);
    realm.close();
    LogManager.d("REALM", Thread.currentThread().getName() + " save patreon data: " + (System.currentTimeMillis() - startTime));
    Log.d(LOG_TAG, "Patreon was saved to Realm");
    return Single.just(result);
}
Also used : PatreonGoalRealm(com.xabber.android.data.database.realm.PatreonGoalRealm) RealmList(io.realm.RealmList) PatreonRealm(com.xabber.android.data.database.realm.PatreonRealm) Realm(io.realm.Realm) PatreonRealm(com.xabber.android.data.database.realm.PatreonRealm) PatreonGoalRealm(com.xabber.android.data.database.realm.PatreonGoalRealm)

Aggregations

PatreonGoalRealm (com.xabber.android.data.database.realm.PatreonGoalRealm)2 PatreonRealm (com.xabber.android.data.database.realm.PatreonRealm)2 Realm (io.realm.Realm)2 Nullable (android.support.annotation.Nullable)1 RealmList (io.realm.RealmList)1