Search in sources :

Example 6 with Reward

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

the class JudgmentDetailFragment method iniList.

private void iniList() {
    textViews.add(rankOne);
    textViews.add(rankTwo);
    textViews.add(rankThree);
    textViews.add(rankFour);
    textViews.add(rankFive);
    textViews.add(rankOne);
    textViews.add(rankTwo);
    textViews.add(rankThree);
    textViews.add(rankFour);
    textViews.add(rankFive);
    headers.add(rankOneTxt);
    headers.add(rankTwoTxt);
    headers.add(rankThreeTxt);
    headers.add(rankFourTxt);
    headers.add(rankFiveTxt);
    headers.add(rankSixTxt);
    headers.add(rankSevenTxt);
    headers.add(rankEightTxt);
    headers.add(rankNineTxt);
    headers.add(rankTenTxt);
    Reward reward = judgement.getRewards();
    for (int i = 0; i < reward.getPoints().size(); i++) {
        headers.get(i).setText(headers.get(i).getText() + getResources().getString(R.string.judgment_points) + reward.getPoints().get(i));
    }
}
Also used : Reward(ch.hsr.sa.radiotour.dataaccess.models.Reward)

Example 7 with Reward

use of ch.hsr.sa.radiotour.dataaccess.models.Reward 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)

Aggregations

Reward (ch.hsr.sa.radiotour.dataaccess.models.Reward)7 Judgement (ch.hsr.sa.radiotour.dataaccess.models.Judgement)3 Test (org.junit.Test)3 RealmList (io.realm.RealmList)2 JudgmentRiderConnection (ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection)1 RiderStageConnection (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)1 Realm (io.realm.Realm)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1