Search in sources :

Example 1 with JudgmentRiderConnection

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

Example 2 with JudgmentRiderConnection

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

Example 3 with JudgmentRiderConnection

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

Example 4 with JudgmentRiderConnection

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

Example 5 with JudgmentRiderConnection

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;
}
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)

Aggregations

JudgmentRiderConnection (ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection)8 Judgement (ch.hsr.sa.radiotour.dataaccess.models.Judgement)4 RealmList (io.realm.RealmList)4 Rider (ch.hsr.sa.radiotour.dataaccess.models.Rider)3 Realm (io.realm.Realm)2 Test (org.junit.Test)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 Toast (android.widget.Toast)1 Reward (ch.hsr.sa.radiotour.dataaccess.models.Reward)1 RiderStageConnection (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)1