use of ch.hsr.sa.radiotour.dataaccess.models.RiderRanking in project app by TourLive.
the class RiderStageConnectionRepository method updateRiderStageConnectionTime.
@Override
public void updateRiderStageConnectionTime(long timeBefore, long timeStamp, final RaceGroup res, OnUpdateRiderStageConnectionCallBack callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
realm.beginTransaction();
if (timeBefore > 0 && !res.getRiders().isEmpty()) {
for (Rider r : res.getRiders()) {
if (!r.getRiderStages().isEmpty()) {
r.getRiderStages().first().setVirtualGap(r.getRiderStages().first().getVirtualGap() - timeBefore);
}
}
}
if (!res.getRiders().isEmpty()) {
for (Rider r : res.getRiders()) {
if (!r.getRiderStages().isEmpty()) {
r.getRiderStages().first().setVirtualGap(r.getRiderStages().first().getVirtualGap() + timeStamp);
}
}
}
RealmResults<RiderStageConnection> connections = realm.where(RiderStageConnection.class).findAll();
List<RiderStageConnection> cons = realm.copyFromRealm(connections);
cons.sort(new RiderStageConnectionComparatorVirtualGap());
for (int i = 0; i < cons.size(); i++) {
RiderRanking riderRanking = realm.where(RiderStageConnection.class).equalTo("id", cons.get(i).getId()).findFirst().getRiderRanking(RankingType.VIRTUAL);
if (riderRanking != null) {
riderRanking.setRank(i + 1);
}
}
realm.commitTransaction();
if (callback != null) {
callback.onSuccess();
}
}
use of ch.hsr.sa.radiotour.dataaccess.models.RiderRanking in project app by TourLive.
the class MaillotsAdapter method getActualLeader.
private void getActualLeader(String type, MaillotViewHolder holder) {
Rider rider = null;
RiderRanking riderRanking = null;
switch(type) {
case "leader":
riderRanking = RiderRankingPresenter.getInstance().getFirstInRanking(RankingType.VIRTUAL);
rider = riderRanking.getRiderStageConnection().getRiders();
holder.leaderVirtInfo.setText(String.format("%s, %s, (%d)", rider.getName(), rider.getTeamName(), riderRanking.getRank()));
break;
case "mountain":
riderRanking = RiderRankingPresenter.getInstance().getFirstInRanking(RankingType.MOUNTAIN);
rider = riderRanking.getRiderStageConnection().getRiders();
holder.leaderVirtInfo.setText(String.format("%s, %s, (%d)", rider.getName(), rider.getTeamName(), riderRanking.getRank()));
break;
case "points":
riderRanking = RiderRankingPresenter.getInstance().getFirstInRanking(RankingType.POINTS);
rider = riderRanking.getRiderStageConnection().getRiders();
holder.leaderVirtInfo.setText(String.format("%s, %s, (%d)", rider.getName(), rider.getTeamName(), riderRanking.getRank()));
break;
case "bestSwiss":
riderRanking = RiderRankingPresenter.getInstance().getFirstInRanking(RankingType.SWISS);
rider = riderRanking.getRiderStageConnection().getRiders();
holder.leaderVirtInfo.setText(String.format("%s, %s, (%d)", rider.getName(), rider.getTeamName(), riderRanking.getRank()));
break;
default:
break;
}
if (rider != null) {
holder.leaderVirtStart.setText(String.valueOf(rider.getStartNr()));
holder.leaderVirtFlag.setImageResource(UIUtilitis.getCountryFlag(String.valueOf(rider.getCountry())));
holder.leaderVirtFlag.setAdjustViewBounds(true);
}
}
Aggregations