Search in sources :

Example 6 with RealmList

use of io.realm.RealmList in project app by TourLive.

the class RaceGroupRepository method updateRaceGroupRiders.

public void updateRaceGroupRiders(RaceGroup raceGroup, final RealmList<Rider> newRiders, OnUpdateRaceGroupCallBack callback) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    RiderRepository riderRepository = new RiderRepository();
    RealmList<Rider> riders = new RealmList<>();
    riders.addAll(newRiders);
    realm.beginTransaction();
    RaceGroup realmRemoveGroup = realm.where(RaceGroup.class).equalTo("riders.id", newRiders.get(0).getId()).findFirst();
    if (realmRemoveGroup != null) {
        for (Rider r : riders) {
            realmRemoveGroup.removeRider(r);
        }
    }
    realm.commitTransaction();
    if (raceGroup.getType() == RaceGroupType.FELD) {
        Iterator<Rider> iterator = riders.iterator();
        while (iterator.hasNext()) {
            Rider r = iterator.next();
            if (r.isUnknown()) {
                riderRepository.removeRider(r, null);
                iterator.remove();
            }
        }
    }
    realm.beginTransaction();
    RaceGroup realmRaceGroup = realm.where(RaceGroup.class).equalTo("type", raceGroup.getType().toString()).equalTo("position", raceGroup.getPosition()).findFirst();
    if (!riders.isEmpty())
        realmRaceGroup.appendRiders(riders);
    realm.commitTransaction();
    if (realmRemoveGroup != null && realmRemoveGroup.getRiders().isEmpty()) {
        deleteRaceGroup(realmRemoveGroup);
    }
    if (callback != null) {
        callback.onSuccess(realmRaceGroup);
    }
}
Also used : RealmList(io.realm.RealmList) RaceGroup(ch.hsr.sa.radiotour.dataaccess.models.RaceGroup) Realm(io.realm.Realm) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider)

Example 7 with RealmList

use of io.realm.RealmList in project app by TourLive.

the class RaceGroupRepository method addRaceGroup.

@Override
public void addRaceGroup(RaceGroup raceGroup, OnSaveRaceGroupCallback callback) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    realm.beginTransaction();
    RealmResults<RaceGroup> rGtoUpdate = realm.where(RaceGroup.class).greaterThanOrEqualTo("position", raceGroup.getPosition()).findAllSorted("position");
    for (RaceGroup rG : rGtoUpdate) {
        rG.setPosition(rG.getPosition() + 1);
        rG.setActualGapTime(rG.getActualGapTime() + 1);
        if (rG.getType() == RaceGroupType.LEAD) {
            rG.setType(RaceGroupType.NORMAL);
        }
    }
    realm.commitTransaction();
    for (Rider r : raceGroup.getRiders()) {
        RealmResults<RaceGroup> resRG = realm.where(RaceGroup.class).equalTo("riders.id", r.getId()).findAll();
        if (!resRG.isEmpty()) {
            Iterator<RaceGroup> iterator = resRG.iterator();
            while (iterator.hasNext()) {
                RaceGroup rG = iterator.next();
                realm.beginTransaction();
                rG.removeRider(r);
                realm.commitTransaction();
                if (rG.getRiders().isEmpty())
                    deleteRaceGroup(rG);
            }
        }
    }
    realm.beginTransaction();
    RaceGroup realmRaceGroup = realm.createObject(RaceGroup.class, UUID.randomUUID().toString());
    realmRaceGroup.setType(raceGroup.getType());
    realmRaceGroup.setActualGapTime(raceGroup.getActualGapTime());
    realmRaceGroup.setHistoryGapTime(0);
    realmRaceGroup.setPosition(raceGroup.getPosition());
    RealmList<Rider> res = new RealmList<>();
    for (Rider r : raceGroup.getRiders()) {
        RealmResults<Rider> temp = realm.where(Rider.class).equalTo("startNr", r.getStartNr()).findAll();
        res.addAll(temp);
    }
    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)

Example 8 with RealmList

use of io.realm.RealmList in project app by TourLive.

the class RiderRepository method getAllUnknownRidersReturned.

@Override
public RealmList<Rider> getAllUnknownRidersReturned() {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    RealmResults<Rider> results = realm.where(Rider.class).equalTo("isUnknown", true).findAll().sort("startNr");
    RealmList<Rider> res = new RealmList<>();
    res.addAll(results);
    return res;
}
Also used : RealmList(io.realm.RealmList) Realm(io.realm.Realm) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider)

Example 9 with RealmList

use of io.realm.RealmList in project app by TourLive.

the class RiderStageConnectionRepository method getAllRiderStateConnections.

@Override
public RealmList<RiderStageConnection> getAllRiderStateConnections() {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    RealmResults<RiderStageConnection> res = realm.where(RiderStageConnection.class).findAll();
    RealmList<RiderStageConnection> resList = new RealmList<>();
    resList.addAll(res);
    return resList;
}
Also used : RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) RealmList(io.realm.RealmList) Realm(io.realm.Realm)

Example 10 with RealmList

use of io.realm.RealmList in project app by TourLive.

the class RiderStageConnectionRepository method getRiderStageConnections.

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

Aggregations

RealmList (io.realm.RealmList)39 Realm (io.realm.Realm)23 Rider (ch.hsr.sa.radiotour.dataaccess.models.Rider)17 Test (org.junit.Test)8 RaceGroup (ch.hsr.sa.radiotour.dataaccess.models.RaceGroup)7 Judgement (ch.hsr.sa.radiotour.dataaccess.models.Judgement)6 RiderStageConnection (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)6 JudgmentRiderConnection (ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection)4 Scheduler (io.reactivex.Scheduler)4 DynamicRealm (io.realm.DynamicRealm)4 RealmConfiguration (io.realm.RealmConfiguration)4 DialogInterface (android.content.DialogInterface)2 View (android.view.View)2 Maillot (ch.hsr.sa.radiotour.dataaccess.models.Maillot)2 Reward (ch.hsr.sa.radiotour.dataaccess.models.Reward)2 EmailRealm (com.xabber.android.data.database.realm.EmailRealm)2 SocialBindingRealm (com.xabber.android.data.database.realm.SocialBindingRealm)2 SyncStateRealm (com.xabber.android.data.database.realm.SyncStateRealm)2 XMPPUserRealm (com.xabber.android.data.database.realm.XMPPUserRealm)2 XabberAccountRealm (com.xabber.android.data.database.realm.XabberAccountRealm)2