Search in sources :

Example 1 with GameScore

use of se.oort.diplicity.apigen.GameScore in project android-diplicity by zond.

the class MemberTable method setMembers.

public void setMembers(final RetrofitActivity retrofitActivity, Game game, final List<Member> members) {
    removeAllViews();
    for (final Member member : members) {
        boolean rowOK = true;
        TableRow tableRow = new TableRow(retrofitActivity);
        TableRow.LayoutParams rowParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
        tableRow.setLayoutParams(rowParams);
        UserView userView = new UserView(retrofitActivity, attributeSet);
        TableRow.LayoutParams userParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1.0f);
        setMargins(userParams);
        userView.setLayoutParams(userParams);
        userView.setMember(retrofitActivity, game, member, member.User, this.phaseStates == null);
        tableRow.addView(userView);
        if (member.Nation != null && !member.Nation.equals("")) {
            TextView nation = new TextView(retrofitActivity);
            nation.setLayoutParams(wrapContentParams);
            nation.setText(member.Nation);
            tableRow.addView(nation);
        }
        if (this.scores != null) {
            GameScore foundScore = null;
            for (GameScore score : scores) {
                if (score.UserId.equals(member.User.Id)) {
                    foundScore = score;
                    break;
                }
            }
            if (foundScore != null) {
                TextView scs = new TextView(retrofitActivity);
                scs.setLayoutParams(wrapContentParams);
                scs.setText(getResources().getString(R.string._scs, foundScore.SCs));
                tableRow.addView(scs);
                TextView points = new TextView(retrofitActivity);
                points.setLayoutParams(wrapContentParams);
                points.setText(getResources().getString(R.string._points, retrofitActivity.toString(foundScore.Score)));
                tableRow.addView(points);
            }
        }
        if (this.phaseStates != null) {
            PhaseState foundState = null;
            for (PhaseState state : phaseStates) {
                if (state.Nation.equals(member.Nation)) {
                    foundState = state;
                    break;
                }
            }
            if (foundState != null) {
                final PhaseState finalFoundState = foundState;
                final CheckBox onProbation = new CheckBox(retrofitActivity);
                final CheckBox readyToResolve = new CheckBox(retrofitActivity);
                readyToResolve.setText(R.string.rdy);
                readyToResolve.setLayoutParams(wrapContentParams);
                readyToResolve.setChecked(finalFoundState.ReadyToResolve);
                if (!foundState.NoOrders && !phaseMeta.Resolved && retrofitActivity.getLoggedInUser().Id.equals(member.User.Id)) {
                    final Game finalGame = game;
                    readyToResolve.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                            finalFoundState.ReadyToResolve = b;
                            retrofitActivity.handleReq(retrofitActivity.phaseStateService.PhaseStateUpdate(finalFoundState, MemberTable.this.game.ID, phaseMeta.PhaseOrdinal.toString(), member.Nation), new Sendable<SingleContainer<PhaseState>>() {

                                @Override
                                public void send(SingleContainer<PhaseState> phaseStateSingleContainer) {
                                    if (readyToResolve.isChecked()) {
                                        Alarm.Alert.fromGame(finalGame, member).turnOff(retrofitActivity);
                                    }
                                    onProbation.setChecked(false);
                                }
                            }, getResources().getString(R.string.updating_phase_state));
                        }
                    });
                    readyToResolve.setEnabled(true);
                } else {
                    readyToResolve.setEnabled(false);
                }
                tableRow.addView(readyToResolve);
                CheckBox wantsDIAS = new CheckBox(retrofitActivity);
                wantsDIAS.setText(R.string.DRAW);
                wantsDIAS.setLayoutParams(wrapContentParams);
                wantsDIAS.setChecked(finalFoundState.WantsDIAS);
                if (!foundState.Eliminated && !phaseMeta.Resolved && retrofitActivity.getLoggedInUser().Id.equals(member.User.Id)) {
                    wantsDIAS.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                            finalFoundState.WantsDIAS = b;
                            retrofitActivity.handleReq(retrofitActivity.phaseStateService.PhaseStateUpdate(finalFoundState, MemberTable.this.game.ID, phaseMeta.PhaseOrdinal.toString(), member.Nation), new Sendable<SingleContainer<PhaseState>>() {

                                @Override
                                public void send(SingleContainer<PhaseState> phaseStateSingleContainer) {
                                    onProbation.setChecked(false);
                                }
                            }, getResources().getString(R.string.updating_phase_state));
                        }
                    });
                } else {
                    wantsDIAS.setEnabled(false);
                }
                tableRow.addView(wantsDIAS);
                onProbation.setText(R.string.nmr);
                onProbation.setLayoutParams(wrapContentParams);
                onProbation.setChecked(finalFoundState.OnProbation);
                onProbation.setEnabled(false);
                tableRow.addView(onProbation);
            } else {
                rowOK = false;
            }
        }
        if (rowOK) {
            addView(tableRow);
        }
    }
}
Also used : GameScore(se.oort.diplicity.apigen.GameScore) SingleContainer(se.oort.diplicity.apigen.SingleContainer) Game(se.oort.diplicity.apigen.Game) PhaseState(se.oort.diplicity.apigen.PhaseState) CheckBox(android.widget.CheckBox) TableRow(android.widget.TableRow) TextView(android.widget.TextView) Member(se.oort.diplicity.apigen.Member) CompoundButton(android.widget.CompoundButton)

Aggregations

CheckBox (android.widget.CheckBox)1 CompoundButton (android.widget.CompoundButton)1 TableRow (android.widget.TableRow)1 TextView (android.widget.TextView)1 Game (se.oort.diplicity.apigen.Game)1 GameScore (se.oort.diplicity.apigen.GameScore)1 Member (se.oort.diplicity.apigen.Member)1 PhaseState (se.oort.diplicity.apigen.PhaseState)1 SingleContainer (se.oort.diplicity.apigen.SingleContainer)1