use of io.realm.RealmList in project realm-rxjava-example by kboyarshinov.
the class RealmDataService method newIssue.
@Override
public Observable<Issue> newIssue(final String title, final String body, final User user, List<Label> labels) {
// map internal UI objects to Realm objects
final RealmUser realmUser = new RealmUser();
realmUser.setLogin(user.getLogin());
final RealmList<RealmLabel> realmLabels = new RealmList<>();
for (Label label : labels) {
RealmLabel realmLabel = new RealmLabel();
realmLabel.setName(label.getName());
realmLabel.setColor(label.getColor());
realmLabels.add(realmLabel);
}
return RealmObservable.object(context, new Func1<Realm, RealmIssue>() {
@Override
public RealmIssue call(Realm realm) {
// internal object instances are not created by realm
// saving them using copyToRealm returning instance associated with realm
RealmUser user = realm.copyToRealm(realmUser);
RealmList<RealmLabel> labels = new RealmList<RealmLabel>();
for (RealmLabel realmLabel : realmLabels) {
labels.add(realm.copyToRealm(realmLabel));
}
// create RealmIssue instance and save it
RealmIssue issue = new RealmIssue();
issue.setTitle(title);
issue.setBody(body);
issue.setUser(user);
issue.setLabels(labels);
return realm.copyToRealm(issue);
}
}).map(new Func1<RealmIssue, Issue>() {
@Override
public Issue call(RealmIssue realmIssue) {
// map to UI object
return issueFromRealm(realmIssue);
}
});
}
use of io.realm.RealmList in project realm-java by realm.
the class RealmListNYTimesMultimediumDeserializer method deserialize.
@Override
public List<NYTimesMultimedium> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
RealmList<NYTimesMultimedium> list = new RealmList<>();
TreeNode treeNode = jp.getCodec().readTree(jp);
if (!(treeNode instanceof ArrayNode)) {
return list;
}
ArrayNode arrayNode = (ArrayNode) treeNode;
for (JsonNode node : arrayNode) {
NYTimesMultimedium nyTimesMultimedium = objectMapper.treeToValue(node, NYTimesMultimedium.class);
list.add(nyTimesMultimedium);
}
return list;
}
use of io.realm.RealmList 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 io.realm.RealmList in project app by TourLive.
the class JudgmentRiderConnectionRepository method getJudgmentRiderConnectionsReturnedByJudgment.
@Override
public RealmList<JudgmentRiderConnection> getJudgmentRiderConnectionsReturnedByJudgment(Judgement judgement) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
RealmResults<JudgmentRiderConnection> res = realm.where(JudgmentRiderConnection.class).equalTo("judgements.id", judgement.getId()).findAll();
RealmList<JudgmentRiderConnection> resList = new RealmList<>();
resList.addAll(res);
return resList;
}
use of io.realm.RealmList in project app by TourLive.
the class MaillotRepository method getAllMaillots.
@Override
public void getAllMaillots(OnGetAllMaillotsCallback callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
RealmResults<Maillot> results = realm.where(Maillot.class).findAll();
RealmList<Maillot> res = new RealmList<>();
res.addAll(results);
if (callback != null) {
callback.onSuccess(res);
}
}
Aggregations