Search in sources :

Example 1 with Maillot

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

the class MaillotRepository method addMaillot.

@Override
public void addMaillot(Maillot maillot, OnSaveMaillotCallback callback) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    realm.executeTransaction((Realm db) -> {
        Maillot realmMaillot = db.createObject(Maillot.class, UUID.randomUUID().toString());
        realmMaillot.setColor(maillot.getColor());
        realmMaillot.setDbIDd(maillot.getDbIDd());
        realmMaillot.setName(maillot.getName());
        realmMaillot.setPartner(maillot.getPartner());
        realmMaillot.setType(maillot.getType());
    });
    if (callback != null)
        callback.onSuccess();
}
Also used : Maillot(ch.hsr.sa.radiotour.dataaccess.models.Maillot) Realm(io.realm.Realm)

Example 2 with Maillot

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

the class MaillotRepository method getAllMaillots.

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

Example 3 with Maillot

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

the class Parser method parseMaillotsRiderConnectionAndPersist.

public static void parseMaillotsRiderConnectionAndPersist(JSONArray maillotsrider) throws InterruptedException {
    final JSONArray maillotsJson = maillotsrider;
    Runnable runnable = (() -> {
        for (int i = 0; i < maillotsJson.length(); i++) {
            try {
                JSONObject jsonMaillot = maillotsJson.getJSONObject(i);
                int id = Integer.parseInt(jsonMaillot.getString("jerseyId"));
                Maillot maillot = Context.getMaillotById(id);
                Context.addRiderToMaillot(maillot, Integer.parseInt(jsonMaillot.getString("riderId")));
            } catch (JSONException e) {
                Log.d(Parser.class.getSimpleName(), "APP - PARSER - MAILLOTS - " + e.getMessage());
            }
        }
    });
    Thread threadMaillots = new Thread(runnable);
    threadMaillots.start();
    threadMaillots.join();
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Maillot(ch.hsr.sa.radiotour.dataaccess.models.Maillot)

Example 4 with Maillot

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

the class Parser method parseMaillotsAndPersist.

public static void parseMaillotsAndPersist(JSONArray maillots) throws InterruptedException {
    final JSONArray maillotsJson = maillots;
    Runnable runnable = (() -> {
        for (int i = 0; i < maillotsJson.length(); i++) {
            try {
                JSONObject jsonMaillot = maillotsJson.getJSONObject(i);
                Maillot maillot = new Maillot();
                maillot.setType(jsonMaillot.getString("type"));
                maillot.setPartner(jsonMaillot.getString("partner"));
                maillot.setName(jsonMaillot.getString("name"));
                maillot.setDbIDd(jsonMaillot.getInt("dbId"));
                maillot.setColor(jsonMaillot.getString("color"));
                Context.addMaillot(maillot);
            } catch (JSONException e) {
                Log.d(Parser.class.getSimpleName(), "APP - PARSER - MAILLOTS - " + e.getMessage());
            }
        }
    });
    Thread threadMaillots = new Thread(runnable);
    threadMaillots.start();
    threadMaillots.join();
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Maillot(ch.hsr.sa.radiotour.dataaccess.models.Maillot)

Example 5 with Maillot

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

the class MaillotRepository method getAllMaillotsReturned.

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

Aggregations

Maillot (ch.hsr.sa.radiotour.dataaccess.models.Maillot)6 Realm (io.realm.Realm)4 RealmList (io.realm.RealmList)2 JSONArray (org.json.JSONArray)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 Rider (ch.hsr.sa.radiotour.dataaccess.models.Rider)1