Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Then add the dependency

```
dependencies {
compile 'com.github.timigod:android-chat-ui:v0.1.4'
implementation 'com.github.subhan9090:android-chat-ui:v0.1'
}
```

Expand Down Expand Up @@ -134,6 +134,16 @@ chatView.setTypingListener(new ChatView.TypingListener(){
});
```

### Typing Indicator

When you receive socket from other user that it's typing you can show and hide the Typing Indicator
In the ChatView.

```
chatView.showTypingIndicator("User Name");
chatView.hideTypingIndicator("User Name");
```

### TODO
This is list of things that are in the works for this library:

Expand All @@ -155,3 +165,5 @@ We welcome any and all contributions, code cleanups and feature requests.
1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
2. Fork the repository on GitHub to start making your changes to the master branch (or branch off of it).
3. Send a pull request and bug the maintainer until it gets merged and published. :).

[![](https://jitpack.io/v/subhan9090/android-chat-ui.svg)](https://jitpack.io/#subhan9090/android-chat-ui)
19 changes: 10 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
compileSdkVersion 34 // at least 28, I recommend latest stable
namespace "co.intentservice.chatui.sample"

defaultConfig {
applicationId "co.intentservice.chatui.sample"
minSdkVersion 16
targetSdkVersion 23
minSdkVersion 23
targetSdkVersion 34
versionCode 1
versionName "1.0"
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -19,10 +19,11 @@ android {
}
}


dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.13.2'

compile 'com.android.support:appcompat-v7:23.4.0'
compile project(':chat-ui')
implementation 'androidx.appcompat:appcompat:1.7.1'
implementation project(':chat-ui')
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package co.intentservice.chatui.sample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import androidx.appcompat.app.AppCompatActivity;

import co.intentservice.chatui.ChatView;
import co.intentservice.chatui.models.ChatMessage;
Expand All @@ -17,12 +18,7 @@ protected void onCreate(Bundle savedInstanceState) {
chatView.addMessage(new ChatMessage("Message received", System.currentTimeMillis(), ChatMessage.Type.RECEIVED));
chatView.addMessage(new ChatMessage("A message with a sender name",
System.currentTimeMillis(), ChatMessage.Type.RECEIVED, "Ryan Java"));
chatView.setOnSentMessageListener(new ChatView.OnSentMessageListener() {
@Override
public boolean sendMessage(ChatMessage chatMessage) {
return true;
}
});
chatView.setOnSentMessageListener(chatMessage -> true);

chatView.setTypingListener(new ChatView.TypingListener() {
@Override
Expand Down
14 changes: 9 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
jcenter()
google()
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'com.android.tools.build:gradle:8.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
jcenter()
google()
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
}

Expand Down
68 changes: 49 additions & 19 deletions chat-ui/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

ext {
bintrayRepo = 'maven'
Expand All @@ -25,15 +26,15 @@ ext {
}

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

namespace "co.intentservice.chatui"
compileSdk = 34
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
minSdk 23
targetSdkVersion 34
versionCode 1
versionName "1.0"
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -42,21 +43,50 @@ android {
}
}

ext {
supportLibVer = '23.4.0'
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile 'junit:junit:4.12'
compile 'com.android.support:support-v4:23.0.0'
compile "com.android.support:appcompat-v7:${supportLibVer}"
compile "com.android.support:cardview-v7:${supportLibVer}"
compile "com.android.support:design:${supportLibVer}"

compile 'pl.tajchert:waitingdots:0.2.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.7.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.13.0'
androidTestImplementation 'androidx.test:core:1.7.0'
implementation 'pl.tajchert:waitingdots:0.2.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'
implementation 'androidx.annotation:annotation:1.9.1'

}
afterEvaluate {
publishing {
publications {
release(MavenPublication) {
// Instead of from components.release, publish the AAR manually
groupId = 'com.github.subhan9090'
artifactId = 'android-chat-ui'
version = 'v0.1.2'

artifact("$buildDir/outputs/aar/${project.name}-release.aar") {
builtBy tasks.named("bundleReleaseAar")
}

apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
pom {
name.set("android-chat-ui")
description.set("A UI Chat Interface Library for Android Applications with typing indicator support")
url.set("https://github.com/subhan9090/android-chat-ui")
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
}
}
}
}
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
13 changes: 0 additions & 13 deletions chat-ui/src/main/java/co/intentservice/chatui/ApplicationTest.java

This file was deleted.

72 changes: 64 additions & 8 deletions chat-ui/src/main/java/co/intentservice/chatui/ChatView.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package co.intentservice.chatui;

import static androidx.core.content.ContextCompat.getColor;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView;
import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
Expand All @@ -22,6 +22,8 @@
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.cardview.widget.CardView;

import java.util.ArrayList;

import co.intentservice.chatui.fab.FloatingActionsMenu;
Expand Down Expand Up @@ -141,17 +143,17 @@ private void getChatViewBackgroundColor() {
}

private void getAttributesForChatMessageRow() {
backgroundRcv = attributes.getColor(R.styleable.ChatView_backgroundRcv, ContextCompat.getColor(context, R.color.default_chat_message_background_color_rcv));
backgroundSend = attributes.getColor(R.styleable.ChatView_backgroundSend, ContextCompat.getColor(context, R.color.default_chat_message_background_color_send));
backgroundRcv = attributes.getColor(R.styleable.ChatView_backgroundRcv, getColor(context, R.color.default_chat_message_background_color_rcv));
backgroundSend = attributes.getColor(R.styleable.ChatView_backgroundSend, getColor(context, R.color.default_chat_message_background_color_send));
}

private void getAttributesForBubbles() {
float dip4 = context.getResources().getDisplayMetrics().density * 4.0f;
int elevation = attributes.getInt(R.styleable.ChatView_bubbleElevation, ELEVATED);
bubbleElevation = elevation == ELEVATED ? dip4 : 0;

bubbleBackgroundRcv = attributes.getColor(R.styleable.ChatView_bubbleBackgroundRcv, ContextCompat.getColor(context, R.color.default_bubble_color_rcv));
bubbleBackgroundSend = attributes.getColor(R.styleable.ChatView_bubbleBackgroundSend, ContextCompat.getColor(context, R.color.default_bubble_color_send));
bubbleBackgroundRcv = attributes.getColor(R.styleable.ChatView_bubbleBackgroundRcv, getColor(context, R.color.default_bubble_color_rcv));
bubbleBackgroundSend = attributes.getColor(R.styleable.ChatView_bubbleBackgroundSend, getColor(context, R.color.default_bubble_color_send));
}


Expand Down Expand Up @@ -226,8 +228,8 @@ private boolean hasStyleResourceSet() {

private void setInputTextDefaults() {
inputTextSize = context.getResources().getDimensionPixelSize(R.dimen.default_input_text_size);
inputTextColor = ContextCompat.getColor(context, R.color.black);
inputHintColor = ContextCompat.getColor(context, R.color.main_color_gray);
inputTextColor = getColor(context, R.color.black);
inputHintColor = getColor(context, R.color.main_color_gray);
setInputHint();
}

Expand Down Expand Up @@ -404,6 +406,60 @@ public FloatingActionsMenu getActionsMenu() {
}


/**
* Shows typing indicator for a specific sender (other user)
*/
public void showTypingIndicator(String sender) {
chatListView.post(() -> {
ArrayList<ChatMessage> messages = chatViewListAdapter.getList();

// Avoid duplicates
for (ChatMessage msg : messages) {
if (msg.getType() == ChatMessage.Type.TYPING && sender.equals(msg.getSender())) {
return; // already showing
}
}

ChatMessage typingMessage = new ChatMessage(
"",
System.currentTimeMillis(),
ChatMessage.Type.TYPING,
sender
);

chatViewListAdapter.addMessage(typingMessage);
scrollToBottom();
});
}

/**
* Removes typing indicator for a specific sender
*/
public void hideTypingIndicator(String sender) {
chatListView.post(() -> {
ArrayList<ChatMessage> messages = chatViewListAdapter.getList();

for (int i = messages.size() - 1; i >= 0; i--) {
ChatMessage msg = messages.get(i);
if (msg.getType() == ChatMessage.Type.TYPING && sender.equals(msg.getSender())) {
chatViewListAdapter.removeMessage(i);
break; // remove only the last typing indicator for this sender
}
}
});
}

/**
* Scroll ListView to bottom
*/
private void scrollToBottom() {
chatListView.post(() -> {
int count = chatViewListAdapter.getCount();
if (count > 0) {
chatListView.setSelection(count - 1);
}
});
}
public interface TypingListener {

void userStartedTyping();
Expand Down
Loading