use of io.realm.RealmList in project app by TourLive.
the class JudgmentRiderConnectionInstrumentedTest method clearAllRewardRiderConnections.
@Test
public void clearAllRewardRiderConnections() {
addRider();
addJudgment();
RealmList<Rider> riderList = new RealmList<>();
RealmList<Judgement> judgementList = new RealmList<>();
riderList.add(RiderPresenter.getInstance().getRiderByStartNr(15));
judgementList.add(JudgmentPresenter.getInstance().getJudgmentsById(93).first());
JudgmentRiderConnection judgmentRiderConnection = new JudgmentRiderConnection();
judgmentRiderConnection.setRank(1);
judgmentRiderConnection.setJudgements(judgementList);
judgmentRiderConnection.setRider(riderList);
synchronized (this) {
judgmentRiderConnectionRepository.addJudgmentRiderConnection(judgmentRiderConnection, onSaveJudgmentRiderConnectionCallback);
}
synchronized (this) {
judgmentRiderConnectionRepository.clearAllJudgmentRiderConnections();
}
Assert.assertEquals(0, realm.where(JudgmentRiderConnection.class).findAll().size());
}
use of io.realm.RealmList in project app by TourLive.
the class RewardRepositoryInstrumentedTest method addReward.
@Test
public void addReward() {
RealmList<Judgement> judgements = new RealmList<>();
RealmResults<Judgement> realmJudgments = realm.where(Judgement.class).findAll();
judgements.addAll(realmJudgments);
Reward reward = new Reward();
reward.setPoints(new RealmList<Integer>(1, 3, 5));
reward.setMoney(new RealmList<Integer>(100, 300, 500));
reward.setType(RewardType.POINTS);
reward.setRewardId(93);
reward.setRewardJudgements(judgements);
synchronized (this) {
rewardRepository.addReward(reward, onSaveRewardCallback);
}
Assert.assertEquals(93, realm.where(Reward.class).findAll().first().getRewardId().intValue());
Assert.assertEquals(300, realm.where(Reward.class).findAll().first().getMoney().get(1).intValue());
Assert.assertEquals(2, realm.where(Reward.class).findAll().first().getRewardJudgements().size());
Assert.assertEquals(93, realm.where(Reward.class).findAll().first().getRewardJudgements().first().getRewardId());
}
use of io.realm.RealmList 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 io.realm.RealmList in project app by TourLive.
the class Parser method parseRewardsAndPersist.
public static void parseRewardsAndPersist(JSONArray rewards) throws InterruptedException {
final JSONArray rewardsJson = rewards;
Runnable runnable = (() -> {
for (int i = 0; i < rewardsJson.length(); i++) {
try {
JSONObject jsonReward = rewardsJson.getJSONObject(i);
Reward reward = new Reward();
RealmList<Integer> moneyList = new RealmList<>();
String[] moneyString = jsonReward.getString("reward").split(",");
for (String s : moneyString) {
moneyList.add(Integer.valueOf(s));
}
reward.setMoney(moneyList);
String bonusType = jsonReward.getString("bonusType");
if (bonusType.equals("time")) {
reward.setType(RewardType.TIME);
}
if (bonusType.equals("points")) {
reward.setType(RewardType.POINTS);
}
RealmList<Integer> bonusList = new RealmList<>();
String[] bonusString = jsonReward.getString("bonus").split(",");
for (String s : bonusString) {
bonusList.add(Integer.valueOf(s));
}
reward.setPoints(bonusList);
reward.setRewardId(jsonReward.getInt("id"));
reward.setRewardJudgements(Context.getJudgmentsById(reward.getRewardId()));
Context.addReward(reward);
} catch (JSONException e) {
Log.d(Parser.class.getSimpleName(), "APP - PARSER - REWARDS - " + e.getMessage());
}
}
});
Thread threadRewards = new Thread(runnable);
threadRewards.start();
threadRewards.join();
}
use of io.realm.RealmList 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