use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection in project app by TourLive.
the class JudgmentRiderConnectionRepository method removeOldJudgmentRiderConnections.
private void removeOldJudgmentRiderConnections(RealmResults<JudgmentRiderConnection> res) {
for (JudgmentRiderConnection jRc : res) {
int rank = jRc.getRank();
Judgement judgement = jRc.getJudgements().first();
Reward reward = judgement.getRewards();
RiderStageConnection riderStageConnection = jRc.getRider().first().getRiderStages().first();
if (reward.getType() == RewardType.POINTS) {
if (judgement.getName().toLowerCase().contains("sprint")) {
riderStageConnection.removeSprintBonusPoints(RiderStageConnectionUtilities.getPointsAtPosition(rank, reward));
riderStageConnection.removeBonusPoint(RiderStageConnectionUtilities.getPointsAtPosition(rank, reward));
} else if (judgement.getName().toLowerCase().contains("bergpreis")) {
riderStageConnection.removeMountainBonusPoints(RiderStageConnectionUtilities.getPointsAtPosition(rank, reward));
} else {
riderStageConnection.removeBonusPoint(RiderStageConnectionUtilities.getPointsAtPosition(rank, reward));
}
}
if (reward.getType() == RewardType.TIME) {
riderStageConnection.removeBonusTime(RiderStageConnectionUtilities.getPointsAtPosition(rank, reward));
}
riderStageConnection.removeMoney(RiderStageConnectionUtilities.getMoneyAtPosition(rank, reward));
jRc.deleteFromRealm();
}
}
use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection in project app by TourLive.
the class RiderStageConnectionRepository method appendTimeInLeadGroup.
@Override
public void appendTimeInLeadGroup(final RiderStageConnection riderStageConnection, int value) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
realm.executeTransaction((Realm db) -> {
RiderStageConnection res = db.where(RiderStageConnection.class).equalTo("id", riderStageConnection.getId()).findFirst();
res.appendTimeInLeadGroup(value);
List<RiderStageConnection> cons = realm.copyFromRealm(db.where(RiderStageConnection.class).findAll());
cons.sort(new RiderStageConnectionComparatorTimeInLead());
for (int i = 0; i < cons.size(); i++) {
db.where(RiderStageConnection.class).equalTo("id", cons.get(i).getId()).findFirst().getRiderRanking(RankingType.TIME_IN_LEAD).setRank(i + 1);
}
});
}
use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection in project app by TourLive.
the class RiderStageConnectionRepository method updateRiderStageConnectionReward.
@Override
public void updateRiderStageConnectionReward(final RiderStageConnection riderStageConnection, OnUpdateRiderStageConnectionCallBack callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
realm.executeTransaction((Realm db) -> {
RiderStageConnection res = db.where(RiderStageConnection.class).equalTo("id", riderStageConnection.getId()).findFirst();
res.appendBonusPoint(riderStageConnection.getBonusPoint());
res.appendBonusTime(riderStageConnection.getBonusTime());
res.appendMoney(riderStageConnection.getMoney());
res.appendMountainBonusPoints(riderStageConnection.getMountainBonusPoints());
res.appendSprintBonusPoints(riderStageConnection.getSprintBonusPoints());
});
realm.executeTransaction((Realm db) -> {
RealmResults<RiderStageConnection> connections = db.where(RiderStageConnection.class).findAll();
List<RiderStageConnection> cons = realm.copyFromRealm(connections);
cons.sort(new RiderStageConnectionComparatorPoints());
for (int i = 0; i < cons.size(); i++) {
db.where(RiderStageConnection.class).equalTo("id", cons.get(i).getId()).findFirst().getRiderRanking(RankingType.POINTS).setRank(i + 1);
}
if (riderStageConnection.getMountainBonusPoints() != 0) {
cons.sort(new RiderStageConnectionComparatorMountainPoints());
for (int i = 0; i < cons.size(); i++) {
db.where(RiderStageConnection.class).equalTo("id", cons.get(i).getId()).findFirst().getRiderRanking(RankingType.MOUNTAIN).setRank(i + 1);
}
}
if (riderStageConnection.getMoney() != 0) {
cons.sort(new RiderStageConnectionComparatorMoney());
for (int i = 0; i < cons.size(); i++) {
db.where(RiderStageConnection.class).equalTo("id", cons.get(i).getId()).findFirst().getRiderRanking(RankingType.MONEY).setRank(i + 1);
}
}
});
if (callback != null) {
callback.onSuccess();
}
}
use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection 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 ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection in project app by TourLive.
the class RiderStageConnectionRepository method addRiderStageConnection.
@Override
public RiderStageConnection addRiderStageConnection(RiderStageConnection riderStageConnection, OnSaveRiderStageConnectionCallback callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
final RiderStageConnection transferRiderStateConnection = riderStageConnection;
RiderStageConnection returnValue;
realm.beginTransaction();
RiderStageConnection realmRiderStageConnection = realm.createObject(RiderStageConnection.class, UUID.randomUUID().toString());
realmRiderStageConnection.setBonusPoint(transferRiderStateConnection.getBonusPoint());
realmRiderStageConnection.setBonusTime(transferRiderStateConnection.getBonusTime());
realmRiderStageConnection.setMountainBonusPoints(transferRiderStateConnection.getMountainBonusPoints());
realmRiderStageConnection.setSprintBonusPoints(transferRiderStateConnection.getSprintBonusPoints());
realmRiderStageConnection.setOfficialGap(transferRiderStateConnection.getOfficialGap());
realmRiderStageConnection.setOfficialTime(transferRiderStateConnection.getOfficialTime());
realmRiderStageConnection.setVirtualGap(transferRiderStateConnection.getVirtualGap());
realmRiderStageConnection.setType(transferRiderStateConnection.getType());
realmRiderStageConnection.setMoney(transferRiderStateConnection.getMoney());
realm.commitTransaction();
returnValue = realmRiderStageConnection;
if (callback != null) {
callback.onSuccess();
}
return returnValue;
}
Aggregations