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;
}
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);
}
Aggregations