Search in sources :

Example 1 with SingleContainer

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

the class RetrofitActivity method updateFCMPushOption.

public void updateFCMPushOption(UserConfig userConfig, boolean newValue, String message) {
    FCMToken pushToken = getFCMToken(userConfig);
    if (newValue) {
        if (pushToken == null) {
            pushToken = new FCMToken();
            pushToken.Note = message + " at " + new Date();
            if (userConfig.FCMTokens == null) {
                userConfig.FCMTokens = new ArrayList<FCMToken>();
            }
            userConfig.FCMTokens.add(pushToken);
        } else if (pushToken.Disabled) {
            pushToken.Note = message + " at " + new Date();
        }
        pushToken.Disabled = false;
        pushToken.Value = FirebaseInstanceId.getInstance().getToken();
        pushToken.App = APP_NAME;
        pushToken.ReplaceToken = new BigInteger(8 * 24, random).toString(32);
        pushToken.MessageConfig = new FCMNotificationConfig();
        pushToken.MessageConfig.ClickActionTemplate = MessagingService.FCM_NOTIFY_ACTION;
        pushToken.PhaseConfig = new FCMNotificationConfig();
        pushToken.PhaseConfig.ClickActionTemplate = MessagingService.FCM_NOTIFY_ACTION;
    } else {
        if (pushToken != null && (pushToken.Disabled == null || !pushToken.Disabled)) {
            pushToken.Disabled = true;
            pushToken.Note = message + " at " + new Date();
        }
    }
    if (pushToken != null) {
        final FCMToken finalToken = pushToken;
        handleReq(userConfigService.UserConfigUpdate(userConfig, getLoggedInUser().Id), new Sendable<SingleContainer<UserConfig>>() {

            @Override
            public void send(SingleContainer<UserConfig> userConfigSingleContainer) {
                PreferenceManager.getDefaultSharedPreferences(RetrofitActivity.this).edit().putString(FCM_REPLACE_TOKEN_PREF_KEY, finalToken.ReplaceToken).apply();
            }
        }, getResources().getString(R.string.updating_settings));
    }
}
Also used : SingleContainer(se.oort.diplicity.apigen.SingleContainer) FCMToken(se.oort.diplicity.apigen.FCMToken) BigInteger(java.math.BigInteger) UserConfig(se.oort.diplicity.apigen.UserConfig) Date(java.util.Date) FCMNotificationConfig(se.oort.diplicity.apigen.FCMNotificationConfig)

Example 2 with SingleContainer

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

the class GameActivity method showOrders.

public void showOrders() {
    hideAllExcept(R.id.orders_view);
    handleReq(JoinObservable.when(JoinObservable.from(orderService.ListOrders(game.ID, phaseMeta.PhaseOrdinal.toString())).and(phaseService.PhaseLoad(game.ID, phaseMeta.PhaseOrdinal.toString())).then(new Func2<MultiContainer<Order>, SingleContainer<Phase>, Object>() {

        @Override
        public Object call(MultiContainer<Order> orderMultiContainer, SingleContainer<Phase> phaseSingleContainer) {
            Map<String, String> resultMap = new HashMap<String, String>();
            if (phaseSingleContainer.Properties.Resolutions != null) {
                for (Resolution resolution : phaseSingleContainer.Properties.Resolutions) {
                    resultMap.put(resolution.Province, resolution.Resolution);
                }
            }
            List<String> orders = new ArrayList<String>();
            for (SingleContainer<Order> orderContainer : orderMultiContainer.Properties) {
                String resolution = resultMap.get(orderContainer.Properties.Parts.get(0));
                if (resolution == null) {
                    orders.add(getResources().getString(R.string.nation_order, orderContainer.Properties.Nation, TextUtils.join(" ", orderContainer.Properties.Parts)));
                } else {
                    orders.add(getResources().getString(R.string.nation_order_result, orderContainer.Properties.Nation, TextUtils.join(" ", orderContainer.Properties.Parts), resolution));
                }
            }
            Collections.sort(orders);
            final EditText ordersView = (EditText) findViewById(R.id.orders_view);
            ordersView.setOnTouchListener(new View.OnTouchListener() {

                @Override
                public boolean onTouch(View view, MotionEvent motionEvent) {
                    flickFrameLayout.onTouchEvent(motionEvent);
                    ordersView.onTouchEvent(motionEvent);
                    return true;
                }
            });
            StringBuffer orderBuffer = new StringBuffer();
            for (String order : orders) {
                orderBuffer.append(order + "\n");
            }
            ordersView.setText(orderBuffer);
            return null;
        }
    })).toObservable(), null, getResources().getString(R.string.loading_orders));
}
Also used : Order(se.oort.diplicity.apigen.Order) EditText(android.widget.EditText) Phase(se.oort.diplicity.apigen.Phase) HashMap(java.util.HashMap) 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) SingleContainer(se.oort.diplicity.apigen.SingleContainer) MultiContainer(se.oort.diplicity.apigen.MultiContainer) Func2(rx.functions.Func2) Resolution(se.oort.diplicity.apigen.Resolution)

Example 3 with SingleContainer

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

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

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

the class GameActivity method showMap.

public void showMap() {
    hideAllExcept(R.id.map_view);
    final Sendable<String> renderer = new Sendable<String>() {

        @Override
        public void send(String url) {
            ((MapView) findViewById(R.id.map_view)).load(GameActivity.this, url);
        }
    };
    if (game.Started) {
        findViewById(R.id.rewind).setVisibility(View.VISIBLE);
        FloatingActionButton firstPhaseButton = (FloatingActionButton) findViewById(R.id.rewind);
        if (phaseMeta.PhaseOrdinal < 3) {
            firstPhaseButton.setEnabled(false);
            firstPhaseButton.setAlpha(0.3f);
        } else {
            firstPhaseButton.setEnabled(true);
            firstPhaseButton.setAlpha(1.0f);
            firstPhaseButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    firstPhase();
                }
            });
        }
        findViewById(R.id.previous).setVisibility(View.VISIBLE);
        FloatingActionButton previousPhaseButton = (FloatingActionButton) findViewById(R.id.previous);
        if (phaseMeta.PhaseOrdinal < 2) {
            previousPhaseButton.setEnabled(false);
            previousPhaseButton.setAlpha(0.3f);
        } else {
            previousPhaseButton.setEnabled(true);
            previousPhaseButton.setAlpha(1.0f);
            previousPhaseButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    prevPhase();
                }
            });
        }
        findViewById(R.id.next).setVisibility(View.VISIBLE);
        FloatingActionButton nextPhaseButton = (FloatingActionButton) findViewById(R.id.next);
        if (game.NewestPhaseMeta != null && game.NewestPhaseMeta.get(0).PhaseOrdinal <= phaseMeta.PhaseOrdinal) {
            nextPhaseButton.setEnabled(false);
            nextPhaseButton.setAlpha(0.3f);
        } else {
            nextPhaseButton.setEnabled(true);
            nextPhaseButton.setAlpha(1.0f);
            nextPhaseButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    nextPhase();
                }
            });
        }
        FloatingActionButton lastPhaseButton = (FloatingActionButton) findViewById(R.id.fast_forward);
        if (game.NewestPhaseMeta != null && game.NewestPhaseMeta.get(0).PhaseOrdinal <= phaseMeta.PhaseOrdinal + 1) {
            lastPhaseButton.setEnabled(false);
            lastPhaseButton.setAlpha(0.3f);
        } else {
            lastPhaseButton.setEnabled(true);
            lastPhaseButton.setAlpha(1.0f);
            findViewById(R.id.fast_forward).setVisibility(View.VISIBLE);
            lastPhaseButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    lastPhase();
                }
            });
        }
        String url = getBaseURL() + "Game/" + game.ID + "/Phase/" + phaseMeta.PhaseOrdinal + "/Map";
        if (getLocalDevelopmentMode() && !getLocalDevelopmentModeFakeID().equals("")) {
            url = url + "?fake-id=" + getLocalDevelopmentModeFakeID();
        }
        renderer.send(url);
        if (member != null && !phaseMeta.Resolved) {
            handleReq(JoinObservable.when(JoinObservable.from(optionsService.GetOptions(game.ID, phaseMeta.PhaseOrdinal.toString())).and(orderService.ListOrders(game.ID, phaseMeta.PhaseOrdinal.toString())).and(phaseService.PhaseLoad(game.ID, phaseMeta.PhaseOrdinal.toString())).then(new Func3<SingleContainer<Map<String, OptionsService.Option>>, MultiContainer<Order>, SingleContainer<Phase>, Object>() {

                @Override
                public Object call(SingleContainer<Map<String, OptionsService.Option>> opts, MultiContainer<Order> ords, SingleContainer<Phase> phase) {
                    options = opts.Properties;
                    orders.clear();
                    for (SingleContainer<Order> orderContainer : ords.Properties) {
                        String srcProvince = orderContainer.Properties.Parts.get(0);
                        if (srcProvince.indexOf('/') != -1) {
                            srcProvince = srcProvince.substring(0, srcProvince.indexOf('/'));
                        }
                        orders.put(srcProvince, orderContainer.Properties);
                    }
                    boolean hasBuildOpts = false;
                    boolean hasDisbandOpts = false;
                    for (OptionsService.Option opt : options.values()) {
                        if (opt.Next.containsKey("Build")) {
                            hasBuildOpts = true;
                        }
                        if (opt.Next.containsKey("Disband")) {
                            hasDisbandOpts = true;
                        }
                    }
                    int units = 0;
                    int scs = 0;
                    for (UnitWrapper unit : phase.Properties.Units) {
                        if (unit.Unit.Nation.equals(member.Nation)) {
                            units++;
                        }
                    }
                    for (SC sc : phase.Properties.SCs) {
                        if (sc.Owner.equals(member.Nation)) {
                            scs++;
                        }
                    }
                    if (hasBuildOpts && units < scs) {
                        Toast.makeText(GameActivity.this, getResources().getString(R.string.you_can_build_n_this_phase, getResources().getQuantityString(R.plurals.unit, scs - units, scs - units)), Toast.LENGTH_LONG).show();
                    } else if (hasDisbandOpts && scs < units) {
                        Toast.makeText(GameActivity.this, getResources().getString(R.string.you_have_to_disband_n_this_phase, getResources().getQuantityString(R.plurals.unit, units - scs, units - scs)), Toast.LENGTH_LONG).show();
                    }
                    return null;
                }
            })).toObservable(), new Sendable<Object>() {

                @Override
                public void send(Object o) {
                    acceptOrders();
                }
            }, getResources().getString(R.string.loading_state));
        }
    } else {
        findViewById(R.id.rewind).setVisibility(View.GONE);
        findViewById(R.id.previous).setVisibility(View.GONE);
        findViewById(R.id.next).setVisibility(View.GONE);
        findViewById(R.id.fast_forward).setVisibility(View.GONE);
        handleReq(variantService.GetStartPhase(game.Variant), new Sendable<SingleContainer<VariantService.Phase>>() {

            @Override
            public void send(SingleContainer<VariantService.Phase> phaseSingleContainer) {
                String url = null;
                for (Link link : phaseSingleContainer.Links) {
                    if (link.Rel.equals("map")) {
                        url = link.URL;
                        break;
                    }
                }
                if (url != null) {
                    renderer.send(url);
                } else {
                    App.firebaseCrashReport("No map URL found in variant " + game.Variant + "?");
                    Toast.makeText(getBaseContext(), R.string.unknown_error, Toast.LENGTH_SHORT).show();
                }
            }
        }, getResources().getString(R.string.loading_start_state));
    }
}
Also used : VariantService(se.oort.diplicity.VariantService) Phase(se.oort.diplicity.apigen.Phase) SC(se.oort.diplicity.apigen.SC) MultiContainer(se.oort.diplicity.apigen.MultiContainer) FloatingActionButton(android.support.design.widget.FloatingActionButton) Func3(rx.functions.Func3) Order(se.oort.diplicity.apigen.Order) OptionsService(se.oort.diplicity.OptionsService) UnitWrapper(se.oort.diplicity.apigen.UnitWrapper) 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) Sendable(se.oort.diplicity.Sendable) Map(java.util.Map) HashMap(java.util.HashMap) Link(se.oort.diplicity.apigen.Link)

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