Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.tinja:android-chat-ui:v0.1.4'
}
<dependency>
<groupId>com.github.tinja</groupId>
<artifactId>android-chat-ui</artifactId>
<version>v0.1.4</version>
</dependency>
libraryDependencies += "com.github.tinja" % "android-chat-ui" % "v0.1.4"
:dependencies [[com.github.tinja/android-chat-ui "v0.1.4"]]
This is meant to ease the life of any developer looking to add chat functionality into his/her Android application and wouldn't like to worry so much about setting up the UI.
This library is still in it's very early stages, but improvements would come over time.
Note: This is merely a UI library, messages being actually sent and recieved by your application still needs to be implemented.
v0.1.2
Add this to your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Then add the dependency
dependencies {
compile 'com.github.timigod:android-chat-ui:v0.1.3'
}
Drop the ChatView in your XML layout as is shown below:
<ChatView
android:id="@+id/chat_view"
android:layout_width="match_parent"
android:layout_height="match_parents"
<!-- Insert customisation options here -->
/>
Remember to add this attribute to your root layout.
xmlns:chatview="http://schemas.android.com/apk/res-auto"
And then in your Activity or Fragment you can get the instance of the ChatView by doing:
ChatView chatView = (ChatView) findViewById(R.id.chat_view);
You can customize the appearance of this view by using the following attributes.
chatview:backgroundColor=""
chatview:inputBackgroundColor=""
chatview:inputUseEditorAction="" // true or false
chatview:inputTextAppearance=""
chatview:inputTextSize=""
chatview:inputTextColor=""
chatview:inputHintColor=""
chatview:sendBtnIcon=""
chatview:sendBtnIconTint=""
chatview:sendBtnBackgroundTint=""
chatview:bubbleBackgroundRcv="" // color
chatview:bubbleBackgroundSend="" //color
chatview:bubbleElevation="" // "flat" or "elevated"
You can detect when a user clicks the "send" action button by using the OnSentMessageListener
.
chatView.setOnSentMessageListener(new ChatView.OnSentMessageListener(){
@Override
public boolean sendMessage(ChatMessage chatMessage){
// perform actual message sending
return true;
}
});
In the method sendMessage()
, you can now perform whatever logic to send messages i.e make an HTTP request or send the message over a socket connection.
Depending on whatever logic or validation you put in place, you may return true
or false
. true
will update the ChatView
with the message bubble and false
will do the opposite.
You can use the chatView.addMessage(ChatMessage message)
to add a "received" message to the UI. This obviously should be done after whatever mechanisms you have in place have actually received a message.
You can use this method or chatView.addMessages(ArrayList<ChatMessage> messages)
to add messages to the UI.
The side the chat bubble will appear on is determined by the Type
of the ChatMessage
.
You can remove messages using chatView.removeMessage(int position)
or chatView.clearMessages()
ChatMessage
holds all the relevant data about your message: String message
, long timestamp
and Type type
. Type
is an enum that can either be SENT
or RECEIVED
.
It is the Type
that determines what side of the UI the bubble will appear.
You can detect different states of the user's typing activity by using TypingListener
.
chatView.setTypingListener(new ChatView.TypingListener(){
@Override
public void userStartedTyping(){
// will be called when the user starts typing
}
@Override
public void userStoppedTyping(){
// will be called when the user stops typing
}
});
This is list of things that are in the works for this library:
Of course, additions to this library aren't limited to the above.
We welcome any and all contributions, code cleanups and feature requests.