Search in sources :

Example 1 with RiderStageConnectionComparatorMoney

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();
    }
}
Also used : RiderStageConnectionComparatorMoney(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorMoney) RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) RiderStageConnectionComparatorPoints(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorPoints) RiderStageConnectionComparatorMountainPoints(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorMountainPoints) Realm(io.realm.Realm)

Aggregations

RiderStageConnection (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)1 RiderStageConnectionComparatorMoney (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorMoney)1 RiderStageConnectionComparatorMountainPoints (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorMountainPoints)1 RiderStageConnectionComparatorPoints (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorPoints)1 Realm (io.realm.Realm)1