Search in sources :

Example 6 with Judgement

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

Example 7 with Judgement

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

Example 8 with Judgement

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();
}
Also used : Judgement(ch.hsr.sa.radiotour.dataaccess.models.Judgement) RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)

Example 9 with Judgement

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;
}
Also used : RealmList(io.realm.RealmList) Judgement(ch.hsr.sa.radiotour.dataaccess.models.Judgement) Toast(android.widget.Toast) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider) JudgmentRiderConnection(ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection)

Example 10 with Judgement

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());
}
Also used : Judgement(ch.hsr.sa.radiotour.dataaccess.models.Judgement) Test(org.junit.Test)

Aggregations

Judgement (ch.hsr.sa.radiotour.dataaccess.models.Judgement)16 Test (org.junit.Test)7 RealmList (io.realm.RealmList)6 JudgmentRiderConnection (ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection)4 Reward (ch.hsr.sa.radiotour.dataaccess.models.Reward)4 Realm (io.realm.Realm)4 Rider (ch.hsr.sa.radiotour.dataaccess.models.Rider)3 RiderStageConnection (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)2 Toast (android.widget.Toast)1 IJudgmentRepository (ch.hsr.sa.radiotour.dataaccess.interfaces.IJudgmentRepository)1 IRewardRepository (ch.hsr.sa.radiotour.dataaccess.interfaces.IRewardRepository)1 JudgmentRepository (ch.hsr.sa.radiotour.dataaccess.repositories.JudgmentRepository)1 RewardRepository (ch.hsr.sa.radiotour.dataaccess.repositories.RewardRepository)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 Before (org.junit.Before)1