Search in sources :

Example 41 with Rider

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

the class RiderRaceGroupFragment method onFinishAddingUnknownUser.

@Override
public void onFinishAddingUnknownUser(int count) {
    int start;
    RealmList<Rider> dbUnknownRiders = RiderPresenter.getInstance().getAllUnknownRidersReturned();
    if (dbUnknownRiders == null || dbUnknownRiders.isEmpty()) {
        start = 0;
    } else {
        start = dbUnknownRiders.get(dbUnknownRiders.size() - 1).getStartNr() - 900 + 1;
    }
    unknownRiders = new RealmList<>();
    for (int i = start; i < count + start; i++) {
        Rider rider = new Rider();
        rider.setUnknown(true);
        rider.setName("U" + i);
        rider.setCountry("U");
        rider.setTeamShortName("U");
        rider.setTeamName("UNKNOWN");
        rider.setStartNr(i + 900);
        RiderPresenter.getInstance().addRiderNone(rider);
        unknownRiders.add(RiderPresenter.getInstance().getRiderByStartNr(rider.getStartNr()));
    }
    txtUnknownRiders.setText(getString(R.string.race_unknownrider_value, Integer.toString(count)));
    txtUnknownRiders.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.colorAccent));
}
Also used : Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider)

Example 42 with Rider

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

the class RiderRaceGroupFragment method resetStates.

public void resetStates() {
    stateHandler.post(() -> {
        for (int startNr : resetRiderAnimation) {
            Rider rider = RiderPresenter.getInstance().getRiderByStartNr(startNr);
            RiderStageConnectionPresenter.getInstance().updateRiderState(RiderStateType.AKTIVE, rider);
        }
        resetRiderAnimation.clear();
    });
}
Also used : Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider)

Example 43 with Rider

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

the class Parser method parseRidersAndPersist.

public static void parseRidersAndPersist(JSONArray riders) throws InterruptedException {
    final JSONArray ridersJson = riders;
    Runnable runnable = new Runnable() {

        public void run() {
            for (int i = 0; i < ridersJson.length(); i++) {
                try {
                    JSONObject jsonRider = ridersJson.getJSONObject(i);
                    Rider rider = new Rider();
                    rider.setStartNr(jsonRider.getInt(startNr));
                    rider.setCountry(jsonRider.getString(country));
                    rider.setName(jsonRider.getString(name));
                    rider.setTeamName(jsonRider.getString(team));
                    rider.setTeamShortName(jsonRider.getString(teamShort));
                    rider.setRiderID(jsonRider.getInt(riderID));
                    synchronized (this) {
                        Context.addRider(rider);
                    }
                    RiderStageConnection riderStageConnection = new RiderStageConnection();
                    riderStageConnection.setBonusPoint(0);
                    riderStageConnection.setBonusTime(0);
                    riderStageConnection.setOfficialGap(jsonRider.getLong("timeRueckLong"));
                    riderStageConnection.setOfficialTime(jsonRider.getLong("timeOffLong"));
                    riderStageConnection.setVirtualGap(jsonRider.getLong("timeVirtLong"));
                    String state = jsonRider.getString("active");
                    if (state.equals("true")) {
                        riderStageConnection.setType(RiderStateType.AKTIVE);
                    } else {
                        riderStageConnection.setType(RiderStateType.DNC);
                    }
                    RiderStageConnection riderStageConnectionOne;
                    synchronized (this) {
                        riderStageConnectionOne = Context.addRiderStageConnection(riderStageConnection);
                    }
                    RealmList<RiderStageConnection> riderStageConnections = new RealmList<>();
                    riderStageConnections.add(riderStageConnectionOne);
                    Context.updateRiderStageConnection(rider, riderStageConnections);
                } catch (JSONException e) {
                    Log.d(Parser.class.getSimpleName(), "APP - PARSER - RIDERS - " + e.getMessage());
                }
            }
        }
    };
    Thread threadRiders = new Thread(runnable);
    threadRiders.start();
    threadRiders.join();
    Thread threadGroup = createDefaultGroup();
    threadGroup.start();
    threadGroup.join();
    updateRiderConnectionRankByOfficalGap();
}
Also used : RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) RealmList(io.realm.RealmList) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider)

Example 44 with Rider

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

the class RiderPresenter method subscribeCallbacks.

@Override
public void subscribeCallbacks() {
    onSaveRiderCallback = new IRiderRepository.OnSaveRiderCallback() {

        @Override
        public void onSuccess() {
            for (Fragment frag : fragments) {
                if (frag instanceof RaceFragment) {
                    handler.post(() -> {
                        RaceFragment rF = (RaceFragment) frag;
                        rF.addRiderToList();
                    });
                } else if (frag instanceof RiderRaceGroupFragment) {
                    handler.post(() -> {
                        RiderRaceGroupFragment riderRaceGroupFragment = (RiderRaceGroupFragment) frag;
                        riderRaceGroupFragment.addRiderToList();
                    });
                } else {
                // Do nothing because a not supported fragment
                }
            }
        }

        @Override
        public void onError(String message) {
        // Not needed and therefore not implemented
        }
    };
    onGetAllRidersCallback = new IRiderRepository.OnGetAllRidersCallback() {

        @Override
        public void onSuccess(RealmList<Rider> riders) {
            for (Fragment frag : fragments) {
                if (frag instanceof RaceFragment) {
                    RaceFragment rF = (RaceFragment) frag;
                    rF.showRiders(riders);
                } else if (frag instanceof RiderRaceGroupFragment) {
                    RiderRaceGroupFragment riderRaceGroupFragment = (RiderRaceGroupFragment) frag;
                    riderRaceGroupFragment.showRiders(riders);
                } else if (frag instanceof VirtualClassFragment) {
                    VirtualClassFragment virtualClassFragment = (VirtualClassFragment) frag;
                    virtualClassFragment.updateRiders(riders);
                } else {
                // Do nothing because a not supported fragment
                }
            }
        }

        @Override
        public void onError(String message) {
        // Not needed and therefore not implemented
        }
    };
    onUpdateRiderStateCallback = new IRiderRepository.OnUpdateRiderStageCallback() {

        @Override
        public void onSuccess() {
        // Not needed and therefore not implemented
        }

        @Override
        public void onError(String message) {
        // Not needed and therefore not implemented
        }
    };
}
Also used : RaceFragment(ch.hsr.sa.radiotour.presentation.fragments.RaceFragment) IRiderRepository(ch.hsr.sa.radiotour.dataaccess.interfaces.IRiderRepository) VirtualClassFragment(ch.hsr.sa.radiotour.presentation.fragments.VirtualClassFragment) RiderRaceGroupFragment(ch.hsr.sa.radiotour.presentation.fragments.RiderRaceGroupFragment) VirtualClassFragment(ch.hsr.sa.radiotour.presentation.fragments.VirtualClassFragment) RiderRaceGroupFragment(ch.hsr.sa.radiotour.presentation.fragments.RiderRaceGroupFragment) Fragment(android.support.v4.app.Fragment) RaceFragment(ch.hsr.sa.radiotour.presentation.fragments.RaceFragment) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider)

Example 45 with Rider

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

the class UnknownRiderTransferDialogFramgent method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = LayoutInflater.from(getContext());
    View dialogView = inflater.inflate(R.layout.dialog_unknowntransfer, null);
    alertDialogBuilder.setView(dialogView);
    spinner = dialogView.findViewById(R.id.riderSpinner);
    addItemsToSpinner();
    alertDialogBuilder.setTitle(R.string.race_unknownrider_transfer_title);
    alertDialogBuilder.setMessage(R.string.race_unknownrider_transfer_description);
    alertDialogBuilder.setPositiveButton(R.string.race_unknownrider_transfer_button, (DialogInterface dialog, int which) -> {
        String[] parts = spinner.getItemAtPosition(spinner.getSelectedItemPosition()).toString().split("\\-");
        String startNr = parts[0];
        Log.d("", "" + selectedUnknownRider.toString());
        final int unknownRiderStartNr = selectedUnknownRider.getStartNr();
        new Thread(() -> {
            Rider unknownRider = RiderPresenter.getInstance().getRiderByStartNr(unknownRiderStartNr);
            RaceGroup raceGroup = unknownRider.getRaceGroups();
            RealmList<Rider> rider = new RealmList<>();
            rider.add(getRider(startNr));
            RaceGroupPresenter.getInstance().updateRaceGroupRiders(raceGroup, rider);
            RaceGroupPresenter.getInstance().deleteRiderInRaceGroup(raceGroup, unknownRider);
            RiderPresenter.getInstance().removeRiderWithoutCallback(unknownRider);
        }).start();
    });
    alertDialogBuilder.setNegativeButton(R.string.dismiss, (DialogInterface dialog, int which) -> dialog.dismiss());
    return alertDialogBuilder.create();
}
Also used : AlertDialog(android.app.AlertDialog) RealmList(io.realm.RealmList) DialogInterface(android.content.DialogInterface) View(android.view.View) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider) RaceGroup(ch.hsr.sa.radiotour.dataaccess.models.RaceGroup) LayoutInflater(android.view.LayoutInflater)

Aggregations

Rider (ch.hsr.sa.radiotour.dataaccess.models.Rider)46 RealmList (io.realm.RealmList)17 Realm (io.realm.Realm)13 RaceGroup (ch.hsr.sa.radiotour.dataaccess.models.RaceGroup)9 Test (org.junit.Test)9 RiderStageConnection (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)5 TextView (android.widget.TextView)3 Judgement (ch.hsr.sa.radiotour.dataaccess.models.Judgement)3 JSONException (org.json.JSONException)3 Fragment (android.support.v4.app.Fragment)2 View (android.view.View)2 JudgmentRiderConnection (ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection)2 RiderRanking (ch.hsr.sa.radiotour.dataaccess.models.RiderRanking)2 Manifest (android.Manifest)1 AlertDialog (android.app.AlertDialog)1 TimePickerDialog (android.app.TimePickerDialog)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 PackageManager (android.content.pm.PackageManager)1 Location (android.location.Location)1