Search in sources :

Example 1 with Question

use of com.yellowmessenger.sdk.models.Question in project yellowmessenger-sdk by yellowmessenger.

the class ChatActivity method onEvent.

@Subscribe
public void onEvent(ChatUpdatedEvent event) {
    if (chatMessages.size() > 0) {
        ChatMessage chatMessage = chatMessages.get(chatMessages.size() - 1);
        if (!chatMessage.isYou() && chatMessage.getChatType() == ChatType.QUESTION) {
            Question question = chatMessage.getChatResponse().getQuestion();
            editText.setInputType(FieldType.getInputType(question.getFieldType()));
            if (question.getOptions() != null && question.getOptions().size() > 0 && !question.isPersistentOptions()) {
                addOptions(question);
            } else {
                optionsLayout.removeAllViews();
            }
        } else {
            optionsLayout.removeAllViews();
            initiateSendMessageListener();
        }
    }
}
Also used : ChatMessage(com.yellowmessenger.sdk.models.db.ChatMessage) Question(com.yellowmessenger.sdk.models.Question) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 2 with Question

use of com.yellowmessenger.sdk.models.Question in project yellowmessenger-sdk by yellowmessenger.

the class RecyclerChatActivity method onEvent.

@Subscribe
public void onEvent(ChatUpdatedEvent event) {
    if (chatMessages.size() > 0) {
        ChatMessage chatMessage = chatMessages.get(chatMessages.size() - 1);
        if (!chatMessage.isYou() && chatMessage.getChatType() == ChatType.QUESTION) {
            Question question = chatMessage.getChatResponse().getQuestion();
            if (question.getOptions() != null && question.getOptions().size() > 0) {
                addOptions(question);
            }
        } else {
            optionsLayout.removeAllViews();
            initiateSendMessageListener();
        }
    }
}
Also used : ChatMessage(com.yellowmessenger.sdk.models.db.ChatMessage) Question(com.yellowmessenger.sdk.models.Question) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 3 with Question

use of com.yellowmessenger.sdk.models.Question 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;
}
Also used : ChatMessage(com.yellowmessenger.sdk.models.db.ChatMessage) ViewGroup(android.view.ViewGroup) SendOptionEvent(com.yellowmessenger.sdk.events.SendOptionEvent) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) TextView(android.widget.TextView) Paint(android.graphics.Paint) Date(java.util.Date) Question(com.yellowmessenger.sdk.models.Question) TextView(android.widget.TextView) Option(com.yellowmessenger.sdk.models.Option) ParseException(java.text.ParseException)

Aggregations

Question (com.yellowmessenger.sdk.models.Question)3 ChatMessage (com.yellowmessenger.sdk.models.db.ChatMessage)3 Subscribe (org.greenrobot.eventbus.Subscribe)2 Paint (android.graphics.Paint)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 HorizontalScrollView (android.widget.HorizontalScrollView)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 SendOptionEvent (com.yellowmessenger.sdk.events.SendOptionEvent)1 Option (com.yellowmessenger.sdk.models.Option)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1