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