Search in sources :

Example 1 with PostHandler

use of ch.hsr.sa.radiotour.controller.api.PostHandler in project app by TourLive.

the class RaceGroupRepositoryInstrumentedTest method initTestData.

@Before
public void initTestData() {
    this.riderRepository = new RiderRepository();
    this.raceGroupRepository = new RaceGroupRepository();
    realm = Realm.getInstance(RadioTourApplication.getInstance());
    initCallbacks();
    raceGroups.clear();
    realm.executeTransaction(realm -> {
        realm.where(Rider.class).findAll().deleteAllFromRealm();
        realm.where(RaceGroup.class).findAll().deleteAllFromRealm();
    });
    PostHandler postHandler = new PostHandler();
    postHandler.start();
    APIClient.setDemoMode(true);
    createRiders();
}
Also used : RiderRepository(ch.hsr.sa.radiotour.dataaccess.repositories.RiderRepository) IRiderRepository(ch.hsr.sa.radiotour.dataaccess.interfaces.IRiderRepository) PostHandler(ch.hsr.sa.radiotour.controller.api.PostHandler) IRaceGroupRepository(ch.hsr.sa.radiotour.dataaccess.interfaces.IRaceGroupRepository) RaceGroupRepository(ch.hsr.sa.radiotour.dataaccess.repositories.RaceGroupRepository) Before(org.junit.Before)

Example 2 with PostHandler

use of ch.hsr.sa.radiotour.controller.api.PostHandler in project app by TourLive.

the class MainActivity method initViewsAndHandlers.

private void initViewsAndHandlers() {
    uiHandler = new Handler();
    timerForRace = new Timer();
    heightView = findViewById(R.id.txtHeightValue);
    topFieldActualGapView = findViewById(R.id.txtTopFieldActualGap);
    topRadioTourActualGapView = findViewById(R.id.txtTopRadioTourActualGap);
    stageView = findViewById(R.id.txtStageValue);
    velocityView = findViewById(R.id.txtVelocityValue);
    raceKilometerView = findViewById(R.id.txtRacekilometerValue);
    raceTimeView = findViewById(R.id.txtRacetimeValue);
    startStopView = findViewById(R.id.btnStartStopRace);
    resetView = findViewById(R.id.btnReset);
    if (StagePresenter.getInstance().getStage() != null)
        updateStageInfo(StagePresenter.getInstance().getStage());
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, 0);
    }
    startStopView.setOnClickListener((View click) -> {
        if (!raceInProgress) {
            raceInProgress = true;
            startStopView.setBackgroundColor(getColor(R.color.colorOlive));
            if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                locationManager.getProvider(LocationManager.GPS_PROVIDER).supportsAltitude();
                locationManager.addNmeaListener((OnNmeaMessageListener) (message, timestamp) -> {
                    if (message.startsWith("$")) {
                        String[] tokens = message.split(",");
                        String type = tokens[0];
                        if (type.startsWith("$GPGGA") && !tokens[11].isEmpty()) {
                            correctionHeight = Double.parseDouble(tokens[11]);
                        }
                    }
                });
                locationListener = new LocationListener() {

                    @Override
                    public void onLocationChanged(Location location) {
                        if (actualLocation != null) {
                            distanceInMeter += actualLocation.distanceTo(location);
                        }
                        actualLocation = location;
                        uiHandler.post(() -> {
                            heightView.setText(getString(R.string.header_prefix_m, (actualLocation.getAltitude() - correctionHeight)));
                            raceKilometerView.setText(getString(R.string.header_prefix_km, distanceInMeter / 1000f, wholeDistanceInKm));
                            double seconds = TimeUnit.MILLISECONDS.toSeconds(raceTime.getTime());
                            double averageSpeed = (distanceInMeter / seconds) * 3.6;
                            velocityView.setText(getString(R.string.header_prefix_kmh, averageSpeed));
                        });
                    }

                    @Override
                    public void onStatusChanged(String provider, int status, Bundle extras) {
                    // Has to be implemented, but not needed
                    }

                    @Override
                    public void onProviderEnabled(String provider) {
                    // Has to be implemented, but not needed
                    }

                    @Override
                    public void onProviderDisabled(String provider) {
                    // Has to be implemented, but not needed
                    }
                };
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updateTime, minDistanceChange, locationListener);
                timerForRace = new Timer();
                timerTaskForRace = new TimerTask() {

                    @Override
                    public void run() {
                        raceTime.setTime(raceTime.getTime() + updateTimeForRace);
                        uiHandler.post(() -> raceTimeView.setText(convertLongToTimeString(raceTime.getTime())));
                        timeInRaceGroupCounter++;
                        if (timeInRaceGroupCounter == 60) {
                            timeInRaceGroupCounter = 0;
                            double tempDistanceInLeadGroup = distanceInLeadGroup;
                            distanceInLeadGroup = distanceInMeter / 1000f;
                            RaceGroup leadRaceGroup = RaceGroupPresenter.getInstance().getLeadRaceGroup();
                            if (leadRaceGroup != null) {
                                for (Rider r : RaceGroupPresenter.getInstance().getLeadRaceGroup().getRiders()) {
                                    RiderStageConnectionPresenter.getInstance().appendTimeInLeadGroup(r.getRiderStages().first(), 1);
                                    RiderStageConnectionPresenter.getInstance().appendDistanceInLeadGroup(r.getRiderStages().first(), (distanceInLeadGroup - tempDistanceInLeadGroup));
                                }
                            }
                        }
                    }
                };
                timerForRace.schedule(timerTaskForRace, delayZero, updateTimeForRace);
            }
        } else {
            raceInProgress = false;
            locationManager.removeUpdates(locationListener);
            startStopView.setBackgroundColor(getColor(R.color.colorPrimaryUltraLight));
            timerForRace.cancel();
        }
    });
    resetView.setOnClickListener(event -> {
        new AlertDialog.Builder(this).setTitle(R.string.resettime_title).setMessage(R.string.resettime_message).setNegativeButton(android.R.string.cancel, null).setPositiveButton(android.R.string.ok, (DialogInterface dialog, int which) -> resetTime()).create().show();
    });
    raceTimeView.setOnClickListener((View event) -> {
        TimePickerDialog dialog = new TimePickerDialog(this, (view, hourOfDay, minute) -> {
            raceTime.setTime(new Time(TimeUnit.HOURS.toMillis(view.getHour()) + TimeUnit.MINUTES.toMillis(view.getMinute())).getTime());
            raceTimeView.setText(convertLongToTimeString(raceTime.getTime()));
        }, 0, 0, true);
        dialog.setTitle(R.string.header_select_time);
        dialog.show();
    });
    timerForUpdate = new Timer();
    timerTaskForUpdate = new TimerTask() {

        @Override
        public void run() {
            updateUIInfos();
        }
    };
    timerForUpdate.schedule(timerTaskForUpdate, delayTime, updateTime);
    PostHandler postHandler = new PostHandler();
    postHandler.start();
}
Also used : R(ch.hsr.sa.radiotour.R) Bundle(android.os.Bundle) Time(java.sql.Time) PackageManager(android.content.pm.PackageManager) Date(java.util.Date) Timer(java.util.Timer) RaceFragment(ch.hsr.sa.radiotour.presentation.fragments.RaceFragment) LocationListener(android.location.LocationListener) Manifest(android.Manifest) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) Matcher(java.util.regex.Matcher) RiderStageConnectionPresenter(ch.hsr.sa.radiotour.business.presenter.RiderStageConnectionPresenter) Handler(android.os.Handler) View(android.view.View) TimerTask(java.util.TimerTask) Log(android.util.Log) UrlLink(ch.hsr.sa.radiotour.controller.api.UrlLink) RewardPresenter(ch.hsr.sa.radiotour.business.presenter.RewardPresenter) RiderRaceGroupFragment(ch.hsr.sa.radiotour.presentation.fragments.RiderRaceGroupFragment) TimeZone(java.util.TimeZone) StagePresenter(ch.hsr.sa.radiotour.business.presenter.StagePresenter) Fragment(android.support.v4.app.Fragment) MaillotPresenter(ch.hsr.sa.radiotour.business.presenter.MaillotPresenter) RiderPresenter(ch.hsr.sa.radiotour.business.presenter.RiderPresenter) Stage(ch.hsr.sa.radiotour.dataaccess.models.Stage) ActivityCompat(android.support.v4.app.ActivityCompat) AppCompatActivity(android.support.v7.app.AppCompatActivity) ImportFragment(ch.hsr.sa.radiotour.presentation.fragments.ImportFragment) TextView(android.widget.TextView) JudgmentPresenter(ch.hsr.sa.radiotour.business.presenter.JudgmentPresenter) Pattern(java.util.regex.Pattern) Location(android.location.Location) LocationManager(android.location.LocationManager) Context(android.content.Context) VirtualClassFragment(ch.hsr.sa.radiotour.presentation.fragments.VirtualClassFragment) TimePickerDialog(android.app.TimePickerDialog) SpecialFragment(ch.hsr.sa.radiotour.presentation.fragments.SpecialFragment) ViewPager(android.support.v4.view.ViewPager) SimpleDateFormat(java.text.SimpleDateFormat) OnNmeaMessageListener(android.location.OnNmeaMessageListener) TabLayout(android.support.design.widget.TabLayout) RaceGroupPresenter(ch.hsr.sa.radiotour.business.presenter.RaceGroupPresenter) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider) MaillotsFragment(ch.hsr.sa.radiotour.presentation.fragments.MaillotsFragment) DialogInterface(android.content.DialogInterface) JudgmentRiderConnectionPresenter(ch.hsr.sa.radiotour.business.presenter.JudgmentRiderConnectionPresenter) ViewPageAdapter(ch.hsr.sa.radiotour.controller.adapter.ViewPageAdapter) PostHandler(ch.hsr.sa.radiotour.controller.api.PostHandler) RaceGroup(ch.hsr.sa.radiotour.dataaccess.models.RaceGroup) TimeUnit(java.util.concurrent.TimeUnit) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) APIClient(ch.hsr.sa.radiotour.controller.api.APIClient) JSONArray(org.json.JSONArray) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) Handler(android.os.Handler) PostHandler(ch.hsr.sa.radiotour.controller.api.PostHandler) TimePickerDialog(android.app.TimePickerDialog) Time(java.sql.Time) View(android.view.View) TextView(android.widget.TextView) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider) PostHandler(ch.hsr.sa.radiotour.controller.api.PostHandler) RaceGroup(ch.hsr.sa.radiotour.dataaccess.models.RaceGroup) Timer(java.util.Timer) TimerTask(java.util.TimerTask) LocationListener(android.location.LocationListener) Location(android.location.Location)

Example 3 with PostHandler

use of ch.hsr.sa.radiotour.controller.api.PostHandler in project app by TourLive.

the class JudgmentRiderConnectionInstrumentedTest method initTestData.

@Before
public void initTestData() {
    this.judgmentRiderConnectionRepository = new JudgmentRiderConnectionRepository();
    this.riderRepository = new RiderRepository();
    this.judgmentRepository = new JudgmentRepository();
    realm = Realm.getInstance(RadioTourApplication.getInstance());
    initCallbacks();
    realm.executeTransaction((Realm db) -> {
        db.where(JudgmentRiderConnection.class).findAll().deleteAllFromRealm();
        db.where(Rider.class).findAll().deleteAllFromRealm();
        db.where(Judgement.class).findAll().deleteAllFromRealm();
    });
    PostHandler postHandler = new PostHandler();
    postHandler.start();
    APIClient.setDemoMode(true);
}
Also used : RiderRepository(ch.hsr.sa.radiotour.dataaccess.repositories.RiderRepository) IRiderRepository(ch.hsr.sa.radiotour.dataaccess.interfaces.IRiderRepository) PostHandler(ch.hsr.sa.radiotour.controller.api.PostHandler) JudgmentRiderConnectionRepository(ch.hsr.sa.radiotour.dataaccess.repositories.JudgmentRiderConnectionRepository) IJudgmentRiderConnectionRepository(ch.hsr.sa.radiotour.dataaccess.interfaces.IJudgmentRiderConnectionRepository) IJudgmentRepository(ch.hsr.sa.radiotour.dataaccess.interfaces.IJudgmentRepository) JudgmentRepository(ch.hsr.sa.radiotour.dataaccess.repositories.JudgmentRepository) Realm(io.realm.Realm) Before(org.junit.Before)

Example 4 with PostHandler

use of ch.hsr.sa.radiotour.controller.api.PostHandler in project app by TourLive.

the class RiderStageConnectionRepositoryInstrumentedTest method initTestData.

@Before
public void initTestData() {
    this.riderRepository = new RiderRepository();
    this.riderStageConnectionRepository = new RiderStageConnectionRepository();
    realm = Realm.getInstance(RadioTourApplication.getInstance());
    initCallbacks();
    realm.executeTransaction(new Realm.Transaction() {

        @Override
        public void execute(Realm realm) {
            realm.where(Rider.class).findAll().deleteAllFromRealm();
            realm.where(RiderStageConnection.class).findAll().deleteAllFromRealm();
        }
    });
    PostHandler postHandler = new PostHandler();
    postHandler.start();
    APIClient.setDemoMode(true);
}
Also used : RiderRepository(ch.hsr.sa.radiotour.dataaccess.repositories.RiderRepository) IRiderRepository(ch.hsr.sa.radiotour.dataaccess.interfaces.IRiderRepository) IRiderStageConnectionRepository(ch.hsr.sa.radiotour.dataaccess.interfaces.IRiderStageConnectionRepository) RiderStageConnectionRepository(ch.hsr.sa.radiotour.dataaccess.repositories.RiderStageConnectionRepository) PostHandler(ch.hsr.sa.radiotour.controller.api.PostHandler) RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) Realm(io.realm.Realm) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider) Before(org.junit.Before)

Aggregations

PostHandler (ch.hsr.sa.radiotour.controller.api.PostHandler)4 IRiderRepository (ch.hsr.sa.radiotour.dataaccess.interfaces.IRiderRepository)3 Rider (ch.hsr.sa.radiotour.dataaccess.models.Rider)2 RiderRepository (ch.hsr.sa.radiotour.dataaccess.repositories.RiderRepository)2 Realm (io.realm.Realm)2 Before (org.junit.Before)2 Manifest (android.Manifest)1 TimePickerDialog (android.app.TimePickerDialog)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1 Location (android.location.Location)1 LocationListener (android.location.LocationListener)1 LocationManager (android.location.LocationManager)1 OnNmeaMessageListener (android.location.OnNmeaMessageListener)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 TabLayout (android.support.design.widget.TabLayout)1 ActivityCompat (android.support.v4.app.ActivityCompat)1