Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View AlexPrestonSB's full-sized avatar

Alex Preston AlexPrestonSB

View GitHub Profile
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.sendbird.sdk:sendbird-android-sdk:3.0.139'
compile 'com.github.bumptech.glide:glide:3.7.0'
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
tools:context="com.sendbird.androidchattutorial.LoginActivity">
package com.sendbird.androidchattutorial;
import android.content.Intent;
import android.support.design.widget.TextInputEditText;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/reycler_chat"
android:layout_width="0dp"
android:layout_height="0dp"
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp">
<ImageView
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp">
<TextView
// Retrieves 30 most recent messages.
void refresh() {
mChannel.getPreviousMessagesByTimestamp(Long.MAX_VALUE, true, 30, true,
BaseChannel.MessageTypeFilter.USER, null, new BaseChannel.GetMessagesHandler() {
@Override
public void onResult(List<BaseMessage> list, SendBirdException e) {
if (e != null) {
e.printStackTrace();
return;
}
// Messages sent by me do not display a profile image or nickname.
private class SentMessageHolder extends RecyclerView.ViewHolder {
TextView messageText, timeText;
SentMessageHolder(View itemView) {
super(itemView);
messageText = (TextView) itemView.findViewById(R.id.text_message_body);
timeText = (TextView) itemView.findViewById(R.id.text_message_time);
}
// Messages sent by others display a profile image and nickname.
private class ReceivedMessageHolder extends RecyclerView.ViewHolder {
TextView messageText, timeText, nameText;
ImageView profileImage;
ReceivedMessageHolder(View itemView) {
super(itemView);
messageText = (TextView) itemView.findViewById(R.id.text_message_body);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat);
mSendButton = (Button) findViewById(R.id.button_chat_send);
mMessageEditText = (EditText) findViewById(R.id.edittext_chat);
mRecyclerView = (RecyclerView) findViewById(R.id.reycler_chat);
mLayoutManager = new LinearLayoutManager(this);