Search in sources :

Example 16 with SingleContainer

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

the class UserView method setupUserDialog.

private static void setupUserDialog(final RetrofitActivity retrofitActivity, AlertDialog dialog, final SingleContainer<UserStats> userStats, final SingleContainer<Ban> ban) {
    ((UserStatsTable) dialog.findViewById(R.id.user_stats)).setUserStats(retrofitActivity, userStats.Properties);
    ((UserView) dialog.findViewById(R.id.user)).setUser(retrofitActivity, userStats.Properties.User, true);
    final CheckBox bannedCheckBox = (CheckBox) dialog.findViewById(R.id.banned);
    if (userStats.Properties.UserId.equals(retrofitActivity.getLoggedInUser().Id)) {
        bannedCheckBox.setVisibility(GONE);
    } else {
        bannedCheckBox.setVisibility(VISIBLE);
        bannedCheckBox.setChecked(ban != null);
        bannedCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    Ban ban = new Ban();
                    ban.UserIds = new ArrayList<String>();
                    ban.UserIds.add(userStats.Properties.UserId);
                    ban.UserIds.add(retrofitActivity.getLoggedInUser().Id);
                    retrofitActivity.handleReq(retrofitActivity.banService.BanCreate(ban, retrofitActivity.getLoggedInUser().Id), new Sendable<SingleContainer<Ban>>() {

                        @Override
                        public void send(SingleContainer<Ban> banSingleContainer) {
                        }
                    }, retrofitActivity.getResources().getString(R.string.updating));
                } else {
                    retrofitActivity.handleReq(retrofitActivity.banService.BanDelete(retrofitActivity.getLoggedInUser().Id, userStats.Properties.UserId), new Sendable<SingleContainer<Ban>>() {

                        @Override
                        public void send(SingleContainer<Ban> banSingleContainer) {
                        }
                    }, retrofitActivity.getResources().getString(R.string.updating));
                }
            }
        });
    }
    dialog.findViewById(R.id.muted).setVisibility(GONE);
    ((Button) dialog.findViewById(R.id.other_finished_game_button)).setOnClickListener(getOtherGamesClickListener(retrofitActivity, userStats.Properties.User, MainActivity.FINISHED));
    ((Button) dialog.findViewById(R.id.other_staging_game_button)).setOnClickListener(getOtherGamesClickListener(retrofitActivity, userStats.Properties.User, MainActivity.STAGING));
    ((Button) dialog.findViewById(R.id.other_started_game_button)).setOnClickListener(getOtherGamesClickListener(retrofitActivity, userStats.Properties.User, MainActivity.STARTED));
}
Also used : SingleContainer(se.oort.diplicity.apigen.SingleContainer) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) CheckBox(android.widget.CheckBox) ArrayList(java.util.ArrayList) CompoundButton(android.widget.CompoundButton) Ban(se.oort.diplicity.apigen.Ban)

Example 17 with SingleContainer

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

the class PressActivity method onPostCreate.

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    setContentView(R.layout.activity_press);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    byte[] serializedMember = getIntent().getByteArrayExtra(SERIALIZED_MEMBER_KEY);
    if (serializedMember != null) {
        member = (Member) unserialize(serializedMember);
    }
    byte[] serializedChannel = getIntent().getByteArrayExtra(SERIALIZED_CHANNEL_KEY);
    channel = (ChannelService.Channel) unserialize(serializedChannel);
    byte[] serializedGame = getIntent().getByteArrayExtra(SERIALIZED_GAME_KEY);
    game = (Game) unserialize(serializedGame);
    ((TextView) findViewById(R.id.multi_line_title)).setText(TextUtils.join(", ", channel.Members));
    if (member == null) {
        findViewById(R.id.send_message_button).setVisibility(View.GONE);
        findViewById(R.id.new_message_body).setVisibility(View.GONE);
    } else {
        final TextInputEditText body = (TextInputEditText) findViewById(R.id.new_message_body);
        body.setText(prefs.getString(draftKey(), ""));
        body.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                prefs.edit().putString(draftKey(), body.getText().toString()).apply();
            }
        });
        ((FloatingActionButton) findViewById(R.id.send_message_button)).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Message message = new Message();
                message.Body = ((EditText) findViewById(R.id.new_message_body)).getText().toString();
                message.ChannelMembers = channel.Members;
                message.CreatedAt = new Date();
                message.Age = new Ticker(new Date(), (long) 0);
                message.GameID = channel.GameID;
                message.Sender = member.Nation;
                handleReq(messageService.MessageCreate(message, channel.GameID), new Sendable<SingleContainer<Message>>() {

                    @Override
                    public void send(SingleContainer<Message> messageSingleContainer) {
                        ((EditText) findViewById(R.id.new_message_body)).setText("");
                        prefs.edit().putString(draftKey(), "").apply();
                        loadMessages(false);
                    }
                }, getResources().getString(R.string.sending_message));
            }
        });
    }
    loadMessages(true);
    Toast.makeText(this, R.string.all_press_becomes_public, Toast.LENGTH_SHORT).show();
}
Also used : TextInputEditText(android.support.design.widget.TextInputEditText) EditText(android.widget.EditText) Message(se.oort.diplicity.apigen.Message) Ticker(se.oort.diplicity.apigen.Ticker) ImageView(android.widget.ImageView) UserView(se.oort.diplicity.UserView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) Date(java.util.Date) SingleContainer(se.oort.diplicity.apigen.SingleContainer) ChannelService(se.oort.diplicity.ChannelService) Sendable(se.oort.diplicity.Sendable) TextInputEditText(android.support.design.widget.TextInputEditText) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) FloatingActionButton(android.support.design.widget.FloatingActionButton) TextView(android.widget.TextView) Toolbar(android.support.v7.widget.Toolbar)

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