use of io.realm.RealmList in project app by TourLive.
the class Parser method createDefaultGroup.
private static Thread createDefaultGroup() {
Runnable runnable = (() -> {
try {
RaceGroup raceGroupField = new RaceGroup();
raceGroupField.setActualGapTime(0);
raceGroupField.setHistoryGapTime(0);
raceGroupField.setPosition(1);
raceGroupField.setType(RaceGroupType.FELD);
RealmList<Rider> activeRiders = new RealmList<>();
for (Rider r : Context.getAllRiders()) {
if (r.getRiderStages().first().getType() == RiderStateType.AKTIVE) {
activeRiders.add(r);
}
}
raceGroupField.setRiders(activeRiders);
Context.addRaceGroup(raceGroupField);
} catch (Exception e) {
Log.d(Parser.class.getSimpleName(), "APP - PARSER - RACEGROUP - " + e.getMessage());
}
});
return new Thread(runnable);
}
use of io.realm.RealmList in project app by TourLive.
the class JudgmentRepository method getAllJudgments.
@Override
public void getAllJudgments(OnGetAllJudgmentCallback callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
RealmResults<Judgement> results = realm.where(Judgement.class).findAll();
RealmList<Judgement> res = new RealmList<>();
res.addAll(results);
if (callback != null) {
callback.onSuccess(res);
}
}
use of io.realm.RealmList in project app by TourLive.
the class JudgmentRepository method getJudgmentsById.
@Override
public RealmList<Judgement> getJudgmentsById(final int judgmentId) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
RealmList<Judgement> results = new RealmList<>();
RealmResults<Judgement> judgments = realm.where(Judgement.class).findAll();
for (Judgement j : judgments) {
if (j.getRewardId() == judgmentId) {
results.add(j);
}
}
return results;
}
use of io.realm.RealmList in project app by TourLive.
the class JudgmentDetailFragment method saveJudgmnet.
public void saveJudgmnet() {
Rider rider = riderBasicAdapter.getSelectedRider();
if (rank != 0) {
JudgmentRiderConnection judgmentRiderConnection = new JudgmentRiderConnection();
judgmentRiderConnection.setRank(rank);
RealmList<Rider> riderToAdd = new RealmList<>();
riderToAdd.add(rider);
judgmentRiderConnection.setRider(riderToAdd);
RealmList<Judgement> judgementToAdd = new RealmList<>();
judgementToAdd.add(judgement);
judgmentRiderConnection.setJudgements(judgementToAdd);
JudgmentRiderConnectionPresenter.getInstance().addJudgmentRiderConnection(judgmentRiderConnection);
updateRiderStateConnectionWithPerformance(rider, rank);
textViews.get(rank - 1).setText(String.valueOf(rider.getStartNr()));
riderBasicAdapter.setColorOnRider(rider.getStartNr());
} else {
Toast toast = Toast.makeText(getContext(), getResources().getString(R.string.judgment_text), Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 0);
toast.show();
Integer integer = rider.getRiderID();
riderBasicAdapter.removeRiderFromList(integer);
}
riderBasicAdapter.resetSelectedRider();
rank = 0;
}
use of io.realm.RealmList in project underlx by underlx.
the class Trip method persistConnectionPath.
public static String persistConnectionPath(Path path, String replaceTrip) {
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
RealmList<StationUse> uses = new RealmList<>();
List<Connection> edgeList = path.getEdgeList();
int size = edgeList.size();
if (size == 0) {
StationUse use = new StationUse();
use.setType(StationUse.UseType.VISIT);
use.setStation(realm.where(RStation.class).equalTo("id", path.getStartVertex().getStation().getId()).findFirst());
use.setEntryDate(path.getEntryExitTimes(0).first);
use.setLeaveDate(path.getEntryExitTimes(0).second);
use.setManualEntry(path.getManualEntry(0));
uses.add(realm.copyToRealm(use));
} else if (size == 1 && edgeList.get(0) instanceof Transfer) {
Connection c = edgeList.get(0);
StationUse use = new StationUse();
use.setType(StationUse.UseType.VISIT);
use.setSourceLine(c.getSource().getLine().getId());
use.setTargetLine(c.getTarget().getLine().getId());
use.setEntryDate(path.getEntryExitTimes(0).first);
use.setLeaveDate(path.getEntryExitTimes(0).second);
use.setManualEntry(path.getManualEntry(0));
use.setStation(realm.where(RStation.class).equalTo("id", c.getSource().getStation().getId()).findFirst());
uses.add(realm.copyToRealm(use));
} else {
int timeIdx = 0;
StationUse startUse = new StationUse();
startUse.setType(StationUse.UseType.NETWORK_ENTRY);
startUse.setStation(realm.where(RStation.class).equalTo("id", path.getStartVertex().getStation().getId()).findFirst());
startUse.setEntryDate(path.getEntryExitTimes(timeIdx).first);
startUse.setLeaveDate(path.getEntryExitTimes(timeIdx).second);
startUse.setManualEntry(path.getManualEntry(timeIdx));
uses.add(realm.copyToRealm(startUse));
int i = 1;
timeIdx++;
if (edgeList.get(0) instanceof Transfer) {
i = 2;
timeIdx++;
}
for (; i < size; i++) {
Connection c = edgeList.get(i);
StationUse use = new StationUse();
if (c instanceof Transfer) {
if (i == size - 1)
break;
use.setType(StationUse.UseType.INTERCHANGE);
use.setSourceLine(c.getSource().getLine().getId());
use.setTargetLine(c.getTarget().getLine().getId());
use.setEntryDate(path.getEntryExitTimes(timeIdx).first);
timeIdx++;
use.setLeaveDate(path.getEntryExitTimes(timeIdx).second);
use.setManualEntry(path.getManualEntry(timeIdx));
timeIdx++;
// skip next station as then we'd have duplicate uses for the same station ID
i++;
} else {
use.setType(StationUse.UseType.GONE_THROUGH);
use.setEntryDate(path.getEntryExitTimes(timeIdx).first);
use.setLeaveDate(path.getEntryExitTimes(timeIdx).second);
use.setManualEntry(path.getManualEntry(timeIdx));
timeIdx++;
}
use.setStation(realm.where(RStation.class).equalTo("id", c.getSource().getStation().getId()).findFirst());
uses.add(realm.copyToRealm(use));
}
StationUse endUse = new StationUse();
endUse.setType(StationUse.UseType.NETWORK_EXIT);
endUse.setStation(realm.where(RStation.class).equalTo("id", path.getEndVertex().getStation().getId()).findFirst());
endUse.setEntryDate(path.getEntryExitTimes(timeIdx).first);
endUse.setLeaveDate(path.getEntryExitTimes(timeIdx).second);
endUse.setManualEntry(path.getManualEntry(timeIdx));
uses.add(realm.copyToRealm(endUse));
}
Trip trip;
if (replaceTrip != null) {
trip = realm.where(Trip.class).equalTo("id", replaceTrip).findFirst();
trip.getPath().deleteAllFromRealm();
trip.setUserConfirmed(true);
trip.setSynced(false);
} else {
trip = realm.createObject(Trip.class, UUID.randomUUID().toString());
trip.setUserConfirmed(false);
}
trip.setPath(uses);
String tripId = trip.getId();
realm.commitTransaction();
realm.close();
return tripId;
}
Aggregations