Search in sources :

Example 1 with Member

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

the class GameActivity method showPress.

public void showPress() {
    hideAllExcept(R.id.press_view);
    if (member != null) {
        FloatingActionButton button = (FloatingActionButton) findViewById(R.id.create_channel_button);
        button.setVisibility(View.VISIBLE);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                final List<String> nations = new ArrayList<String>();
                for (Member thisMember : game.Members) {
                    if (!member.Nation.equals(thisMember.Nation)) {
                        nations.add(thisMember.Nation);
                    }
                }
                final boolean[] checked = new boolean[nations.size()];
                final AlertDialog dialog = new AlertDialog.Builder(GameActivity.this).setMultiChoiceItems(nations.toArray(new String[] {}), checked, new DialogInterface.OnMultiChoiceClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i, boolean b) {
                        checked[i] = b;
                    }
                }).setTitle(R.string.members).setPositiveButton(R.string.create, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int j) {
                        List<String> channelMembers = new ArrayList<String>();
                        for (int i = 0; i < checked.length; i++) {
                            if (checked[i]) {
                                channelMembers.add(nations.get(i));
                            }
                        }
                        channelMembers.add(member.Nation);
                        Collections.sort(channelMembers);
                        ChannelService.Channel channel = new ChannelService.Channel();
                        channel.GameID = game.ID;
                        channel.Members = channelMembers;
                        PressActivity.startPressActivity(GameActivity.this, game, channel, member);
                        dialogInterface.dismiss();
                    }
                }).show();
            }
        });
    } else {
        findViewById(R.id.create_channel_button).setVisibility(View.GONE);
    }
    handleReq(channelService.ListChannels(game.ID), new Sendable<MultiContainer<ChannelService.Channel>>() {

        @Override
        public void send(MultiContainer<ChannelService.Channel> channelMultiContainer) {
            final List<ChannelService.Channel> channels = new ArrayList<>();
            for (SingleContainer<ChannelService.Channel> channelSingleContainer : channelMultiContainer.Properties) {
                channels.add(channelSingleContainer.Properties);
            }
            ChannelTable channelTable = (ChannelTable) findViewById(R.id.press_channel_table);
            channelTable.setChannels(GameActivity.this, game, member, channels);
        }
    }, getResources().getString(R.string.loading_channels));
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) 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) SingleContainer(se.oort.diplicity.apigen.SingleContainer) MultiContainer(se.oort.diplicity.apigen.MultiContainer) ChannelService(se.oort.diplicity.ChannelService) FloatingActionButton(android.support.design.widget.FloatingActionButton) List(java.util.List) ArrayList(java.util.ArrayList) Member(se.oort.diplicity.apigen.Member)

Example 2 with Member

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

the class UserView method getAvatarClickListener.

public static OnClickListener getAvatarClickListener(final RetrofitActivity retrofitActivity, final Game game, final Member member, final User user) {
    if (game == null) {
        return getAvatarClickListener(retrofitActivity, user);
    }
    Member me = retrofitActivity.getLoggedInMember(game);
    if (me == null || me.Nation.equals(member.Nation)) {
        return getAvatarClickListener(retrofitActivity, user);
    }
    final Member finalMe = me;
    return new OnClickListener() {

        @Override
        public void onClick(View v) {
            retrofitActivity.handleReq(JoinObservable.when(JoinObservable.from(retrofitActivity.userStatsService.UserStatsLoad(user.Id)).and(retrofitActivity.gameStateService.GameStateLoad(game.ID, finalMe.Nation)).and(retrofitActivity.banService.BanLoad(retrofitActivity.getLoggedInUser().Id, user.Id).onErrorReturn(new Func1<Throwable, SingleContainer<Ban>>() {

                @Override
                public SingleContainer<Ban> call(Throwable throwable) {
                    if (throwable instanceof HttpException) {
                        HttpException he = (HttpException) throwable;
                        if (he.code() == 404) {
                            return null;
                        }
                    }
                    throw new RuntimeException(throwable);
                }
            })).then(new Func3<SingleContainer<UserStats>, SingleContainer<GameState>, SingleContainer<Ban>, Object>() {

                @Override
                public Object call(final SingleContainer<UserStats> userStatsSingleContainer, final SingleContainer<GameState> gameStateSingleContainer, final SingleContainer<Ban> banSingleContainer) {
                    AlertDialog dialog = new AlertDialog.Builder(retrofitActivity).setView(R.layout.user_dialog).show();
                    setupUserDialog(retrofitActivity, dialog, userStatsSingleContainer, banSingleContainer);
                    final CheckBox mutedCheckBox = (CheckBox) dialog.findViewById(R.id.muted);
                    mutedCheckBox.setVisibility(VISIBLE);
                    mutedCheckBox.setChecked(gameStateSingleContainer.Properties.Muted != null && gameStateSingleContainer.Properties.Muted.contains(member.Nation));
                    mutedCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            if (isChecked && (gameStateSingleContainer.Properties.Muted == null || !gameStateSingleContainer.Properties.Muted.contains(member.Nation))) {
                                if (gameStateSingleContainer.Properties.Muted == null) {
                                    gameStateSingleContainer.Properties.Muted = new ArrayList<String>();
                                }
                                gameStateSingleContainer.Properties.Muted.add(member.Nation);
                            } else if (!isChecked && gameStateSingleContainer.Properties.Muted != null && gameStateSingleContainer.Properties.Muted.contains(member.Nation)) {
                                gameStateSingleContainer.Properties.Muted.remove(member.Nation);
                            }
                            retrofitActivity.handleReq(retrofitActivity.gameStateService.GameStateUpdate(gameStateSingleContainer.Properties, game.ID, finalMe.Nation), new Sendable<SingleContainer<GameState>>() {

                                @Override
                                public void send(SingleContainer<GameState> gameStateSingleContainer) {
                                }
                            }, retrofitActivity.getResources().getString(R.string.updating));
                        }
                    });
                    return null;
                }
            })).toObservable(), new Sendable<Object>() {

                @Override
                public void send(Object o) {
                }
            }, retrofitActivity.getResources().getString(R.string.loading_user_stats));
        }
    };
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ArrayList(java.util.ArrayList) GameState(se.oort.diplicity.apigen.GameState) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Ban(se.oort.diplicity.apigen.Ban) SingleContainer(se.oort.diplicity.apigen.SingleContainer) UserStats(se.oort.diplicity.apigen.UserStats) CheckBox(android.widget.CheckBox) HttpException(retrofit2.adapter.rxjava.HttpException) Func1(rx.functions.Func1) Member(se.oort.diplicity.apigen.Member) Func3(rx.functions.Func3) CompoundButton(android.widget.CompoundButton)

Example 3 with Member

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

the class GameUnserializer method deserialize.

public Game deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObject = json.getAsJsonObject();
    Game game = baseGson.fromJson(jsonObject, Game.class);
    Member member = retrofitActivity.getLoggedInMember(game);
    if (member != null && game.NewestPhaseMeta != null && game.NewestPhaseMeta.size() > 0 && game.PhaseLengthMinutes > 0) {
        manageAlarms(retrofitActivity, game, member);
    }
    return game;
}
Also used : Game(se.oort.diplicity.apigen.Game) JsonObject(com.google.gson.JsonObject) Member(se.oort.diplicity.apigen.Member)

Example 4 with Member

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

Example 5 with Member

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

the class GameActivity method showGameStates.

public void showGameStates() {
    hideAllExcept(R.id.game_state_view);
    if (member == null) {
        findViewById(R.id.edit_game_state_button).setVisibility(View.GONE);
    }
    handleReq(gameStateService.ListGameStates(game.ID), new Sendable<MultiContainer<GameState>>() {

        @Override
        public void send(MultiContainer<GameState> gameStateMultiContainer) {
            GameState myState = null;
            TableLayout mutedTable = (TableLayout) findViewById(R.id.muted_table);
            mutedTable.removeAllViews();
            FloatingActionButton button = ((FloatingActionButton) mutedTable.findViewById(R.id.open_button));
            if (button != null) {
                mutedTable.removeView(button);
            }
            final List<String> nations = new ArrayList<String>();
            for (Member thisMember : game.Members) {
                if (member == null || !thisMember.Nation.equals(member.Nation)) {
                    nations.add(thisMember.Nation);
                }
                GameState foundState = null;
                for (SingleContainer<GameState> singleContainer : gameStateMultiContainer.Properties) {
                    if (singleContainer.Properties.Nation.equals(thisMember.Nation)) {
                        foundState = singleContainer.Properties;
                    }
                }
                if (member != null && thisMember.Nation.equals(member.Nation)) {
                    myState = foundState;
                }
                TableRow.LayoutParams params = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1.0f);
                int margin = getResources().getDimensionPixelSize(R.dimen.muted_table_margin);
                params.bottomMargin = margin;
                params.topMargin = margin;
                params.leftMargin = margin;
                params.rightMargin = margin;
                TableRow tableRow = new TableRow(GameActivity.this);
                tableRow.setLayoutParams(params);
                LinearLayout playerSide = new LinearLayout(GameActivity.this);
                LinearLayout.LayoutParams linearParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                playerSide.setLayoutParams(params);
                playerSide.setOrientation(LinearLayout.VERTICAL);
                UserView user = new UserView(GameActivity.this, null);
                user.setUser(GameActivity.this, thisMember.User, true);
                user.setLayoutParams(linearParams);
                playerSide.addView(user);
                TextView nation = new TextView(GameActivity.this);
                nation.setText(thisMember.Nation);
                nation.setLayoutParams(linearParams);
                playerSide.addView(nation);
                tableRow.addView(playerSide);
                TextView muteds = new TextView(GameActivity.this);
                muteds.setLayoutParams(params);
                if (foundState != null && foundState.Muted != null) {
                    muteds.setText(TextUtils.join(", ", foundState.Muted));
                } else {
                    muteds.setText("");
                }
                tableRow.addView(muteds);
                mutedTable.addView(tableRow);
            }
            final GameState finalMyState = myState;
            if (finalMyState != null) {
                ((FloatingActionButton) findViewById(R.id.edit_game_state_button)).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        final boolean[] checked = new boolean[nations.size()];
                        if (finalMyState.Muted != null) {
                            for (String muted : finalMyState.Muted) {
                                int pos = nations.indexOf(muted);
                                if (pos > -1) {
                                    checked[pos] = true;
                                }
                            }
                        }
                        final AlertDialog dialog = new AlertDialog.Builder(GameActivity.this).setMultiChoiceItems(nations.toArray(new String[] {}), checked, new DialogInterface.OnMultiChoiceClickListener() {

                            @Override
                            public void onClick(DialogInterface dialogInterface, int i, boolean b) {
                                checked[i] = b;
                            }
                        }).setTitle(R.string.muted).setPositiveButton(R.string.update, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialogInterface, int j) {
                                List<String> mutedMembers = new ArrayList<String>();
                                for (int i = 0; i < checked.length; i++) {
                                    if (checked[i]) {
                                        mutedMembers.add(nations.get(i));
                                    }
                                }
                                Collections.sort(mutedMembers);
                                finalMyState.Muted = mutedMembers;
                                handleReq(gameStateService.GameStateUpdate(finalMyState, game.ID, finalMyState.Nation), new Sendable<SingleContainer<GameState>>() {

                                    @Override
                                    public void send(SingleContainer<GameState> gameStateSingleContainer) {
                                        showGameStates();
                                    }
                                }, getResources().getString(R.string.updating_game_state));
                            }
                        }).show();
                    }
                });
            }
        }
    }, getResources().getString(R.string.loading_game_settings));
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) UserView(se.oort.diplicity.UserView) MultiContainer(se.oort.diplicity.apigen.MultiContainer) FloatingActionButton(android.support.design.widget.FloatingActionButton) List(java.util.List) ArrayList(java.util.ArrayList) TextView(android.widget.TextView) TableLayout(android.widget.TableLayout) Member(se.oort.diplicity.apigen.Member) GameState(se.oort.diplicity.apigen.GameState) 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) SingleContainer(se.oort.diplicity.apigen.SingleContainer) TableRow(android.widget.TableRow) LinearLayout(android.widget.LinearLayout)

Aggregations

Member (se.oort.diplicity.apigen.Member)5 TextView (android.widget.TextView)4 SingleContainer (se.oort.diplicity.apigen.SingleContainer)4 AlertDialog (android.support.v7.app.AlertDialog)3 View (android.view.View)3 ArrayList (java.util.ArrayList)3 DialogInterface (android.content.DialogInterface)2 FloatingActionButton (android.support.design.widget.FloatingActionButton)2 NavigationView (android.support.design.widget.NavigationView)2 AdapterView (android.widget.AdapterView)2 CheckBox (android.widget.CheckBox)2 CompoundButton (android.widget.CompoundButton)2 ListView (android.widget.ListView)2 ScrollView (android.widget.ScrollView)2 TableRow (android.widget.TableRow)2 List (java.util.List)2 UserView (se.oort.diplicity.UserView)2 Game (se.oort.diplicity.apigen.Game)2 GameState (se.oort.diplicity.apigen.GameState)2 MultiContainer (se.oort.diplicity.apigen.MultiContainer)2