use of com.yellowmessenger.sdk.models.db.ChatMessage in project yellowmessenger-sdk by yellowmessenger.
the class ChatListAdapter method getQuestionView.
private View getQuestionView(int position, View convertView, ViewGroup parent) {
View view = convertView;
final ChatMessage chatMessage = values.get(position);
QuestionViewHolder questionViewHolder = null;
if (view == null) {
view = inflater.inflate(R.layout.chat_list_item_question, parent, false);
questionViewHolder = new QuestionViewHolder();
questionViewHolder.message = (TextView) view.findViewById(R.id.message);
questionViewHolder.timestamp = (TextView) view.findViewById(R.id.timestamp);
questionViewHolder.actionButton = view.findViewById(R.id.action_button);
questionViewHolder.actionText = (TextView) view.findViewById(R.id.action_text);
for (int i = 0; i < 10; i++) {
View optionView = inflater.inflate(R.layout.options_view, parent, false);
((ViewGroup) view.findViewById(R.id.persistentOptions)).addView(optionView);
questionViewHolder.persistentOptions.add(optionView);
}
view.setTag(questionViewHolder);
} else {
questionViewHolder = (QuestionViewHolder) view.getTag();
}
final Question question = chatMessage.getChatResponse().getQuestion();
questionViewHolder.message.setText(chatMessage.getChatResponse().getQuestion().getQuestion());
if (question.getAction() != null) {
questionViewHolder.actionButton.setVisibility(View.VISIBLE);
questionViewHolder.actionText.setText(question.getAction().getLabel());
questionViewHolder.actionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((ChatActivity) context).sendOptionEvent(new SendOptionEvent(question.getAction()));
}
});
} else {
questionViewHolder.actionButton.setVisibility(GONE);
}
for (View optionView : questionViewHolder.persistentOptions) {
optionView.setVisibility(GONE);
optionView.findViewById(R.id.button_1).setVisibility(GONE);
optionView.findViewById(R.id.button_2).setVisibility(GONE);
optionView.findViewById(R.id.button_3).setVisibility(GONE);
}
if (question.isPersistentOptions() && question.getOptions() != null && question.getOptions().size() > 0) {
for (int i = 0; i < question.getOptions().size(); i++) {
View optionView = questionViewHolder.persistentOptions.get(i / 3);
optionView.setVisibility(View.VISIBLE);
int buttonNumber = i % 3;
TextView button = null;
if (buttonNumber == 0) {
button = (TextView) optionView.findViewById(R.id.button_1);
} else if (buttonNumber == 1) {
button = (TextView) optionView.findViewById(R.id.button_2);
} else {
button = (TextView) optionView.findViewById(R.id.button_3);
}
final Option option = question.getOptions().get(i);
button.setVisibility(View.VISIBLE);
button.setText(question.getOptions().get(i).getLabel());
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((ChatActivity) context).sendOptionEvent(new SendOptionEvent(option));
}
});
}
}
try {
questionViewHolder.timestamp.setText(DateUtils.getRelativeTimeSpanString(format.parse(values.get(position).getTimestamp()).getTime(), (new Date()).getTime(), DateUtils.FORMAT_ABBREV_RELATIVE).toString());
} catch (ParseException e) {
e.printStackTrace();
}
return view;
}
use of com.yellowmessenger.sdk.models.db.ChatMessage in project yellowmessenger-sdk by yellowmessenger.
the class ChatActivity method sendOptionEvent.
public void sendOptionEvent(SendOptionEvent sendOptionEvent) {
optionsLayout.setVisibility(View.GONE);
optionsLayout.removeAllViews();
ChatMessage chatMessage = new ChatMessage(username, sendOptionEvent.getOption().getLabel(), name, true);
addMessage(chatMessage);
chatMessage.setMessageValue(sendOptionEvent.getOption().getValue());
EventBus.getDefault().post(new SendMessageEvent(chatMessage));
}
use of com.yellowmessenger.sdk.models.db.ChatMessage in project yellowmessenger-sdk by yellowmessenger.
the class ChatActivity method onEvent.
@Subscribe
public void onEvent(AudioCompleteEvent event) {
try {
JSONObject jsonObject = new JSONObject(event.getResponse());
ChatMessage chatMessage = new ChatMessage(username, jsonObject.getJSONArray("transcriptions").getJSONObject(0).getString("utf_text"), name, true);
EventBus.getDefault().post(new SendMessageEvent(chatMessage));
addMessage(chatMessage);
dialog.hide();
} catch (JSONException e) {
e.printStackTrace();
}
}
use of com.yellowmessenger.sdk.models.db.ChatMessage in project yellowmessenger-sdk by yellowmessenger.
the class ChatActivity method sendMessage.
public void sendMessage(View view) {
String message = editText.getText().toString();
if (!message.trim().equals("")) {
ChatMessage chatMessage = new ChatMessage(username, message, name, true);
EventBus.getDefault().post(new SendMessageEvent(chatMessage));
addMessage(chatMessage);
editText.setText("");
optionsLayout.removeAllViews();
}
}
use of com.yellowmessenger.sdk.models.db.ChatMessage in project yellowmessenger-sdk by yellowmessenger.
the class RecyclerChatActivity method sendActionEvent.
public void sendActionEvent(SendActionEvent sendActionEvent) {
ChatMessage chatMessage = new ChatMessage(username, sendActionEvent.getAction().getTitle(), name, true);
addMessage(chatMessage);
chatMessage.setMessageValue(sendActionEvent.getAction().getText() != null ? sendActionEvent.getAction().getText() : sendActionEvent.getAction().getTitle());
EventBus.getDefault().post(new SendMessageEvent(chatMessage));
}
Aggregations