use of com.yellowmessenger.sdk.events.SendOptionEvent 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;
}
Aggregations