use of io.realm.RealmList in project app by TourLive.
the class RaceGroupRepository method updateRaceGroupRiders.
public void updateRaceGroupRiders(RaceGroup raceGroup, final RealmList<Rider> newRiders, OnUpdateRaceGroupCallBack callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
RiderRepository riderRepository = new RiderRepository();
RealmList<Rider> riders = new RealmList<>();
riders.addAll(newRiders);
realm.beginTransaction();
RaceGroup realmRemoveGroup = realm.where(RaceGroup.class).equalTo("riders.id", newRiders.get(0).getId()).findFirst();
if (realmRemoveGroup != null) {
for (Rider r : riders) {
realmRemoveGroup.removeRider(r);
}
}
realm.commitTransaction();
if (raceGroup.getType() == RaceGroupType.FELD) {
Iterator<Rider> iterator = riders.iterator();
while (iterator.hasNext()) {
Rider r = iterator.next();
if (r.isUnknown()) {
riderRepository.removeRider(r, null);
iterator.remove();
}
}
}
realm.beginTransaction();
RaceGroup realmRaceGroup = realm.where(RaceGroup.class).equalTo("type", raceGroup.getType().toString()).equalTo("position", raceGroup.getPosition()).findFirst();
if (!riders.isEmpty())
realmRaceGroup.appendRiders(riders);
realm.commitTransaction();
if (realmRemoveGroup != null && realmRemoveGroup.getRiders().isEmpty()) {
deleteRaceGroup(realmRemoveGroup);
}
if (callback != null) {
callback.onSuccess(realmRaceGroup);
}
}
use of io.realm.RealmList in project app by TourLive.
the class RaceGroupRepository method addRaceGroup.
@Override
public void addRaceGroup(RaceGroup raceGroup, OnSaveRaceGroupCallback callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
realm.beginTransaction();
RealmResults<RaceGroup> rGtoUpdate = realm.where(RaceGroup.class).greaterThanOrEqualTo("position", raceGroup.getPosition()).findAllSorted("position");
for (RaceGroup rG : rGtoUpdate) {
rG.setPosition(rG.getPosition() + 1);
rG.setActualGapTime(rG.getActualGapTime() + 1);
if (rG.getType() == RaceGroupType.LEAD) {
rG.setType(RaceGroupType.NORMAL);
}
}
realm.commitTransaction();
for (Rider r : raceGroup.getRiders()) {
RealmResults<RaceGroup> resRG = realm.where(RaceGroup.class).equalTo("riders.id", r.getId()).findAll();
if (!resRG.isEmpty()) {
Iterator<RaceGroup> iterator = resRG.iterator();
while (iterator.hasNext()) {
RaceGroup rG = iterator.next();
realm.beginTransaction();
rG.removeRider(r);
realm.commitTransaction();
if (rG.getRiders().isEmpty())
deleteRaceGroup(rG);
}
}
}
realm.beginTransaction();
RaceGroup realmRaceGroup = realm.createObject(RaceGroup.class, UUID.randomUUID().toString());
realmRaceGroup.setType(raceGroup.getType());
realmRaceGroup.setActualGapTime(raceGroup.getActualGapTime());
realmRaceGroup.setHistoryGapTime(0);
realmRaceGroup.setPosition(raceGroup.getPosition());
RealmList<Rider> res = new RealmList<>();
for (Rider r : raceGroup.getRiders()) {
RealmResults<Rider> temp = realm.where(Rider.class).equalTo("startNr", r.getStartNr()).findAll();
res.addAll(temp);
}
realmRaceGroup.setRiders(res);
realm.commitTransaction();
if (callback != null) {
callback.onSuccess(realmRaceGroup);
}
}
use of io.realm.RealmList in project app by TourLive.
the class RiderRepository method getAllUnknownRidersReturned.
@Override
public RealmList<Rider> getAllUnknownRidersReturned() {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
RealmResults<Rider> results = realm.where(Rider.class).equalTo("isUnknown", true).findAll().sort("startNr");
RealmList<Rider> res = new RealmList<>();
res.addAll(results);
return res;
}
use of io.realm.RealmList in project app by TourLive.
the class RiderStageConnectionRepository method getAllRiderStateConnections.
@Override
public RealmList<RiderStageConnection> getAllRiderStateConnections() {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
RealmResults<RiderStageConnection> res = realm.where(RiderStageConnection.class).findAll();
RealmList<RiderStageConnection> resList = new RealmList<>();
resList.addAll(res);
return resList;
}
use of io.realm.RealmList in project app by TourLive.
the class RiderStageConnectionRepository method getRiderStageConnections.
@Override
public void getRiderStageConnections(OnGetAllRiderStageConnectionsCallback callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
RealmResults<RiderStageConnection> results = realm.where(RiderStageConnection.class).findAll();
RealmList<RiderStageConnection> res = new RealmList<>();
res.addAll(results);
if (callback != null) {
callback.onSuccess(res);
}
}
Aggregations