Search in sources :

Example 1 with PatreonGoalRealm

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

the class PatreonManager method patreonRealmToDTO.

private XabberComClient.Patreon patreonRealmToDTO(PatreonRealm realmItem) {
    List<XabberComClient.PatreonGoal> patreonGoals = new ArrayList<>();
    for (PatreonGoalRealm patreonGoalRealm : realmItem.getGoals()) {
        XabberComClient.PatreonGoal patreonGoal = new XabberComClient.PatreonGoal(patreonGoalRealm.getTitle(), patreonGoalRealm.getGoal());
        patreonGoals.add(patreonGoal);
    }
    return new XabberComClient.Patreon(realmItem.getString(), realmItem.getPledged(), patreonGoals);
}
Also used : PatreonGoalRealm(com.xabber.android.data.database.realm.PatreonGoalRealm) ArrayList(java.util.ArrayList)

Example 2 with PatreonGoalRealm

use of com.xabber.android.data.database.realm.PatreonGoalRealm 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)1 Realm (io.realm.Realm)1 RealmList (io.realm.RealmList)1 ArrayList (java.util.ArrayList)1