Search in sources :

Example 1 with Stage

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);
}
Also used : Stage(ch.hsr.sa.radiotour.dataaccess.models.Stage) Realm(io.realm.Realm)

Example 2 with Stage

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);
    }
}
Also used : Stage(ch.hsr.sa.radiotour.dataaccess.models.Stage) Realm(io.realm.Realm)

Example 3 with 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());
}
Also used : RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) RealmList(io.realm.RealmList) Stage(ch.hsr.sa.radiotour.dataaccess.models.Stage) Date(java.util.Date) Test(org.junit.Test)

Example 4 with Stage

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();
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Stage(ch.hsr.sa.radiotour.dataaccess.models.Stage) JSONException(org.json.JSONException) Date(java.util.Date)

Example 5 with Stage

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;
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) Stage(ch.hsr.sa.radiotour.dataaccess.models.Stage) ProgressDialog(android.app.ProgressDialog) View(android.view.View) TextView(android.widget.TextView)

Aggregations

Stage (ch.hsr.sa.radiotour.dataaccess.models.Stage)6 Date (java.util.Date)3 Realm (io.realm.Realm)2 Test (org.junit.Test)2 ProgressDialog (android.app.ProgressDialog)1 View (android.view.View)1 TextView (android.widget.TextView)1 RiderStageConnection (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)1 RealmList (io.realm.RealmList)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1