Search in sources :

Example 1 with SendMessageEvent

use of com.yellowmessenger.sdk.events.SendMessageEvent in project yellowmessenger-sdk by yellowmessenger.

the class ChatActivity method getChatHistory.

private void getChatHistory() {
    chatMessages.clear();
    List<ChatMessage> newChatMessages = ChatMessageDAO.findAllByUsername(username, 200, 0);
    if (newChatMessages.size() == 0) {
        ChatMessage chatMessage = new ChatMessage(username, "Start", name, true);
        chatMessage.setMessageValue("GET_STARTED");
        EventBus.getDefault().post(new SendMessageEvent(chatMessage));
    }
    Collections.reverse(newChatMessages);
    chatMessages.addAll(newChatMessages);
    chatListAdapter.notifyDataSetChanged();
}
Also used : ChatMessage(com.yellowmessenger.sdk.models.db.ChatMessage) SendMessageEvent(com.yellowmessenger.sdk.events.SendMessageEvent)

Example 2 with SendMessageEvent

use of com.yellowmessenger.sdk.events.SendMessageEvent in project yellowmessenger-sdk by yellowmessenger.

the class ChatActivity 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));
}
Also used : ChatMessage(com.yellowmessenger.sdk.models.db.ChatMessage) SendMessageEvent(com.yellowmessenger.sdk.events.SendMessageEvent)

Example 3 with SendMessageEvent

use of com.yellowmessenger.sdk.events.SendMessageEvent in project yellowmessenger-sdk by yellowmessenger.

the class ChatActivity method sendLocation.

private void sendLocation(LatLng latLng, String locationName, String address) {
    optionsLayout.setVisibility(View.GONE);
    optionsLayout.removeAllViews();
    try {
        JSONObject locationObj = new JSONObject();
        locationObj.put("lat", latLng.latitude);
        locationObj.put("lng", latLng.longitude);
        locationObj.put("name", locationName);
        locationObj.put("address", address);
        JSONObject messageObject = new JSONObject();
        messageObject.put("location", locationObj);
        final ChatMessage chatMessage = new ChatMessage(username, messageObject.toString(), name, true);
        addMessage(chatMessage);
        EventBus.getDefault().post(new SendMessageEvent(chatMessage));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JSONObject(org.json.JSONObject) ChatMessage(com.yellowmessenger.sdk.models.db.ChatMessage) SendMessageEvent(com.yellowmessenger.sdk.events.SendMessageEvent) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 4 with SendMessageEvent

use of com.yellowmessenger.sdk.events.SendMessageEvent in project yellowmessenger-sdk by yellowmessenger.

the class ChatActivity method sendOption.

public void sendOption(final Question question, final Option option) {
    if (option.isLocation()) {
        askForLocation();
    } else {
        optionsLayout.setVisibility(View.GONE);
        optionsLayout.removeAllViews();
        ChatMessage chatMessage = new ChatMessage(username, option.getLabel(), name, true);
        chatMessage.setMessageValue(option.getValue());
        EventBus.getDefault().post(new SendMessageEvent(chatMessage));
        addMessage(chatMessage);
    }
}
Also used : ChatMessage(com.yellowmessenger.sdk.models.db.ChatMessage) SendMessageEvent(com.yellowmessenger.sdk.events.SendMessageEvent)

Example 5 with SendMessageEvent

use of com.yellowmessenger.sdk.events.SendMessageEvent in project yellowmessenger-sdk by yellowmessenger.

the class RecyclerChatActivity 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));
}
Also used : ChatMessage(com.yellowmessenger.sdk.models.db.ChatMessage) SendMessageEvent(com.yellowmessenger.sdk.events.SendMessageEvent)

Aggregations

SendMessageEvent (com.yellowmessenger.sdk.events.SendMessageEvent)13 ChatMessage (com.yellowmessenger.sdk.models.db.ChatMessage)13 JSONObject (org.json.JSONObject)3 IOException (java.io.IOException)2 Subscribe (org.greenrobot.eventbus.Subscribe)2 JSONException (org.json.JSONException)2