diff --git a/app/src/main/java/co/intentservice/chatui/sample/MainActivity.java b/app/src/main/java/co/intentservice/chatui/sample/MainActivity.java index 15bacea..819a46c 100644 --- a/app/src/main/java/co/intentservice/chatui/sample/MainActivity.java +++ b/app/src/main/java/co/intentservice/chatui/sample/MainActivity.java @@ -1,5 +1,6 @@ package co.intentservice.chatui.sample; +import android.net.Uri; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; @@ -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) { diff --git a/build.gradle b/build.gradle index 83eeae5..412fbf9 100644 --- a/build.gradle +++ b/build.gradle @@ -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 @@ -16,6 +17,7 @@ buildscript { allprojects { repositories { jcenter() + google() } } diff --git a/chat-ui/build.gradle b/chat-ui/build.gradle index 7ec8dab..d39cc9d 100644 --- a/chat-ui/build.gradle +++ b/chat-ui/build.gradle @@ -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' } diff --git a/chat-ui/src/main/java/co/intentservice/chatui/adapters/ChatViewListAdapter.java b/chat-ui/src/main/java/co/intentservice/chatui/adapters/ChatViewListAdapter.java index 2e01766..4d71602 100644 --- a/chat-ui/src/main/java/co/intentservice/chatui/adapters/ChatViewListAdapter.java +++ b/chat-ui/src/main/java/co/intentservice/chatui/adapters/ChatViewListAdapter.java @@ -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; } diff --git a/chat-ui/src/main/java/co/intentservice/chatui/models/ChatMessage.java b/chat-ui/src/main/java/co/intentservice/chatui/models/ChatMessage.java index d62200a..efb82ec 100644 --- a/chat-ui/src/main/java/co/intentservice/chatui/models/ChatMessage.java +++ b/chat-ui/src/main/java/co/intentservice/chatui/models/ChatMessage.java @@ -1,5 +1,6 @@ package co.intentservice.chatui.models; +import android.net.Uri; import android.text.format.DateFormat; import java.util.concurrent.TimeUnit; @@ -14,6 +15,7 @@ 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; @@ -21,11 +23,23 @@ public ChatMessage(String message, long timestamp, Type type) { 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; } @@ -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; diff --git a/chat-ui/src/main/java/co/intentservice/chatui/viewholders/MessageViewHolder.java b/chat-ui/src/main/java/co/intentservice/chatui/viewholders/MessageViewHolder.java index c20c4d4..7d2ebd7 100644 --- a/chat-ui/src/main/java/co/intentservice/chatui/viewholders/MessageViewHolder.java +++ b/chat-ui/src/main/java/co/intentservice/chatui/viewholders/MessageViewHolder.java @@ -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); } diff --git a/chat-ui/src/main/java/co/intentservice/chatui/views/ItemRecvView.java b/chat-ui/src/main/java/co/intentservice/chatui/views/ItemRecvView.java index 7c96bd5..3b06f40 100644 --- a/chat-ui/src/main/java/co/intentservice/chatui/views/ItemRecvView.java +++ b/chat-ui/src/main/java/co/intentservice/chatui/views/ItemRecvView.java @@ -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. @@ -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. @@ -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); } diff --git a/chat-ui/src/main/java/co/intentservice/chatui/views/MessageView.java b/chat-ui/src/main/java/co/intentservice/chatui/views/MessageView.java index 8c7eac5..090d12c 100644 --- a/chat-ui/src/main/java/co/intentservice/chatui/views/MessageView.java +++ b/chat-ui/src/main/java/co/intentservice/chatui/views/MessageView.java @@ -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, @@ -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. @@ -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. diff --git a/chat-ui/src/main/res/layout/chat_item_rcv.xml b/chat-ui/src/main/res/layout/chat_item_rcv.xml index 4691267..390da81 100644 --- a/chat-ui/src/main/res/layout/chat_item_rcv.xml +++ b/chat-ui/src/main/res/layout/chat_item_rcv.xml @@ -10,61 +10,81 @@ android:paddingEnd="72dp" android:paddingRight="72dp"> - + android:paddingBottom="8dp"> - + + + android:layout_gravity="start" + app:cardBackgroundColor="@color/default_bubble_color_rcv" + app:cardCornerRadius="8dp"> - + android:gravity="start" + android:orientation="vertical" + android:padding="8dp"> - + - + - + + + + + + + + + - - \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 04e285f..3a0b64c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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