Search in sources :

Example 6 with MultiContainer

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

the class MainActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        Intent i = new Intent(this, PreferenceActivity.class);
        startActivity(i);
        return true;
    } else if (id == R.id.action_error_log) {
        AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).setView(R.layout.error_log_dialog).show();
        ((EditText) dialog.findViewById(R.id.error_log)).setText(App.errorLog.toString());
    } else if (id == R.id.action_forum) {
        String url = "https://groups.google.com/forum/#!forum/diplicity-talk";
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
    } else if (id == R.id.action_source) {
        String url = "https://github.com/zond/android-diplicity";
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
    } else if (id == R.id.action_alarms) {
        AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).setView(R.layout.alarms_dialog).show();
        Map<String, ?> alarms = Alarm.getAlarmPreferences(this).getAll();
        LinearLayout layout = (LinearLayout) dialog.findViewById(R.id.alarms_list);
        if (alarms.size() == 0) {
            dialog.findViewById(R.id.empty_view).setVisibility(View.VISIBLE);
            layout.setVisibility(View.GONE);
        } else {
            dialog.findViewById(R.id.empty_view).setVisibility(View.GONE);
            for (Object json : Alarm.getAlarmPreferences(this).getAll().values()) {
                Alarm.Alert alert = Alarm.Alert.fromJSON("" + json);
                LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View row = inflater.inflate(R.layout.alarm_list_row, null);
                ((TextView) row.findViewById(R.id.desc)).setText(alert.desc);
                ((TextView) row.findViewById(R.id.at)).setText(alert.alertAt(this).toString());
                layout.addView(row);
            }
            layout.setVisibility(View.VISIBLE);
        }
    } else if (id == R.id.action_bans) {
        handleReq(banService.ListBans(getLoggedInUser().Id), new Sendable<MultiContainer<Ban>>() {

            private RelativeLayout.LayoutParams wrapContentParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

            private void setMargins(RelativeLayout.LayoutParams params) {
                int margin = getResources().getDimensionPixelSize(R.dimen.member_table_margin);
                params.bottomMargin = margin;
                params.topMargin = margin;
                params.leftMargin = margin;
                params.rightMargin = margin;
            }

            private void setupView(final AlertDialog dialog, final MultiContainer<Ban> banMultiContainer, final SingleContainer<Ban> ban, View convertView) {
                User other = null;
                for (User u : ban.Properties.Users) {
                    if (!u.Id.equals(getLoggedInUser().Id)) {
                        other = u;
                        break;
                    }
                }
                if (other != null) {
                    final User finalOther = other;
                    ((UserView) convertView.findViewById(R.id.other_user)).setUser(MainActivity.this, other, true);
                    if (ban.Properties.OwnerIds.contains(getLoggedInUser().Id)) {
                        LayoutInflater inflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                        FloatingActionButton button = (FloatingActionButton) inflater.inflate(R.layout.clear_button, null);
                        setMargins(wrapContentParams);
                        wrapContentParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                        wrapContentParams.addRule(RelativeLayout.ALIGN_PARENT_END);
                        wrapContentParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                        button.setLayoutParams(wrapContentParams);
                        button.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                handleReq(banService.BanDelete(getLoggedInUser().Id, finalOther.Id), new Sendable<SingleContainer<Ban>>() {

                                    @Override
                                    public void send(SingleContainer<Ban> banSingleContainer) {
                                        ban.Properties.OwnerIds.remove(getLoggedInUser().Id);
                                        if (ban.Properties.OwnerIds.isEmpty()) {
                                            banMultiContainer.Properties.remove(ban);
                                        }
                                        setupDialog(dialog, banMultiContainer);
                                    }
                                }, getResources().getString(R.string.updating));
                            }
                        });
                        ((RelativeLayout) convertView.findViewById(R.id.ban_list_row_layout)).addView(button);
                    }
                }
            }

            @Override
            public void send(MultiContainer<Ban> banMultiContainer) {
                AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).setView(R.layout.bans_dialog).show();
                setupDialog(dialog, banMultiContainer);
            }

            private void setupDialog(AlertDialog dialog, MultiContainer<Ban> banMultiContainer) {
                List<SingleContainer<Ban>> asBannerList = new ArrayList<>();
                List<SingleContainer<Ban>> asBannedList = new ArrayList<>();
                for (SingleContainer<Ban> banSingleContainer : banMultiContainer.Properties) {
                    if (banSingleContainer.Properties.OwnerIds.contains(getLoggedInUser().Id)) {
                        asBannerList.add(banSingleContainer);
                    } else {
                        asBannedList.add(banSingleContainer);
                    }
                }
                ViewGroup parent = (ViewGroup) dialog.findViewById(R.id.bans_dialog_layout);
                LinearLayout asBanner = (LinearLayout) dialog.findViewById(R.id.hater_list);
                if (asBannerList.isEmpty()) {
                    dialog.findViewById(R.id.as_banner_no_data).setVisibility(View.VISIBLE);
                    asBanner.setVisibility(View.GONE);
                } else {
                    dialog.findViewById(R.id.as_banner_no_data).setVisibility(View.GONE);
                    asBanner.removeAllViews();
                    for (SingleContainer<Ban> ban : asBannerList) {
                        View itemView = LayoutInflater.from(MainActivity.this).inflate(R.layout.ban_list_row, parent, false);
                        asBanner.addView(itemView);
                        setupView(dialog, banMultiContainer, ban, itemView);
                    }
                }
                LinearLayout asBanned = (LinearLayout) dialog.findViewById(R.id.hated_list);
                if (asBannedList.isEmpty()) {
                    dialog.findViewById(R.id.as_banned_no_data).setVisibility(View.VISIBLE);
                    asBanned.setVisibility(View.GONE);
                } else {
                    dialog.findViewById(R.id.as_banner_no_data).setVisibility(View.GONE);
                    asBanned.removeAllViews();
                    for (SingleContainer<Ban> ban : asBannedList) {
                        View itemView = LayoutInflater.from(MainActivity.this).inflate(R.layout.ban_list_row, parent, false);
                        asBanned.addView(itemView);
                        setupView(dialog, banMultiContainer, ban, itemView);
                    }
                }
            }
        }, getResources().getString(R.string.loading_bans));
    }
    return super.onOptionsItemSelected(item);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) User(se.oort.diplicity.apigen.User) ArrayList(java.util.ArrayList) MultiContainer(se.oort.diplicity.apigen.MultiContainer) FloatingActionButton(android.support.design.widget.FloatingActionButton) TextView(android.widget.TextView) ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ExpandableListView(android.widget.ExpandableListView) Ban(se.oort.diplicity.apigen.Ban) SingleContainer(se.oort.diplicity.apigen.SingleContainer) LayoutInflater(android.view.LayoutInflater) RelativeLayout(android.widget.RelativeLayout) LinearLayout(android.widget.LinearLayout)

Example 7 with MultiContainer

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

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

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

the class GameActivity method showPhases.

public void showPhases(boolean loadPhases) {
    hideAllExcept(R.id.phases_view);
    final Sendable<MultiContainer<Phase>> renderer = new Sendable<MultiContainer<Phase>>() {

        @Override
        public void send(MultiContainer<Phase> phaseMultiContainer) {
            final List<PhaseElement> phases = new ArrayList<>();
            for (int i = 0; i < phaseMultiContainer.Properties.size(); i++) {
                phases.add(new PhaseElement(phaseMultiContainer.Properties.get(phaseMultiContainer.Properties.size() - i - 1).Properties));
            }
            ListView phasesView = (ListView) findViewById(R.id.phases_view);
            phasesView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                    Gson gson = new Gson();
                    phaseMeta = gson.fromJson(gson.toJson(phases.get(i).phase), PhaseMeta.class);
                    currentView = R.id.nav_map;
                    showMap();
                }
            });
            phasesView.setAdapter(new ArrayAdapter<PhaseElement>(GameActivity.this, android.R.layout.simple_list_item_1, phases));
        }
    };
    if (loadPhases || phases == null) {
        handleReq(phaseService.ListPhases(game.ID), new Sendable<MultiContainer<Phase>>() {

            @Override
            public void send(MultiContainer<Phase> phaseMultiContainer) {
                phases = phaseMultiContainer;
                renderer.send(phaseMultiContainer);
            }
        }, getResources().getString(R.string.loading_phases));
    } else {
        renderer.send(phases);
    }
}
Also used : Phase(se.oort.diplicity.apigen.Phase) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) 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) ListView(android.widget.ListView) MultiContainer(se.oort.diplicity.apigen.MultiContainer) Sendable(se.oort.diplicity.Sendable) AdapterView(android.widget.AdapterView)

Aggregations

MultiContainer (se.oort.diplicity.apigen.MultiContainer)9 View (android.view.View)7 AdapterView (android.widget.AdapterView)7 TextView (android.widget.TextView)7 SingleContainer (se.oort.diplicity.apigen.SingleContainer)7 NavigationView (android.support.design.widget.NavigationView)6 ListView (android.widget.ListView)6 ScrollView (android.widget.ScrollView)6 ArrayList (java.util.ArrayList)6 UserView (se.oort.diplicity.UserView)6 FloatingActionButton (android.support.design.widget.FloatingActionButton)4 AlertDialog (android.support.v7.app.AlertDialog)3 List (java.util.List)3 Phase (se.oort.diplicity.apigen.Phase)3 DialogInterface (android.content.DialogInterface)2 MotionEvent (android.view.MotionEvent)2 LinearLayout (android.widget.LinearLayout)2 Gson (com.google.gson.Gson)2 HashMap (java.util.HashMap)2 Func2 (rx.functions.Func2)2