Search in sources :

Example 1 with ChatMessage

use of com.yellowmessenger.sdk.models.db.ChatMessage 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 ChatMessage

use of com.yellowmessenger.sdk.models.db.ChatMessage 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 3 with ChatMessage

use of com.yellowmessenger.sdk.models.db.ChatMessage in project yellowmessenger-sdk by yellowmessenger.

the class ChatActivity method sendImageMessage.

public void sendImageMessage(Bitmap bm, String filename) {
    String message = "";
    ChatMessage chatMessage = new ChatMessage(username, message, name, true);
    chatMessage.setBitmap(bm);
    addMessage(chatMessage);
    EventBus.getDefault().post(new UploadStartEvent(chatMessage, filename));
}
Also used : ChatMessage(com.yellowmessenger.sdk.models.db.ChatMessage) UploadStartEvent(com.yellowmessenger.sdk.events.UploadStartEvent)

Example 4 with ChatMessage

use of com.yellowmessenger.sdk.models.db.ChatMessage 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 5 with ChatMessage

use of com.yellowmessenger.sdk.models.db.ChatMessage 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)

Aggregations

ChatMessage (com.yellowmessenger.sdk.models.db.ChatMessage)29 SendMessageEvent (com.yellowmessenger.sdk.events.SendMessageEvent)13 View (android.view.View)7 HorizontalScrollView (android.widget.HorizontalScrollView)7 ImageView (android.widget.ImageView)7 TextView (android.widget.TextView)7 ParseException (java.text.ParseException)7 Date (java.util.Date)7 Subscribe (org.greenrobot.eventbus.Subscribe)5 Intent (android.content.Intent)4 ChatResponse (com.yellowmessenger.sdk.models.ChatResponse)3 Question (com.yellowmessenger.sdk.models.Question)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 SmackException (org.jivesoftware.smack.SmackException)3 JSONObject (org.json.JSONObject)3 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)3 Paint (android.graphics.Paint)2 Bundle (android.os.Bundle)2 ViewGroup (android.view.ViewGroup)2 MessageReceivedEvent (com.yellowmessenger.sdk.events.MessageReceivedEvent)2