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();
}
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);
}
}
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();
}
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();
}
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;
}
Aggregations