Search in sources :

Example 6 with RaceGroup

use of ch.hsr.sa.radiotour.dataaccess.models.RaceGroup in project app by TourLive.

the class RaceGroupRepositoryInstrumentedTest method addRaceGroup.

@Test
public void addRaceGroup() {
    RaceGroup raceGroup = new RaceGroup();
    raceGroup.setType(RaceGroupType.NORMAL);
    raceGroup.setPosition(0);
    raceGroup.setRiders(riders);
    synchronized (this) {
        raceGroupRepository.addRaceGroup(raceGroup, onSaveRaceGroupCallback);
    }
    RealmResults<RaceGroup> res = realm.where(RaceGroup.class).findAll();
    assertEquals(1, res.size());
    assertEquals(0, res.get(0).getHistoryGapTime());
    assertEquals(0, res.get(0).getHistoryGapTime());
    assertEquals(0, res.get(0).getPosition());
    assertEquals(RaceGroupType.NORMAL, res.get(0).getType());
}
Also used : RaceGroup(ch.hsr.sa.radiotour.dataaccess.models.RaceGroup) Test(org.junit.Test)

Example 7 with RaceGroup

use of ch.hsr.sa.radiotour.dataaccess.models.RaceGroup in project app by TourLive.

the class RaceGroupRepositoryInstrumentedTest method updateRaceGroupRiders.

@Test
public void updateRaceGroupRiders() {
    RaceGroup raceGroupOne = new RaceGroup();
    raceGroupOne.setType(RaceGroupType.LEAD);
    raceGroupOne.setPosition(0);
    raceGroupOne.setRiders(riders);
    RealmList<Rider> newRiders = new RealmList<>();
    for (int i = 3; i < 6; i++) {
        Rider rider = new Rider();
        rider.setTeamShortName("T");
        rider.setTeamName("TEST");
        rider.setCountry("T");
        rider.setName("TEST " + i);
        rider.setStartNr(i);
        newRiders.add(rider);
        synchronized (this) {
            riderRepository.addRider(rider, onSaveRiderCallback);
        }
    }
    RaceGroup raceGroupTwo = new RaceGroup();
    raceGroupTwo.setType(RaceGroupType.NORMAL);
    raceGroupTwo.setPosition(1);
    raceGroupTwo.setRiders(newRiders);
    synchronized (this) {
        raceGroupRepository.addRaceGroup(raceGroupOne, onSaveRaceGroupCallback);
    }
    synchronized (this) {
        raceGroupRepository.addRaceGroup(raceGroupTwo, onSaveRaceGroupCallback);
    }
    RealmResults<RaceGroup> res = realm.where(RaceGroup.class).findAll();
    RealmList<Rider> riderToTransfer = new RealmList<>();
    riderToTransfer.add(res.get(0).getRiders().first());
    assertEquals(3, res.get(0).getRiders().size());
    assertEquals(3, res.get(1).getRiders().size());
    synchronized (this) {
        raceGroupRepository.updateRaceGroupRiders(res.get(1), riderToTransfer, onUpdateRaceGroupCallBack);
    }
    RealmResults<RaceGroup> endRes = realm.where(RaceGroup.class).findAll();
    assertEquals(2, res.get(0).getRiders().size());
    assertEquals(4, res.get(1).getRiders().size());
}
Also used : RaceGroup(ch.hsr.sa.radiotour.dataaccess.models.RaceGroup) RealmList(io.realm.RealmList) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider) Test(org.junit.Test)

Example 8 with RaceGroup

use of ch.hsr.sa.radiotour.dataaccess.models.RaceGroup in project app by TourLive.

the class Parser method createDefaultGroup.

private static Thread createDefaultGroup() {
    Runnable runnable = (() -> {
        try {
            RaceGroup raceGroupField = new RaceGroup();
            raceGroupField.setActualGapTime(0);
            raceGroupField.setHistoryGapTime(0);
            raceGroupField.setPosition(1);
            raceGroupField.setType(RaceGroupType.FELD);
            RealmList<Rider> activeRiders = new RealmList<>();
            for (Rider r : Context.getAllRiders()) {
                if (r.getRiderStages().first().getType() == RiderStateType.AKTIVE) {
                    activeRiders.add(r);
                }
            }
            raceGroupField.setRiders(activeRiders);
            Context.addRaceGroup(raceGroupField);
        } catch (Exception e) {
            Log.d(Parser.class.getSimpleName(), "APP - PARSER - RACEGROUP - " + e.getMessage());
        }
    });
    return new Thread(runnable);
}
Also used : RaceGroup(ch.hsr.sa.radiotour.dataaccess.models.RaceGroup) RealmList(io.realm.RealmList) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider) JSONException(org.json.JSONException)

Example 9 with RaceGroup

use of ch.hsr.sa.radiotour.dataaccess.models.RaceGroup in project app by TourLive.

the class RiderRaceGroupFragment method onNewRaceGroupClicked.

public void onNewRaceGroupClicked(RaceGroup beforeRaceGroup, RaceGroupType raceGroupType) {
    RaceGroup raceGroup = new RaceGroup();
    raceGroup.setPosition(beforeRaceGroup.getPosition() + 1);
    raceGroup.setActualGapTime(beforeRaceGroup.getActualGapTime() + 1);
    raceGroup.setType(raceGroupType);
    if (!adapter.getSelectedRiders().isEmpty()) {
        RealmList<Rider> activeRider = filterNonActiveRiders(adapter.getSelectedRiders());
        if (activeRider.isEmpty()) {
            adapter.resetSelectRiders();
            return;
        }
        raceGroup.setRiders(activeRider);
        RaceGroupPresenter.getInstance().addRaceGroup(raceGroup);
        raceGroupAdapter.notifyDataSetChanged();
        adapter.resetSelectRiders();
    } else if (!unknownRiders.isEmpty()) {
        raceGroup.setRiders(unknownRiders);
        RaceGroupPresenter.getInstance().addRaceGroup(raceGroup);
        raceGroupAdapter.notifyDataSetChanged();
        removeUnknownRiders();
    }
}
Also used : RaceGroup(ch.hsr.sa.radiotour.dataaccess.models.RaceGroup) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider)

Example 10 with RaceGroup

use of ch.hsr.sa.radiotour.dataaccess.models.RaceGroup in project app by TourLive.

the class RaceGroupRepository method addInitialRaceGroup.

@Override
public void addInitialRaceGroup(RaceGroup raceGroup, OnSaveRaceGroupCallback callback) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    final RaceGroup transferRaceGroup = raceGroup;
    realm.beginTransaction();
    RaceGroup realmRaceGroup = realm.createObject(RaceGroup.class, UUID.randomUUID().toString());
    realmRaceGroup.setType(transferRaceGroup.getType());
    realmRaceGroup.setActualGapTime(transferRaceGroup.getActualGapTime());
    realmRaceGroup.setHistoryGapTime(transferRaceGroup.getHistoryGapTime());
    RealmList<Rider> res = new RealmList<>();
    for (Rider r : transferRaceGroup.getRiders()) {
        RealmResults<Rider> temp = realm.where(Rider.class).equalTo("startNr", r.getStartNr()).findAll();
        res.addAll(temp);
    }
    realmRaceGroup.setPosition(transferRaceGroup.getPosition());
    realmRaceGroup.setRiders(res);
    realm.commitTransaction();
    if (callback != null) {
        callback.onSuccess(realmRaceGroup);
    }
}
Also used : RaceGroup(ch.hsr.sa.radiotour.dataaccess.models.RaceGroup) RealmList(io.realm.RealmList) Realm(io.realm.Realm) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider)

Aggregations

RaceGroup (ch.hsr.sa.radiotour.dataaccess.models.RaceGroup)17 Rider (ch.hsr.sa.radiotour.dataaccess.models.Rider)9 Realm (io.realm.Realm)7 RealmList (io.realm.RealmList)7 Test (org.junit.Test)6 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 TextView (android.widget.TextView)1 JSONException (org.json.JSONException)1