use of ch.hsr.sa.radiotour.dataaccess.models.Judgement in project app by TourLive.
the class JudgmentRepository method getAllJudgments.
@Override
public void getAllJudgments(OnGetAllJudgmentCallback callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
RealmResults<Judgement> results = realm.where(Judgement.class).findAll();
RealmList<Judgement> res = new RealmList<>();
res.addAll(results);
if (callback != null) {
callback.onSuccess(res);
}
}
use of ch.hsr.sa.radiotour.dataaccess.models.Judgement in project app by TourLive.
the class JudgmentRepository method getJudgmentsById.
@Override
public RealmList<Judgement> getJudgmentsById(final int judgmentId) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
RealmList<Judgement> results = new RealmList<>();
RealmResults<Judgement> judgments = realm.where(Judgement.class).findAll();
for (Judgement j : judgments) {
if (j.getRewardId() == judgmentId) {
results.add(j);
}
}
return results;
}
use of ch.hsr.sa.radiotour.dataaccess.models.Judgement in project app by TourLive.
the class JudgmentDetailFragment method updateRiderStateConnectionWithPerformance.
private void updateRiderStateConnectionWithPerformance(Rider rider, int rank) {
int r = rider.getStartNr();
new Thread(() -> {
Judgement judgement = JudgmentPresenter.getInstance().getJudgmentByObjectIdReturned(judgementID);
rewardM = RewardPresenter.getInstance().getRewardReturnedByJudgment(judgement);
RiderStageConnection riderStageConnection = new RiderStageConnection();
riderStageConnection.setId(RiderPresenter.getInstance().getRiderByStartNr(r).getRiderStages().first().getId());
if (rewardM.getType() == RewardType.TIME) {
riderStageConnection.setBonusTime(RiderStageConnectionUtilities.getPointsAtPosition(rank, rewardM));
} else if (rewardM.getType() == RewardType.POINTS) {
int points = RiderStageConnectionUtilities.getPointsAtPosition(rank, rewardM);
if (judgement.getName().toLowerCase().contains("sprint")) {
riderStageConnection.setSprintBonusPoints(points);
riderStageConnection.setBonusPoint(points);
} else if (judgement.getName().toLowerCase().contains("bergpreis")) {
riderStageConnection.setMountainBonusPoints(points);
} else {
riderStageConnection.setBonusPoint(points);
}
} else {
Log.d(JudgmentDetailFragment.class.getSimpleName(), "APP - CALCULATE - UNSUPPORTED TYPE");
}
riderStageConnection.setMoney(RiderStageConnectionUtilities.getMoneyAtPosition(rank, rewardM));
RiderStageConnectionPresenter.getInstance().updateRiderStageConnectionReward(riderStageConnection);
}).start();
}
use of ch.hsr.sa.radiotour.dataaccess.models.Judgement 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;
}
use of ch.hsr.sa.radiotour.dataaccess.models.Judgement in project app by TourLive.
the class JudgmentRepositoryInstrumentedTest method addJudgment.
@Test
public void addJudgment() {
Judgement judgement = new Judgement();
judgement.setDistance(100);
judgement.setName("judgment");
judgement.setRewardId(93);
synchronized (this) {
judgmentRepository.addJudgment(judgement, onSaveJudgmentCallback);
}
Judgement realmJudgment = realm.where(Judgement.class).findAll().first();
Assert.assertEquals(judgement.getDistance(), realmJudgment.getDistance());
Assert.assertEquals(judgement.getRewardId(), realmJudgment.getRewardId());
Assert.assertEquals(judgement.getName(), realmJudgment.getName());
}
Aggregations