Search in sources :

Example 11 with SingleContainer

use of se.oort.diplicity.apigen.SingleContainer 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 12 with SingleContainer

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

the class RetrofitActivity method performLogin.

protected void performLogin() {
    observe(JoinObservable.when(JoinObservable.from(rootService.GetRoot()).and(variantService.GetVariants()).then(new Func2<RootService.Root, MultiContainer<VariantService.Variant>, Object>() {

        @Override
        public Object call(final RootService.Root root, final MultiContainer<VariantService.Variant> receivedVariants) {
            SharedPreferences.Editor prefEditor = prefs.edit();
            Gson gson = new Gson();
            prefEditor.putString(LOGGED_IN_USER_PREF_KEY, gson.toJson(root.Properties.User));
            loggedInUser = root.Properties.User;
            prefEditor.putString(VARIANTS_PREF_KEY, gson.toJson(receivedVariants));
            variants = receivedVariants;
            prefEditor.apply();
            List<LoginSubscriber<?>> subscribersCopy;
            synchronized (loginSubscribers) {
                subscribersCopy = new ArrayList<LoginSubscriber<?>>(loginSubscribers);
                loginSubscribers.clear();
            }
            for (LoginSubscriber<?> subscriber : subscribersCopy) {
                subscriber.retry();
            }
            if (!prefs.getBoolean(INITIAL_FCM_SETUP_DONE_PREF_KEY, false)) {
                handleReq(userConfigService.UserConfigLoad(root.Properties.User.Id), new Sendable<SingleContainer<UserConfig>>() {

                    @Override
                    public void send(SingleContainer<UserConfig> userConfigSingleContainer) {
                        updateFCMPushOption(userConfigSingleContainer.Properties, true, "Enabled at initial startup");
                        prefs.edit().putBoolean(INITIAL_FCM_SETUP_DONE_PREF_KEY, true).apply();
                    }
                }, getResources().getString(R.string.updating_settings));
            }
            return null;
        }
    })).toObservable(), null, newProgressAndToastHandler(null, getResources().getString(R.string.logging_in)));
}
Also used : SharedPreferences(android.content.SharedPreferences) Gson(com.google.gson.Gson) UserConfig(se.oort.diplicity.apigen.UserConfig) SingleContainer(se.oort.diplicity.apigen.SingleContainer) MultiContainer(se.oort.diplicity.apigen.MultiContainer) Func2(rx.functions.Func2)

Example 13 with SingleContainer

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

Example 14 with SingleContainer

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

the class GameActivity method showPhaseResults.

public void showPhaseResults() {
    setVisibility(View.GONE, R.id.nmr_members, R.id.nmr_members_label, R.id.active_members, R.id.active_members_label, R.id.ready_members, R.id.ready_members_label);
    hideAllExcept(R.id.phase_results_view);
    final ScrollView phaseResultsView = (ScrollView) findViewById(R.id.phase_results_view);
    phaseResultsView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            flickFrameLayout.onTouchEvent(motionEvent);
            phaseResultsView.onTouchEvent(motionEvent);
            return true;
        }
    });
    if (phaseMeta.Resolved) {
        handleReq(phaseResultService.PhaseResultLoad(game.ID, phaseMeta.PhaseOrdinal.toString()), new Sendable<SingleContainer<PhaseResult>>() {

            @Override
            public void send(SingleContainer<PhaseResult> phaseResultSingleContainer) {
                MemberListPopulater populater = new MemberListPopulater();
                if (phaseResultSingleContainer.Properties.NMRUsers != null) {
                    populater.populate(R.id.nmr_members, phaseResultSingleContainer.Properties.NMRUsers);
                    setVisibility(View.VISIBLE, R.id.nmr_members, R.id.nmr_members_label);
                }
                if (phaseResultSingleContainer.Properties.ActiveUsers != null) {
                    populater.populate(R.id.active_members, phaseResultSingleContainer.Properties.ActiveUsers);
                    setVisibility(View.VISIBLE, R.id.active_members, R.id.active_members_label);
                }
                if (phaseResultSingleContainer.Properties.ReadyUsers != null) {
                    populater.populate(R.id.ready_members, phaseResultSingleContainer.Properties.ReadyUsers);
                    setVisibility(View.VISIBLE, R.id.ready_members, R.id.ready_members_label);
                }
            }
        }, new ErrorHandler(404, new Sendable<HttpException>() {

            @Override
            public void send(HttpException e) {
            }
        }), getResources().getString(R.string.loading_phase_result));
    }
}
Also used : 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) SingleContainer(se.oort.diplicity.apigen.SingleContainer) PhaseResult(se.oort.diplicity.apigen.PhaseResult) ScrollView(android.widget.ScrollView) Sendable(se.oort.diplicity.Sendable) HttpException(retrofit2.adapter.rxjava.HttpException)

Example 15 with SingleContainer

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

the class UserView method getAvatarClickListener.

public static OnClickListener getAvatarClickListener(final RetrofitActivity retrofitActivity, final User user) {
    return new OnClickListener() {

        @Override
        public void onClick(View v) {
            retrofitActivity.handleReq(JoinObservable.when(JoinObservable.from(retrofitActivity.userStatsService.UserStatsLoad(user.Id)).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 Func2<SingleContainer<UserStats>, SingleContainer<Ban>, Object>() {

                @Override
                public Object call(SingleContainer<UserStats> userStatsSingleContainer, SingleContainer<Ban> banSingleContainer) {
                    AlertDialog dialog = new AlertDialog.Builder(retrofitActivity).setView(R.layout.user_dialog).show();
                    setupUserDialog(retrofitActivity, dialog, userStatsSingleContainer, banSingleContainer);
                    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) 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) HttpException(retrofit2.adapter.rxjava.HttpException) Func1(rx.functions.Func1) Func2(rx.functions.Func2)

Aggregations

SingleContainer (se.oort.diplicity.apigen.SingleContainer)17 TextView (android.widget.TextView)13 View (android.view.View)12 AdapterView (android.widget.AdapterView)9 ArrayList (java.util.ArrayList)8 UserView (se.oort.diplicity.UserView)8 NavigationView (android.support.design.widget.NavigationView)7 ListView (android.widget.ListView)7 ScrollView (android.widget.ScrollView)7 MultiContainer (se.oort.diplicity.apigen.MultiContainer)7 FloatingActionButton (android.support.design.widget.FloatingActionButton)6 AlertDialog (android.support.v7.app.AlertDialog)6 List (java.util.List)4 HttpException (retrofit2.adapter.rxjava.HttpException)4 Sendable (se.oort.diplicity.Sendable)4 Ban (se.oort.diplicity.apigen.Ban)4 Member (se.oort.diplicity.apigen.Member)4 MotionEvent (android.view.MotionEvent)3 CheckBox (android.widget.CheckBox)3 CompoundButton (android.widget.CompoundButton)3