Search in sources :

Example 31 with RealmList

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());
}
Also used : RealmList(io.realm.RealmList) Judgement(ch.hsr.sa.radiotour.dataaccess.models.Judgement) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider) JudgmentRiderConnection(ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection) Test(org.junit.Test)

Example 32 with RealmList

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());
}
Also used : Judgement(ch.hsr.sa.radiotour.dataaccess.models.Judgement) RealmList(io.realm.RealmList) Reward(ch.hsr.sa.radiotour.dataaccess.models.Reward) Test(org.junit.Test)

Example 33 with RealmList

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();
}
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 34 with RealmList

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();
}
Also used : RealmList(io.realm.RealmList) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Reward(ch.hsr.sa.radiotour.dataaccess.models.Reward)

Example 35 with RealmList

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

RealmList (io.realm.RealmList)39 Realm (io.realm.Realm)23 Rider (ch.hsr.sa.radiotour.dataaccess.models.Rider)17 Test (org.junit.Test)8 RaceGroup (ch.hsr.sa.radiotour.dataaccess.models.RaceGroup)7 Judgement (ch.hsr.sa.radiotour.dataaccess.models.Judgement)6 RiderStageConnection (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)6 JudgmentRiderConnection (ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection)4 Scheduler (io.reactivex.Scheduler)4 DynamicRealm (io.realm.DynamicRealm)4 RealmConfiguration (io.realm.RealmConfiguration)4 DialogInterface (android.content.DialogInterface)2 View (android.view.View)2 Maillot (ch.hsr.sa.radiotour.dataaccess.models.Maillot)2 Reward (ch.hsr.sa.radiotour.dataaccess.models.Reward)2 EmailRealm (com.xabber.android.data.database.realm.EmailRealm)2 SocialBindingRealm (com.xabber.android.data.database.realm.SocialBindingRealm)2 SyncStateRealm (com.xabber.android.data.database.realm.SyncStateRealm)2 XMPPUserRealm (com.xabber.android.data.database.realm.XMPPUserRealm)2 XabberAccountRealm (com.xabber.android.data.database.realm.XabberAccountRealm)2