Search in sources :

Example 1 with Message

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

FloatingActionButton (android.support.design.widget.FloatingActionButton)1 TextInputEditText (android.support.design.widget.TextInputEditText)1 NestedScrollView (android.support.v4.widget.NestedScrollView)1 Toolbar (android.support.v7.widget.Toolbar)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 View (android.view.View)1 EditText (android.widget.EditText)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Date (java.util.Date)1 ChannelService (se.oort.diplicity.ChannelService)1 Sendable (se.oort.diplicity.Sendable)1 UserView (se.oort.diplicity.UserView)1 Message (se.oort.diplicity.apigen.Message)1 SingleContainer (se.oort.diplicity.apigen.SingleContainer)1 Ticker (se.oort.diplicity.apigen.Ticker)1