Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Preston AlexPrestonSB

View GitHub Profile
View build.gradle
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'
View activity_login.xml
<?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">
View LoginActivity.java
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;
View activity_chat.xml
<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"
View item_message_received.xml
<?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
View item_message_sent.xml
<?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
View FetchMessages.java
// 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;
}
View MessageHolder.java
// 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);
}
View ReceivedMessageHolder.java
// 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);
View OnCreate.java
@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);