Search in sources :

Example 1 with PhaseState

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

the class GameActivity method showPhaseStates.

public void showPhaseStates() {
    hideAllExcept(R.id.phase_state_view);
    final MemberTable phaseStateView = (MemberTable) findViewById(R.id.phase_state_view);
    phaseStateView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            flickFrameLayout.onTouchEvent(motionEvent);
            phaseStateView.onTouchEvent(motionEvent);
            return true;
        }
    });
    handleReq(phaseStateService.ListPhaseStates(game.ID, phaseMeta.PhaseOrdinal.toString()), new Sendable<MultiContainer<PhaseState>>() {

        @Override
        public void send(MultiContainer<PhaseState> phaseStateMultiContainer) {
            List<PhaseState> phaseStates = new ArrayList<PhaseState>();
            for (SingleContainer<PhaseState> phaseStateSingleContainer : phaseStateMultiContainer.Properties) {
                phaseStates.add(phaseStateSingleContainer.Properties);
            }
            phaseStateView.setPhaseStates(game, phaseMeta, phaseStates);
            phaseStateView.setMembers(GameActivity.this, game, game.Members);
        }
    }, getResources().getString(R.string.loading_phase_settings));
}
Also used : MemberTable(se.oort.diplicity.MemberTable) SingleContainer(se.oort.diplicity.apigen.SingleContainer) MultiContainer(se.oort.diplicity.apigen.MultiContainer) PhaseState(se.oort.diplicity.apigen.PhaseState) List(java.util.List) ArrayList(java.util.ArrayList) NavigationView(android.support.design.widget.NavigationView) UserView(se.oort.diplicity.UserView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ScrollView(android.widget.ScrollView) MotionEvent(android.view.MotionEvent)

Example 2 with PhaseState

use of se.oort.diplicity.apigen.PhaseState 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

TextView (android.widget.TextView)2 PhaseState (se.oort.diplicity.apigen.PhaseState)2 SingleContainer (se.oort.diplicity.apigen.SingleContainer)2 NavigationView (android.support.design.widget.NavigationView)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 CheckBox (android.widget.CheckBox)1 CompoundButton (android.widget.CompoundButton)1 ListView (android.widget.ListView)1 ScrollView (android.widget.ScrollView)1 TableRow (android.widget.TableRow)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MemberTable (se.oort.diplicity.MemberTable)1 UserView (se.oort.diplicity.UserView)1 Game (se.oort.diplicity.apigen.Game)1 GameScore (se.oort.diplicity.apigen.GameScore)1 Member (se.oort.diplicity.apigen.Member)1 MultiContainer (se.oort.diplicity.apigen.MultiContainer)1