use of br.ufrj.caronae.adapters.ChatMsgsAdapter in project caronae-android by caronae.
the class ChatAct method sendBt.
@OnClick(R.id.send_bt)
public void sendBt() {
final String message = msg_et.getText().toString();
msg_et.setText("");
if (message.isEmpty())
return;
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US).format(new Date());
final ChatMessageReceived msg = new ChatMessageReceived(App.getUser().getName(), App.getUser().getDbId() + "", message, rideId, time);
msg.setId((long) -1);
chatMsgsList.add(msg);
final ChatMsgsAdapter adapter = (ChatMsgsAdapter) chatMsgs_rv.getAdapter();
adapter.notifyItemInserted(chatMsgsList.size() - 1);
chatMsgs_rv.scrollToPosition(chatMsgsList.size() - 1);
CaronaeAPI.service(getApplicationContext()).sendChatMsg(rideId, new ChatSendMessageForJson(message)).enqueue(new Callback<ChatMessageSendResponse>() {
@Override
public void onResponse(Call<ChatMessageSendResponse> call, Response<ChatMessageSendResponse> response) {
if (response.isSuccessful()) {
ChatMessageSendResponse chatMessageSendResponse = response.body();
Log.i("Message Sent", "Sulcefully Send Chat Messages");
msg.setId(Long.parseLong(chatMessageSendResponse.getMessageId()));
chatMsgsList.get(getMessagePositionWithId(chatMsgsList, msg.getId())).setId(Long.parseLong(chatMessageSendResponse.getMessageId()));
msg.save();
} else {
Util.treatResponseFromServer(response);
Util.toast("Erro ao enviar mensagem de chat, verifique sua conexao");
chatMsgsList.remove(chatMsgsList.size() - 1);
chatMsgsAdapter.notifyItemRemoved(chatMsgsList.size());
msg_et.setText(msg.getMessage());
/**
*********** Esconde o teclado **********
*/
View view = ChatAct.this.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
/**
******
*/
Log.e("SendMessages", response.message());
}
}
@Override
public void onFailure(Call<ChatMessageSendResponse> call, Throwable t) {
Util.toast("Erro ao enviar mensagem de chat, verifique sua conexao");
if (chatMsgsList.size() > 0) {
chatMsgsList.remove(chatMsgsList.size() - 1);
chatMsgsAdapter.notifyItemRemoved(chatMsgsList.size());
msg_et.setText(msg.getMessage());
}
/**
*********** Esconde o teclado **********
*/
View view = ChatAct.this.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
/**
******
*/
Log.e("SendMessages", t.getMessage());
}
});
}
use of br.ufrj.caronae.adapters.ChatMsgsAdapter in project caronae-android by caronae.
the class ChatAct method configureActivityWithChatAssets.
private void configureActivityWithChatAssets(ChatAssets chatAssets) {
context = this;
color = chatAssets.getColor();
int colorPressed = Util.getPressedColorbyNormalColor(color);
lay1.setBackgroundColor(color);
toolbar.setBackgroundColor(color);
int bgRes = chatAssets.getBgRes();
// send_bt.setBackgroundResource(bgRes);
send_bt.setColorNormal(color);
send_bt.setColorPressed(colorPressed);
String neighborhood = chatAssets.getLocation();
// neighborhood_tv.setText(neighborhood);
String date = chatAssets.getDate();
// date_tv.setText(date);
String time = chatAssets.getTime();
// time_tv.setText(time);
headerText.setText(neighborhood + " - " + date + " - " + time);
chatMsgsList = ChatMessageReceived.find(ChatMessageReceived.class, "ride_id = ?", rideId);
Collections.sort(chatMsgsList, new ChatMsgComparator());
chatMsgsAdapter = new ChatMsgsAdapter(chatMsgsList, color);
chatMsgs_rv.setAdapter(chatMsgsAdapter);
chatMsgs_rv.setLayoutManager(new LinearLayoutManager(context));
chatMsgsAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
super.onChanged();
Util.toast("mudou");
}
});
if (!chatMsgsList.isEmpty())
chatMsgs_rv.scrollToPosition(chatMsgsList.size() - 1);
}
Aggregations