Search in sources :

Example 1 with Message

use of drift.com.drift.model.Message in project drift-sdk-android by Driftt.

the class ConversationActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.drift_sdk_activity_conversation);
    StatusBarColorizer.setActivityColor(this);
    IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
    registerReceiver(downloadReceiver, filter);
    textEntryEditText = findViewById(R.id.drift_sdk_conversation_activity_edit_text);
    sendButtonImageView = findViewById(R.id.drift_sdk_conversation_activity_send_button);
    plusButtonImageView = findViewById(R.id.drift_sdk_conversation_activity_plus_button);
    recyclerView = findViewById(R.id.drift_sdk_conversation_activity_recycler_activity);
    statusTextView = findViewById(R.id.drift_sdk_conversation_activity_status_view);
    progressBar = findViewById(R.id.drift_sdk_conversation_activity_progress_view);
    driftWelcomeMessage = findViewById(R.id.drift_sdk_conversation_activity_welcome_text_view);
    driftWelcomeImageView = findViewById(R.id.drift_sdk_conversation_activity_welcome_image_view);
    driftBrandTextView = findViewById(R.id.drift_sdk_conversation_activity_drift_brand_text_view);
    welcomeMessageLinearLayout = findViewById(R.id.drift_sdk_conversation_activity_welcome_linear_layout);
    Intent intent = getIntent();
    if (intent.getExtras() != null) {
        conversationId = intent.getExtras().getInt(CONVERSATION_ID, -1);
        conversationType = (ConversationType) intent.getExtras().getSerializable(CONVERSATION_TYPE);
    }
    if (conversationId == -1 && conversationType == ConversationType.CONTINUE) {
        Toast.makeText(this, "Invalid Conversation Id", Toast.LENGTH_SHORT).show();
        finish();
    }
    Auth auth = Auth.getInstance();
    if (auth != null && auth.endUser != null) {
        endUserId = auth.endUser.id;
    } else {
        // No Auth
        Toast.makeText(this, "We're sorry, an unknown error occurred", Toast.LENGTH_LONG).show();
        finish();
    }
    sendButtonImageView.setBackgroundColor(ColorHelper.getBackgroundColor());
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle("Conversation");
    }
    sendButtonImageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            didPressSendButton();
        }
    });
    textEntryEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                didPressSendButton();
                return true;
            }
            return false;
        }
    });
    textEntryEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() != 0) {
                sendButtonImageView.setVisibility(View.VISIBLE);
            } else {
                sendButtonImageView.setVisibility(View.GONE);
            }
        }
    });
    AttachmentManager.getInstance().setAttachmentLoadHandle(this);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    layoutManager.setReverseLayout(true);
    layoutManager.setAutoMeasureEnabled(false);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.addOnItemTouchListener(new RecyclerTouchListener(this, recyclerView, new ClickListener() {

        @Override
        public void onClick(View view, int position) {
            Message message = conversationAdapter.getItemAt(position);
            if (message != null && message.sendStatus == Message.SendStatus.FAILED) {
                resendMessage(message);
            }
        }
    }));
    conversationAdapter = new ConversationAdapter(this, MessageManager.getInstance().getMessagesForConversationId(conversationId));
    recyclerView.setAdapter(conversationAdapter);
    if (conversationAdapter.getItemCount() == 0) {
        progressBar.setVisibility(View.VISIBLE);
    } else {
        progressBar.setVisibility(View.GONE);
    }
}
Also used : RecyclerTouchListener(drift.com.drift.helpers.RecyclerTouchListener) IntentFilter(android.content.IntentFilter) Message(drift.com.drift.model.Message) ConversationAdapter(drift.com.drift.adapters.ConversationAdapter) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) KeyEvent(android.view.KeyEvent) Auth(drift.com.drift.model.Auth) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) ActionBar(android.support.v7.app.ActionBar) ClickListener(drift.com.drift.helpers.ClickListener)

Example 2 with Message

use of drift.com.drift.model.Message in project drift-sdk-android by Driftt.

the class ConversationActivity method createConversation.

void createConversation() {
    final String textToSend = textEntryEditText.getText().toString();
    final MessageRequest messageRequest = new MessageRequest(textToSend, endUserId, null, this);
    final Message message = messageRequest.messageFromRequest(conversationId);
    progressBar.setVisibility(View.VISIBLE);
    MessageManager.getInstance().createConversation(textToSend, new APICallbackWrapper<Message>() {

        @Override
        public void onResponse(Message response) {
            progressBar.setVisibility(View.GONE);
            if (response != null) {
                conversationId = response.conversationId;
                conversationType = ConversationType.CONTINUE;
                message.sendStatus = Message.SendStatus.SENT;
                conversationAdapter.addMessage(recyclerView, message);
                updateForConversationType();
            } else {
                conversationAdapter.updateData(new ArrayList<Message>());
                textEntryEditText.setText(textToSend);
                Alert.showAlert(ConversationActivity.this, "Error", "Failed to create conversation", "Retry", new Runnable() {

                    @Override
                    public void run() {
                        didPressSendButton();
                    }
                });
            }
        }
    });
}
Also used : MessageRequest(drift.com.drift.model.MessageRequest) Message(drift.com.drift.model.Message) ArrayList(java.util.ArrayList)

Example 3 with Message

use of drift.com.drift.model.Message in project drift-sdk-android by Driftt.

the class ConversationAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(MessageCell holder, int position) {
    boolean showDayHeader = true;
    Message message = getItemAt(position);
    if (position < getItemCount() - 1) {
        Message pastMessage = getItemAt(position + 1);
        if (message.createdAt == null || pastMessage.createdAt == null) {
            Log.d("TAG", "Null Created At");
        } else {
            showDayHeader = !DateHelper.isSameDay(message.createdAt, pastMessage.createdAt);
        }
    }
    holder.setupForMessage(messages.get(position), showDayHeader);
}
Also used : Message(drift.com.drift.model.Message)

Example 4 with Message

use of drift.com.drift.model.Message in project drift-sdk-android by Driftt.

the class PresentationManager method showMessagePopupFromManager.

private void showMessagePopupFromManager() {
    // /Check for unread conversation extras
    ArrayList<Message> unreadMessages = new ArrayList<>();
    int unreadMessageCount = -1;
    for (ConversationExtra conversationExtra : ConversationManager.getInstance().getConversations()) {
        if (conversationExtra.unreadMessages != 0) {
            if (conversationExtra.lastAgentMessage != null) {
                unreadMessages.add(conversationExtra.lastAgentMessage);
                unreadMessageCount += conversationExtra.unreadMessages;
            }
        }
    }
    if (!unreadMessages.isEmpty()) {
        showPopupForMessage(unreadMessages.get(0), unreadMessageCount);
    }
}
Also used : ConversationExtra(drift.com.drift.model.ConversationExtra) Message(drift.com.drift.model.Message) ArrayList(java.util.ArrayList)

Example 5 with Message

use of drift.com.drift.model.Message in project drift-sdk-android by Driftt.

the class SocketManager method processEnvelopeData.

private void processEnvelopeData(final String type, final JsonObject data) {
    Handler mainHandler = new Handler(Looper.getMainLooper());
    Runnable myRunnable = new Runnable() {

        @Override
        public void run() {
            switch(type) {
                case "MESSAGE":
                    Message message = gson.fromJson(data, Message.class);
                    if (message != null && message.contentType.equals("CHAT") && message.authorType.equals("USER")) {
                        LoggerHelper.logMessage(TAG, "Received new Message");
                        PresentationManager.getInstance().didReceiveNewMessage(message);
                    }
                    break;
                default:
                    LoggerHelper.logMessage(TAG, "Undealt with socket event type: " + type);
                    break;
            }
        }
    };
    mainHandler.post(myRunnable);
}
Also used : Message(drift.com.drift.model.Message) Handler(android.os.Handler)

Aggregations

Message (drift.com.drift.model.Message)7 Editable (android.text.Editable)2 MessageRequest (drift.com.drift.model.MessageRequest)2 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Handler (android.os.Handler)1 ActionBar (android.support.v7.app.ActionBar)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 TextWatcher (android.text.TextWatcher)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 ConversationAdapter (drift.com.drift.adapters.ConversationAdapter)1 ClickListener (drift.com.drift.helpers.ClickListener)1 RecyclerTouchListener (drift.com.drift.helpers.RecyclerTouchListener)1 Auth (drift.com.drift.model.Auth)1