Coder Social home page Coder Social logo

android-chat-ui's Introduction

Android Chat UI

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.

Image of Library in action

Version

v0.1.4

Installation

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.4'
}

Usage

Drop the ChatView in your XML layout as is shown below:

<co.intentservice.chatui.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);

Customization

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:inputHint=""
chatview:inputHintColor=""
chatview:sendBtnIcon=""
chatview:sendBtnIconTint=""
chatview:sendBtnBackgroundTint=""

chatview:bubbleBackgroundRcv="" // color
chatview:bubbleBackgroundSend="" //color
chatview:bubbleElevation="" // "flat" or "elevated"

Sending messages

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.

Receiving messages

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.

Deleting messages

You can remove messages using chatView.removeMessage(int position) or chatView.clearMessages()

The ChatMessage class

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.

Typing Listener

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
	}
});

TODO

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

Theming

  • message TextAppearance (sent / received messages)
  • timestamp TextAppearance (sent / received messages)
  • The ability to use an image as the background for the ChatView

Functionality

  • Ability to use custom item layout
  • Ability to send and recieve multimedia messages like images, embedded locations and even videos.
  • Ability to track and update individual messages (Useful to be able to show delivered/read/unread status or the like)

Of course, additions to this library aren't limited to the above.

Contributing

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. :).

android-chat-ui's People

Contributors

azemoh avatar brebory avatar efemoney avatar efeturi avatar fathermerry avatar jam155 avatar michaelobi avatar onyekvchi avatar r-cohen avatar samuelo-101 avatar segunfamisa avatar timigod avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-chat-ui's Issues

Hide FloatingActionButton

I need an option to hide the FloatingActionButton "sendButton".

I hidden it with the following code:

FloatingActionsMenu sendButton = (FloatingActionsMenu) chatView.findViewById(R.id.sendButton);
sendButton.setVisibility(View.GONE);

How to Send Images?

Thanks for this library. I want to know how we can send Images through this library. There is no help found in README.

Send Event

When the send button is clicked and i add the message to the chatview, it gets displayed twice

Program Type already present

Program type already present: android.support.v4.app.FragmentTransitionCompat21$1
Message{kind=ERROR, text=Program type already present: android.support.v4.app.FragmentTransitionCompat21$1, sources=[Unknown source file], tool name=Optional.of(D8)}

Background for section with chat bubble different color than specified background

My background is broken up when a new message is placed on the UI, despite my background setting.

Tried both implementation 'com.github.timigod:android-chat-ui:v0.1.4' and implementation 'com.github.timigod:android-chat-ui:master'.

Tried even wrapping another layout around it. That didn't work either.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/custom_red"
    xmlns:android="http://schemas.android.com/apk/res/android">
<co.intentservice.chatui.ChatView xmlns:chatview="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/chat_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    chatview:backgroundColor="@color/custom_red"
    chatview:sendBtnIcon="@drawable/ic_send_white_24dp"
    chatview:sendBtnBackgroundTint="@color/button_background"
    chatview:bubbleBackgroundRcv="@android:color/holo_orange_light"
    chatview:bubbleBackgroundSend="@color/whitesmoke"
    chatview:bubbleElevation="elevated"
    />
</LinearLayout>


This is still the result:

selection_008

How can I get rid of the stripe, or do I have to use white for the background?

Could not find android-chat-ui.jar

I get this error after adding your dependency to the build.gradle file. It's looking for a .jar file but your repo has a .pom file. What am I doing wrong?

selection_009

Message sent/seen status

Very grateful for such complete UI library, is there any way to set status of message sent/seen in the bubble. I have the code for message delivery and receipt, I just want to implement in the ChatView. My App would be complete if I can do it. Thanks.

add message method

Hi,
I want add history message. so plz ChatView have addMessage(ChatMessage chatMessage,int index)addMessages(ArrayList<ChatMessage>,int index)

thanks

Updating

Hello,
Thanks for great UI!
I'm currently trying to delete messages from the view that are older than x days, but unfortunaltely i can't but it together. My question is that how do i access the message list adapter to view all the message currently on the chat screen and loop through all the messages and if their timestamp is older than x days/hours delete them from the ChatViewListAdapater. Is there a way?

Add multimedia sending support

I believe this is one of the things in your todo list:

  • Ability to send and recieve multimedia messages like images, embedded locations and even videos.

Is there any update of it? I have need to send images only through camera. Is there any possibilty of getting this feature anytime soon? Even if only with Image sending capability?

Thanks
Tobibur

Send next message

After sending 1 message and receiving 1 how can I send the next message?

Error rendering layout

Hi, I would like to use this ui but I got this error:

java.lang.NoSuchFieldError: chat_list
at co.intentservice.chatui.ChatView.initializeViews(ChatView.java:101)
at co.intentservice.chatui.ChatView.init(ChatView.java:91)
at co.intentservice.chatui.ChatView.(ChatView.java:84)
at co.intentservice.chatui.ChatView.(ChatView.java:79)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:465)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:172)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:105)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:186)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:334)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:345)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:245)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:324)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:389)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:548)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:533)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:966)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:533)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$70(RenderTask.java:659)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

This is my layout xml code:

<!--<co.devcenter.androiduilibrary.ChatView
    android:id="@+id/rooster_chat_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</co.devcenter.androiduilibrary.ChatView>-->

<co.intentservice.chatui.ChatView
    android:id="@+id/chat_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Listview updation refresh issue

Hello ,
I am facing issues regarding the refresh of list view after adding every message.
Everytime a message is received in the ui, only after refreshing the ui the message will be displayed.
Kindly help me out with this issue.

Caused by java.lang.ArrayIndexOutOfBoundsException length=18; index=66

co.intentservice.chatui.ChatView.setInputTextSize (ChatView.java:235)

co.intentservice.chatui.ChatView.getAttributesForInputText (ChatView.java:174)

co.intentservice.chatui.ChatView.getXMLAttributes (ChatView.java:120)

co.intentservice.chatui.ChatView.init (ChatView.java:99)

co.intentservice.chatui.ChatView. (ChatView.java:91)

co.intentservice.chatui.ChatView. (ChatView.java:84)

co.intentservice.chatui.ChatView. (ChatView.java:80)

this issue in in production app and plz help me understand the Exception! and its not reproduceable.

ChatMessage

Hi!
First of all i'm using below as dependencies
dependencies {
compile 'com.github.timigod:android-chat-ui:v0.1.3'
}
but I can't see
public ChatMessage(String message, long timestamp, Type type, String sender) {
this(message, timestamp, type);
this.sender = sender;
}

why?

Input field hint

Possibility to add another hint for input. Or possibility to add localization for this field.

sendMessage() has private access in ChatView

Below are the code I wrote and is used to test if message can be sent

`
private ChatView mChatView;
private SendButton mSendButton

...

mSendButton.setOnClickListener(new View.OnClickListener() {
@OverRide
public void onClick(View view) {
if (RoosterConnectionService.getState().equals(RoosterConnection.ConnectionState.CONNECTED)) {
Log.d(TAG, "The client is connected to server, sending message");
// send message to server

        Intent sendIntent = new Intent(RoosterConnectionService.SEND_MESSAGE);
        sendIntent.putExtra(RoosterConnectionService.BUNDLE_MESSAGE_BODY, mChatView.getTypedMessage());
        sendIntent.putExtra(RoosterConnectionService.BUNDLE_TO, contactJid);
        sendBroadcast(sendIntent);
        mChatView.sendMessage();
    }
}

});
...
So at the end there, I got a red line beneath thesendMessage()function telling me thatsendMessage(java.lang.String, long) has private access in 'co.intentservice.chatui.ChatView'.
Is there any other method for sending message?

clear input text

how to clear input text when click button send?
it's not automaticly clear

this is my xml:
<co.intentservice.chatui.ChatView
android:id="@+id/chat_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
chatview:inputBackgroundColor="@color/white"
chatview:inputUseEditorAction="false"
chatview:inputTextSize="15dp"
chatview:inputTextColor="@color/black"
chatview:inputHint="Ketik Disini..."
chatview:inputHintColor="@color/black"
chatview:sendBtnIcon="@drawable/ic_menu_send"
chatview:sendBtnBackgroundTint="@color/colorPrimary"
chatview:sendBtnIconTint="@color/white"
chatview:bubbleBackgroundRcv="@color/colorSecondary"
chatview:bubbleBackgroundSend="@color/white"
chatview:bubbleElevation="elevated"
chatview:tStampTextColorRcv="@color/white"
chatview:tStampTextColorSend="@color/white"
chatview:messageTextColorRcv="@color/white"
chatview:messageTextColorSend="@color/white"

/>

image

thank you

Custom message views

Hi Timigod -

My name is Tyler, and I have recently integrated this ui framework with a small app I'm working on. Everything works great, except I had one use case that I am not sure whether it is supported. I want to add custom chat bubbles, so that I can create a custom view, and have it appear just like any other chat bubble. That way I can add buttons and other functions to the custom view. Is anything like this in the works? Or is there some way I can get this to work given what's already implemented?

Thanks,
Tyler

Bubble colors not changing

Hi,
I am trying to change the bubble colors, but they are not changing... Is anyone else facing the same issue ?
I am adding the following:

<co.intentservice.chatui.ChatView
        android:id="@+id/chat_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        chatview:bubbleElevation="elevated"
        chatview:bubbleBackgroundRcv="@color/white"
        chatview:bubbleBackgroundSend="@color/white"
        chatview:backgroundRcv="@color/white"
        chatview:messageTextColorSend="@color/blue"
    />

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.