Search in sources :

Example 11 with RaceGroup

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

the class RaceGroupRepository method getAllRaceGroups.

@Override
public void getAllRaceGroups(OnGetAllRaceGroupsCallback callback) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    RealmResults<RaceGroup> results = realm.where(RaceGroup.class).findAll();
    RealmList<RaceGroup> res = new RealmList<>();
    res.addAll(results);
    if (callback != null) {
        callback.onSuccess(res);
    }
}
Also used : RaceGroup(ch.hsr.sa.radiotour.dataaccess.models.RaceGroup) RealmList(io.realm.RealmList) Realm(io.realm.Realm)

Example 12 with RaceGroup

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

the class RaceGroupRepository method getRaceGroupById.

@Override
public RaceGroup getRaceGroupById(String raceGroupId) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    realm.beginTransaction();
    RaceGroup raceGroup = realm.where(RaceGroup.class).equalTo("id", raceGroupId).findFirst();
    realm.commitTransaction();
    return raceGroup;
}
Also used : RaceGroup(ch.hsr.sa.radiotour.dataaccess.models.RaceGroup) Realm(io.realm.Realm)

Example 13 with RaceGroup

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

the class RaceGroupRepositoryInstrumentedTest method updateRaceGroupGapTime.

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

Example 14 with RaceGroup

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

the class RaceGroupRepositoryInstrumentedTest method addInitialRaceGroup.

@Test
public void addInitialRaceGroup() {
    RaceGroup raceGroup = new RaceGroup();
    raceGroup.setType(RaceGroupType.NORMAL);
    raceGroup.setHistoryGapTime(100);
    raceGroup.setActualGapTime(10);
    raceGroup.setPosition(0);
    raceGroup.setRiders(riders);
    synchronized (this) {
        raceGroupRepository.addInitialRaceGroup(raceGroup, onSaveRaceGroupCallback);
    }
    RealmResults<RaceGroup> res = realm.where(RaceGroup.class).findAll();
    assertEquals(1, res.size());
    assertEquals(100, res.get(0).getHistoryGapTime());
    assertEquals(10, res.get(0).getActualGapTime());
    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 15 with RaceGroup

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

the class RaceGroupRepositoryInstrumentedTest method deleteRiderInRaceGroup.

@Test
public void deleteRiderInRaceGroup() {
    RaceGroup raceGroup = new RaceGroup();
    raceGroup.setType(RaceGroupType.NORMAL);
    raceGroup.setPosition(1);
    raceGroup.setRiders(riders);
    synchronized (this) {
        raceGroupRepository.addRaceGroup(raceGroup, onSaveRaceGroupCallback);
    }
    RealmResults<RaceGroup> res = realm.where(RaceGroup.class).findAll();
    RealmResults<Rider> resRiders = realm.where(Rider.class).findAll();
    Rider riderToDelete = resRiders.get(0);
    assertEquals(3, res.get(0).getRiders().size());
    synchronized (this) {
        raceGroupRepository.deleteRiderInRaceGroup(res.first(), riderToDelete, onUpdateRaceGroupCallBack);
    }
    RealmResults<RaceGroup> endRes = realm.where(RaceGroup.class).findAll();
    assertEquals(2, endRes.get(0).getRiders().size());
}
Also used : RaceGroup(ch.hsr.sa.radiotour.dataaccess.models.RaceGroup) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider) Test(org.junit.Test)

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