Search in sources :

Example 16 with RealmList

use of io.realm.RealmList 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 17 with RealmList

use of io.realm.RealmList 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 18 with RealmList

use of io.realm.RealmList 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 19 with RealmList

use of io.realm.RealmList 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 20 with RealmList

use of io.realm.RealmList in project underlx by underlx.

the class Trip method persistConnectionPath.

public static String persistConnectionPath(Path path, String replaceTrip) {
    Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();
    RealmList<StationUse> uses = new RealmList<>();
    List<Connection> edgeList = path.getEdgeList();
    int size = edgeList.size();
    if (size == 0) {
        StationUse use = new StationUse();
        use.setType(StationUse.UseType.VISIT);
        use.setStation(realm.where(RStation.class).equalTo("id", path.getStartVertex().getStation().getId()).findFirst());
        use.setEntryDate(path.getEntryExitTimes(0).first);
        use.setLeaveDate(path.getEntryExitTimes(0).second);
        use.setManualEntry(path.getManualEntry(0));
        uses.add(realm.copyToRealm(use));
    } else if (size == 1 && edgeList.get(0) instanceof Transfer) {
        Connection c = edgeList.get(0);
        StationUse use = new StationUse();
        use.setType(StationUse.UseType.VISIT);
        use.setSourceLine(c.getSource().getLine().getId());
        use.setTargetLine(c.getTarget().getLine().getId());
        use.setEntryDate(path.getEntryExitTimes(0).first);
        use.setLeaveDate(path.getEntryExitTimes(0).second);
        use.setManualEntry(path.getManualEntry(0));
        use.setStation(realm.where(RStation.class).equalTo("id", c.getSource().getStation().getId()).findFirst());
        uses.add(realm.copyToRealm(use));
    } else {
        int timeIdx = 0;
        StationUse startUse = new StationUse();
        startUse.setType(StationUse.UseType.NETWORK_ENTRY);
        startUse.setStation(realm.where(RStation.class).equalTo("id", path.getStartVertex().getStation().getId()).findFirst());
        startUse.setEntryDate(path.getEntryExitTimes(timeIdx).first);
        startUse.setLeaveDate(path.getEntryExitTimes(timeIdx).second);
        startUse.setManualEntry(path.getManualEntry(timeIdx));
        uses.add(realm.copyToRealm(startUse));
        int i = 1;
        timeIdx++;
        if (edgeList.get(0) instanceof Transfer) {
            i = 2;
            timeIdx++;
        }
        for (; i < size; i++) {
            Connection c = edgeList.get(i);
            StationUse use = new StationUse();
            if (c instanceof Transfer) {
                if (i == size - 1)
                    break;
                use.setType(StationUse.UseType.INTERCHANGE);
                use.setSourceLine(c.getSource().getLine().getId());
                use.setTargetLine(c.getTarget().getLine().getId());
                use.setEntryDate(path.getEntryExitTimes(timeIdx).first);
                timeIdx++;
                use.setLeaveDate(path.getEntryExitTimes(timeIdx).second);
                use.setManualEntry(path.getManualEntry(timeIdx));
                timeIdx++;
                // skip next station as then we'd have duplicate uses for the same station ID
                i++;
            } else {
                use.setType(StationUse.UseType.GONE_THROUGH);
                use.setEntryDate(path.getEntryExitTimes(timeIdx).first);
                use.setLeaveDate(path.getEntryExitTimes(timeIdx).second);
                use.setManualEntry(path.getManualEntry(timeIdx));
                timeIdx++;
            }
            use.setStation(realm.where(RStation.class).equalTo("id", c.getSource().getStation().getId()).findFirst());
            uses.add(realm.copyToRealm(use));
        }
        StationUse endUse = new StationUse();
        endUse.setType(StationUse.UseType.NETWORK_EXIT);
        endUse.setStation(realm.where(RStation.class).equalTo("id", path.getEndVertex().getStation().getId()).findFirst());
        endUse.setEntryDate(path.getEntryExitTimes(timeIdx).first);
        endUse.setLeaveDate(path.getEntryExitTimes(timeIdx).second);
        endUse.setManualEntry(path.getManualEntry(timeIdx));
        uses.add(realm.copyToRealm(endUse));
    }
    Trip trip;
    if (replaceTrip != null) {
        trip = realm.where(Trip.class).equalTo("id", replaceTrip).findFirst();
        trip.getPath().deleteAllFromRealm();
        trip.setUserConfirmed(true);
        trip.setSynced(false);
    } else {
        trip = realm.createObject(Trip.class, UUID.randomUUID().toString());
        trip.setUserConfirmed(false);
    }
    trip.setPath(uses);
    String tripId = trip.getId();
    realm.commitTransaction();
    realm.close();
    return tripId;
}
Also used : RealmList(io.realm.RealmList) Connection(im.tny.segvault.subway.Connection) Transfer(im.tny.segvault.subway.Transfer) 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