use of ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection in project app by TourLive.
the class JudgmentRiderConnectionRepository method addJudgmentRiderConnection.
@Override
public void addJudgmentRiderConnection(JudgmentRiderConnection judgmentRiderConnection, OnSaveJudgmentRiderConnectionCallback callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
final JudgmentRiderConnection transferConnection = judgmentRiderConnection;
realm.beginTransaction();
RealmResults<JudgmentRiderConnection> res = realm.where(JudgmentRiderConnection.class).equalTo("rank", judgmentRiderConnection.getRank()).equalTo("judgements.id", judgmentRiderConnection.getJudgements().first().getId()).findAll();
if (!res.isEmpty()) {
removeOldJudgmentRiderConnections(res);
}
realm.commitTransaction();
realm.beginTransaction();
JudgmentRiderConnection realmConnection = realm.createObject(JudgmentRiderConnection.class, UUID.randomUUID().toString());
realmConnection.setRank(transferConnection.getRank());
realmConnection.setJudgements(transferConnection.getJudgements());
realmConnection.setRider(transferConnection.getRider());
realm.commitTransaction();
if (callback != null)
callback.onSuccess();
}
use of ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection 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.JudgmentRiderConnection in project app by TourLive.
the class JudgmentRiderConnectionRepository method getJudgmentRiderConnectionsReturnedByJudgment.
@Override
public RealmList<JudgmentRiderConnection> getJudgmentRiderConnectionsReturnedByJudgment(Judgement judgement) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
RealmResults<JudgmentRiderConnection> res = realm.where(JudgmentRiderConnection.class).equalTo("judgements.id", judgement.getId()).findAll();
RealmList<JudgmentRiderConnection> resList = new RealmList<>();
resList.addAll(res);
return resList;
}
use of ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection in project app by TourLive.
the class RiderBasicAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(RiderViewHolder holder, int position) {
holder.tvNummer.setText(String.valueOf(riders.get(position).getStartNr()));
holderHashMap.put(riders.get(position).getStartNr(), holder);
for (JudgmentRiderConnection jRc : judgement.getJudgmentRiderConnection()) {
if (jRc.getRider().contains(riders.get(position))) {
setColorOnRider(riders.get(position).getStartNr());
}
}
setRiderStateAnimation(holder.tvNummer, riders.get(position).getRiderStages().first().getType());
}
use of ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection in project app by TourLive.
the class JudgmentDetailFragment method saveJudgmnet.
public void saveJudgmnet() {
Rider rider = riderBasicAdapter.getSelectedRider();
if (rank != 0) {
JudgmentRiderConnection judgmentRiderConnection = new JudgmentRiderConnection();
judgmentRiderConnection.setRank(rank);
RealmList<Rider> riderToAdd = new RealmList<>();
riderToAdd.add(rider);
judgmentRiderConnection.setRider(riderToAdd);
RealmList<Judgement> judgementToAdd = new RealmList<>();
judgementToAdd.add(judgement);
judgmentRiderConnection.setJudgements(judgementToAdd);
JudgmentRiderConnectionPresenter.getInstance().addJudgmentRiderConnection(judgmentRiderConnection);
updateRiderStateConnectionWithPerformance(rider, rank);
textViews.get(rank - 1).setText(String.valueOf(rider.getStartNr()));
riderBasicAdapter.setColorOnRider(rider.getStartNr());
} else {
Toast toast = Toast.makeText(getContext(), getResources().getString(R.string.judgment_text), Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 0);
toast.show();
Integer integer = rider.getRiderID();
riderBasicAdapter.removeRiderFromList(integer);
}
riderBasicAdapter.resetSelectedRider();
rank = 0;
}
Aggregations