use of ch.hsr.sa.radiotour.dataaccess.models.Stage in project app by TourLive.
the class StageRepository method addStage.
@Override
public void addStage(final Stage stage, OnSaveStageCallback callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
realm.executeTransaction((Realm db) -> {
Stage realmStage = db.createObject(Stage.class, UUID.randomUUID().toString());
realmStage.setStageId(stage.getStageId());
realmStage.setDistance(stage.getDistance());
realmStage.setEndTime(stage.getEndTime());
realmStage.setStartTime(stage.getStartTime());
realmStage.setFrom(stage.getFrom());
realmStage.setTo(stage.getTo());
realmStage.setName(stage.getName());
realmStage.setType(stage.getType());
realmStage.setStageConnections(stage.getStageConnections());
realmStage.setMaillotConnections(stage.getMaillotConnections());
realmStage.setRaceName(stage.getRaceName());
realmStage.setRaceId(stage.getRaceId());
});
Stage dbStage = realm.where(Stage.class).findFirst();
if (callback != null)
callback.onSuccess(dbStage);
}
use of ch.hsr.sa.radiotour.dataaccess.models.Stage in project app by TourLive.
the class StageRepository method getStage.
public void getStage(OnGetStageCallback callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
Stage stage = realm.where(Stage.class).findFirst();
if (callback != null) {
callback.onSuccess(stage);
}
}
use of ch.hsr.sa.radiotour.dataaccess.models.Stage in project app by TourLive.
the class StageRepositoryInstrumentedTest method addStage.
@Test
public void addStage() {
RiderStageConnection riderStageConnection = new RiderStageConnection();
riderStageConnection.setBonusPoint(10);
riderStageConnection.setBonusTime(20);
riderStageConnection.setOfficialGap(100);
riderStageConnection.setOfficialTime(100);
riderStageConnection.setType(RiderStateType.DNC);
riderStageConnection.setVirtualGap(100);
synchronized (this) {
riderStageConnectionRepository.addRiderStageConnection(riderStageConnection, onSaveRiderStageConnectionCallback);
riderStageConnection.setBonusPoint(100);
riderStageConnectionRepository.addRiderStageConnection(riderStageConnection, onSaveRiderStageConnectionCallback);
}
RealmList<RiderStageConnection> connections = new RealmList<>();
RealmResults<RiderStageConnection> realmConnections = realm.where(RiderStageConnection.class).findAll();
connections.addAll(realmConnections);
Stage stage = new Stage();
stage.setStageId(1);
stage.setDistance(100);
stage.setStartTime(new Date());
stage.setEndTime(new Date());
stage.setFrom("bern");
stage.setTo("zuerich");
stage.setName("Etappe 1");
stage.setType(StageType.FLATSTAGE);
stage.setStageConnections(connections);
synchronized (this) {
stageRepository.addStage(stage, onSaveStageCallback);
}
Assert.assertEquals(100, realm.where(Stage.class).findAll().first().getDistance());
Assert.assertEquals("bern", realm.where(Stage.class).findAll().first().getFrom());
Assert.assertEquals("Etappe 1", realm.where(Stage.class).findAll().first().getName());
Assert.assertEquals(2, realm.where(Stage.class).findAll().first().getStageConnections().size());
Assert.assertEquals(20, realm.where(Stage.class).findAll().first().getStageConnections().first().getBonusTime());
}
use of ch.hsr.sa.radiotour.dataaccess.models.Stage in project app by TourLive.
the class Parser method parseStagesAndPersist.
public static void parseStagesAndPersist(JSONArray stages, final int STAGE_NR) throws InterruptedException {
final JSONArray stagesJson = stages;
Runnable runnable = (() -> {
try {
JSONObject jsonStage = stagesJson.getJSONObject(STAGE_NR);
Stage stage = new Stage();
stage.setStageId(jsonStage.getInt("stageId"));
stage.setType(StageType.valueOf(jsonStage.getString("stagetype")));
stage.setName(jsonStage.getString("stageName"));
stage.setTo(jsonStage.getString("to"));
stage.setFrom(jsonStage.getString("from"));
stage.setStartTime(new Date(jsonStage.getLong("starttimeAsTimestamp")));
stage.setEndTime(new Date(jsonStage.getLong("endtimeAsTimestamp")));
stage.setDistance(jsonStage.getInt("distance"));
stage.setStageConnections(Context.getAllRiderStageConnections());
stage.setMaillotConnections(Context.getAllMaillots());
JSONObject jsonRace = jsonStage.getJSONObject("race");
stage.setRaceId(jsonRace.getInt("raceId"));
stage.setRaceName(jsonRace.getString("raceName"));
Context.addStage(stage);
} catch (JSONException e) {
Log.d(Parser.class.getSimpleName(), "APP - PARSER - STAGES - " + e.getMessage());
}
});
Thread threadRewards = new Thread(runnable);
threadRewards.start();
threadRewards.join();
}
use of ch.hsr.sa.radiotour.dataaccess.models.Stage in project app by TourLive.
the class ImportFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.d("TAG", "ImportFragment onCreateView");
demoMode = false;
View root = inflater.inflate(R.layout.fragment_import, container, false);
btnImport = root.findViewById(R.id.btn_Import);
btnImport.setOnClickListener(this);
btnDemo = root.findViewById(R.id.btn_ImportDemodata);
btnDemo.setOnClickListener(this);
gpsView = root.findViewById(R.id.circleGPS);
serverView = root.findViewById(R.id.circleServer);
raceIdView = root.findViewById(R.id.txtActualRaceIdValue);
stageIdView = root.findViewById(R.id.txtActualStageIdValue);
StagePresenter.getInstance().addView(this);
Stage stage = StagePresenter.getInstance().getStage();
if (stage != null) {
updateActualStage(stage);
}
progressBar = new ProgressDialog(getActivity());
timerForUpdate = new Timer();
timerTaskForUpdate = new TimerTask() {
@Override
public void run() {
updateViews();
}
};
timerForUpdate.schedule(timerTaskForUpdate, delayTime, updateTime);
statusView = root.findViewById(R.id.txtStatus);
statusView.setText(getString(R.string.import_status) + getString(R.string.import_version, BuildConfig.VERSION_NAME));
return root;
}
Aggregations