Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sender's profile pic in chat view option added #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.intentservice.chatui.sample;

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

Expand All @@ -12,11 +13,15 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Uri uri = Uri.parse("https://abs.twimg.com/sticky/default_profile_images/default_profile_400x400.png");

ChatView chatView = (ChatView) findViewById(R.id.chat_view);
chatView.addMessage(new ChatMessage("Message received with profile pic", System.currentTimeMillis(), ChatMessage.Type.RECEIVED,uri));
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.addMessage(new ChatMessage("A message with a sender name and profile pic",
System.currentTimeMillis(), ChatMessage.Type.RECEIVED, "Ryan Java",uri));
chatView.setOnSentMessageListener(new ChatView.OnSentMessageListener() {
@Override
public boolean sendMessage(ChatMessage chatMessage) {
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -16,6 +17,7 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
}
}

Expand Down
3 changes: 3 additions & 0 deletions chat-ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ dependencies {
compile "com.android.support:design:${supportLibVer}"

compile 'pl.tajchert:waitingdots:0.2.0'

implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'de.hdodenhof:circleimageview:2.2.0'
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,13 @@ public View getView(int position, View convertView, ViewGroup parent) {
holder.setElevation(bubbleElevation);
holder.setBackground(type);
String sender = chatMessages.get(position).getSender();
String uri = chatMessages.get(position).getUri();
if (sender != null) {
holder.setSender(sender);
}

if (uri != null && !uri.isEmpty()){
holder.setProfileIcon(uri);
}
return convertView;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.intentservice.chatui.models;

import android.net.Uri;
import android.text.format.DateFormat;

import java.util.concurrent.TimeUnit;
Expand All @@ -14,18 +15,31 @@ public class ChatMessage {
private long timestamp;
private Type type;
private String sender;
private Uri uri;

public ChatMessage(String message, long timestamp, Type type) {
this.message = message;
this.timestamp = timestamp;
this.type = type;
}

public ChatMessage(String message, long timestamp, Type type, Uri uri) {
this.message = message;
this.timestamp = timestamp;
this.type = type;
this.uri = uri;
}

public ChatMessage(String message, long timestamp, Type type, String sender) {
this(message, timestamp, type);
this.sender = sender;
}

public ChatMessage(String message, long timestamp, Type type, String sender, Uri uri) {
this(message, timestamp, type, uri);
this.sender = sender;
}

public long getTimestamp() {
return timestamp;
}
Expand All @@ -51,6 +65,19 @@ public void setType(Type type) {
}


public String getUri() {
if(uri == null){
return "";
}else {
return uri.toString();
}

}

public void setUri(Uri uri) {
this.uri = uri;
}

public String getFormattedTime() {

long oneDayInMillis = TimeUnit.DAYS.toMillis(1); // 24 * 60 * 60 * 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public void setElevation(float elevation) {

}

public void setProfileIcon(String uri){
messageView.setProfileIcon(uri);
}

public void setSender(String sender) {
messageView.setSender(sender);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.widget.TextView;

import co.intentservice.chatui.R;
import de.hdodenhof.circleimageview.CircleImageView;

/**
* View to display messages that have been received throught the chat-ui.
Expand All @@ -20,6 +21,7 @@ public class ItemRecvView extends MessageView {

private CardView bubble;
private TextView messageTextView, timestampTextView;
private CircleImageView profileIcon = (CircleImageView) findViewById(R.id.profile_icon);

/**
* Method to set the messages text in the view so it can be displayed on the screen.
Expand Down Expand Up @@ -124,6 +126,7 @@ private void initializeView(Context context) {
this.bubble = (CardView) findViewById(R.id.bubble);
this.messageTextView = (TextView) findViewById(R.id.message_text_view);
this.timestampTextView = (TextView) findViewById(R.id.timestamp_text_view);
this.profileIcon = (CircleImageView) findViewById(R.id.profile_icon);

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package co.intentservice.chatui.views;

import android.content.Context;
import android.net.Uri;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import co.intentservice.chatui.R;
import de.hdodenhof.circleimageview.CircleImageView;

/**
* MessageView is used to help support custom views without defining a custom viewholder,
Expand All @@ -17,6 +22,7 @@
public abstract class MessageView extends FrameLayout {

private TextView senderTextView;
private CircleImageView circleImageView;

/**
* Method to set the messages text in the view so it can be displayed on the screen.
Expand Down Expand Up @@ -46,6 +52,18 @@ public abstract class MessageView extends FrameLayout {
*/
public abstract void setElevation(float elevation);

/**
* Method to set sender's profile icon.
*
* @param uri The url of the pic that you want the view to be display.
*/
public void setProfileIcon(String uri){
if(circleImageView == null){
this.circleImageView = (CircleImageView)findViewById(R.id.profile_icon);
}
circleImageView.setVisibility(VISIBLE);
Picasso.get().load(Uri.parse(uri)).into(circleImageView);
}

/**
* Method to set the message's sender name.
Expand Down
106 changes: 63 additions & 43 deletions chat-ui/src/main/res/layout/chat_item_rcv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,81 @@
android:paddingEnd="72dp"
android:paddingRight="72dp">

<android.support.v7.widget.CardView
android:id="@+id/bubble"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
app:cardBackgroundColor="@color/default_bubble_color_rcv"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true">
android:paddingBottom="8dp">

<LinearLayout
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="10dp"
android:paddingTop="4dp"
android:layout_gravity="start"
android:layout_marginRight="10dp"
tools:src="@color/dark_gray"
android:visibility="gone"
tools:visibility="visible"/>

<android.support.v7.widget.CardView
android:id="@+id/bubble"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="start"
android:orientation="vertical"
android:padding="8dp">
android:layout_gravity="start"
app:cardBackgroundColor="@color/default_bubble_color_rcv"
app:cardCornerRadius="8dp">

<TextView
android:id="@+id/sender_text_view"
tools:text="Timi"
android:textSize="@dimen/default_message_text_size"
android:textColor="@color/default_message_color_rcv"
android:layout_gravity="center_vertical|start"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:textStyle="bold"
android:visibility="gone"
tools:visibility="visible"/>
android:gravity="start"
android:orientation="vertical"
android:padding="8dp">

<TextView
android:id="@+id/message_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:gravity="center_vertical|start"
android:textColor="@color/default_message_color_rcv"
android:textSize="@dimen/default_message_text_size"
tools:text="My name is Timi and I am..." />
<TextView
android:id="@+id/sender_text_view"
tools:text="Timi"
android:textSize="@dimen/default_message_text_size"
android:textColor="@color/default_message_color_rcv"
android:layout_gravity="center_vertical|start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:textStyle="bold"
android:visibility="gone"
tools:visibility="visible"/>

<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="4dp" />
<TextView
android:id="@+id/message_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:gravity="center_vertical|start"
android:textColor="@color/default_message_color_rcv"
android:textSize="@dimen/default_message_text_size"
tools:text="My name is Timi and I am..." />

<TextView
android:id="@+id/timestamp_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:gravity="center_vertical|end"
android:textColor="@color/default_tstamp_color_rcv"
android:textSize="@dimen/default_timestamp_text_size"
tools:text="12:10 am" />
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="4dp" />

<TextView
android:id="@+id/timestamp_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:gravity="center_vertical|end"
android:textColor="@color/default_tstamp_color_rcv"
android:textSize="@dimen/default_timestamp_text_size"
tools:text="12:10 am" />

</LinearLayout>

</android.support.v7.widget.CardView>

</LinearLayout>

</LinearLayout>

</android.support.v7.widget.CardView>

</FrameLayout>
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
#Mon Jul 16 08:51:47 CDT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip