use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorMoney 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();
}
}
Aggregations