use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorDistanceInLead in project app by TourLive.
the class RiderStageConnectionRepository method appendDistanceInLeadGroup.
@Override
public void appendDistanceInLeadGroup(final RiderStageConnection riderStageConnection, double value) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
realm.executeTransaction((Realm db) -> {
RiderStageConnection res = db.where(RiderStageConnection.class).equalTo("id", riderStageConnection.getId()).findFirst();
res.appendDistanceInLeadGroup(value);
List<RiderStageConnection> cons = realm.copyFromRealm(db.where(RiderStageConnection.class).findAll());
cons.sort(new RiderStageConnectionComparatorDistanceInLead());
for (int i = 0; i < cons.size(); i++) {
db.where(RiderStageConnection.class).equalTo("id", cons.get(i).getId()).findFirst().getRiderRanking(RankingType.DISTANCE_IN_LEAD).setRank(i + 1);
}
PostHandler.makeMessage("UpdateRiderStageConnection", realm.copyFromRealm(res));
});
}
use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorDistanceInLead in project app by TourLive.
the class Parser method updateRiderConnectionRankByDistanceInLead.
public static String updateRiderConnectionRankByDistanceInLead() throws InterruptedException {
Runnable runnable = new Runnable() {
public void run() {
try {
RealmList<RiderStageConnection> connections = Context.getAllRiderStageConnections();
connections.sort(new RiderStageConnectionComparatorDistanceInLead());
for (int i = 0; i < connections.size(); i++) {
RiderRanking rankingTimeInLead = new RiderRanking();
rankingTimeInLead.setType(RankingType.DISTANCE_IN_LEAD);
rankingTimeInLead.setRank(i + 1);
synchronized (this) {
Context.addRiderRanking(rankingTimeInLead);
}
RiderRanking realmRiderRanking = Context.getRiderRanking(rankingTimeInLead);
Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
}
} catch (Exception e) {
Log.d(Parser.class.getSimpleName(), "APP - PARSER - RIDERCONNECTION - " + e.getMessage());
}
}
};
Thread threadRanking = new Thread(runnable);
threadRanking.start();
threadRanking.join();
return "success";
}
Aggregations