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();
}
Aggregations