From bdab469f9680ff10917dc3f5324c9dcd82c5d7d3 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 4 Jul 2019 18:49:55 +0400 Subject: [PATCH 1/9] Grouping messages from the same author --- .../chatkit/commons/models/IMessage.java | 1 + .../chatkit/messages/MessageHolders.java | 13 +++++- .../chatkit/messages/MessagesListAdapter.java | 40 ++++++++++++++++++- .../sample/common/data/model/Message.java | 1 + .../CustomIncomingImageMessageViewHolder.java | 9 +++++ .../CustomIncomingTextMessageViewHolder.java | 8 ++++ .../item_custom_incoming_text_message.xml | 2 +- 7 files changed, 71 insertions(+), 3 deletions(-) diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IMessage.java b/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IMessage.java index 4605aab3..52beca0e 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IMessage.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IMessage.java @@ -50,4 +50,5 @@ public interface IMessage { * @return the message creation date */ Date getCreatedAt(); + } diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java index c089cbdf..88d69545 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java @@ -563,7 +563,7 @@ protected ViewHolder getHolder(ViewGroup parent, int viewType, MessagesListStyle } @SuppressWarnings("unchecked") - protected void bind(final ViewHolder holder, final Object item, boolean isSelected, + protected void bind(final ViewHolder holder, final Object item, boolean isSelected, boolean isContinuous, final ImageLoader imageLoader, final View.OnClickListener onMessageClickListener, final View.OnLongClickListener onMessageLongClickListener, @@ -572,6 +572,7 @@ protected void bind(final ViewHolder holder, final Object item, boolean isSelect if (item instanceof IMessage) { ((MessageHolders.BaseMessageViewHolder) holder).isSelected = isSelected; + ((BaseMessageViewHolder) holder).isContinuous = isContinuous; ((MessageHolders.BaseMessageViewHolder) holder).imageLoader = imageLoader; holder.itemView.setOnLongClickListener(onMessageLongClickListener); holder.itemView.setOnClickListener(onMessageClickListener); @@ -676,6 +677,7 @@ public static abstract class BaseMessageViewHolder ext boolean isSelected; + boolean isContinuous; /** * For setting custom data to ViewHolder */ @@ -705,6 +707,15 @@ public boolean isSelected() { return isSelected; } + /** + * Returns whether item belongs to the same user + * + * @return weather item belongs to the same user. + */ + public boolean isContinuous() { + return isContinuous; + } + /** * Returns weather is selection mode enabled * diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java index e0fcb8a2..b4bfad5f 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -19,6 +19,7 @@ import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; +import android.graphics.Paint; import android.support.annotation.LayoutRes; import android.support.v7.widget.RecyclerView; import android.text.Spannable; @@ -34,6 +35,7 @@ import com.stfalcon.chatkit.commons.ImageLoader; import com.stfalcon.chatkit.commons.ViewHolder; import com.stfalcon.chatkit.commons.models.IMessage; +import com.stfalcon.chatkit.commons.models.IUser; import com.stfalcon.chatkit.utils.DateFormatter; import java.util.ArrayList; @@ -103,13 +105,45 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { @Override public void onBindViewHolder(ViewHolder holder, int position) { Wrapper wrapper = items.get(position); - holders.bind(holder, wrapper.item, wrapper.isSelected, imageLoader, + boolean isContinuous = false; + if (position > 0 && position != items.size() - 1) { + isContinuous = isContinuous(items.get(position), items.get(position - 1)); + } + holders.bind(holder, wrapper.item, wrapper.isSelected, isContinuous, imageLoader, getMessageClickListener(wrapper), getMessageLongClickListener(wrapper), dateHeadersFormatter, viewClickListenersArray); } + private boolean isContinuous(Wrapper currentMsg, Wrapper precedingMsg) { + // null check + if (currentMsg == null || precedingMsg == null) { + return false; + } + + IUser currentUser = null, precedingUser = null; + if (currentMsg.item instanceof IMessage) { + currentUser = ((IMessage) currentMsg.item).getUser(); + } else { + return false; + } + if (precedingMsg.item instanceof IMessage) { + precedingUser = ((IMessage) precedingMsg.item).getUser(); + } else { + return false; + } + + + System.out.println(" ------------------ " + (!(currentUser == null || precedingUser == null) + && currentUser.getId().equals(precedingUser.getId()))); + // If admin message or + return !(currentUser == null || precedingUser == null) + && currentUser.getId().equals(precedingUser.getId()); + + + } + @Override public int getItemCount() { return items.size(); @@ -155,7 +189,11 @@ public void addToStart(MESSAGE message, boolean scroll) { } Wrapper element = new Wrapper<>(message); items.add(0, element); + boolean isContinuous = isPreviousSameAuthor(message.getUser().getId(), 0); notifyItemRangeInserted(0, isNewMessageToday ? 2 : 1); + if (isContinuous) { + notifyItemChanged(1); + } if (layoutManager != null && scroll) { layoutManager.scrollToPosition(0); } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/common/data/model/Message.java b/sample/src/main/java/com/stfalcon/chatkit/sample/common/data/model/Message.java index c24fd039..a458bafd 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/common/data/model/Message.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/common/data/model/Message.java @@ -18,6 +18,7 @@ public class Message implements IMessage, private User user; private Image image; private Voice voice; + private boolean isContinous; public Message(String id, User user, String text) { this(id, user, text, new Date()); diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomIncomingImageMessageViewHolder.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomIncomingImageMessageViewHolder.java index 124b4cc4..9f6aecfa 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomIncomingImageMessageViewHolder.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomIncomingImageMessageViewHolder.java @@ -1,5 +1,6 @@ package com.stfalcon.chatkit.sample.features.demo.custom.holder.holders.messages; +import android.animation.Animator; import android.view.View; import com.stfalcon.chatkit.messages.MessageHolders; @@ -29,5 +30,13 @@ public void onBind(Message message) { } else { onlineIndicator.setBackgroundResource(R.drawable.shape_bubble_offline); } + + if (isContinuous()) { + userAvatar.setVisibility(View.INVISIBLE); + onlineIndicator.setVisibility(View.GONE); + } else { + userAvatar.setVisibility(View.VISIBLE); + onlineIndicator.setVisibility(View.VISIBLE); + } } } \ No newline at end of file diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomIncomingTextMessageViewHolder.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomIncomingTextMessageViewHolder.java index a846a840..fe1cc072 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomIncomingTextMessageViewHolder.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomIncomingTextMessageViewHolder.java @@ -1,5 +1,6 @@ package com.stfalcon.chatkit.sample.features.demo.custom.holder.holders.messages; +import android.animation.Animator; import android.view.View; import com.stfalcon.chatkit.messages.MessageHolders; @@ -37,6 +38,13 @@ public void onClick(View view) { } } }); + if (isContinuous()) { + userAvatar.setVisibility(View.INVISIBLE); + onlineIndicator.setVisibility(View.GONE); + } else { + userAvatar.setVisibility(View.VISIBLE); + onlineIndicator.setVisibility(View.VISIBLE); + } } public static class Payload { diff --git a/sample/src/main/res/layout/item_custom_incoming_text_message.xml b/sample/src/main/res/layout/item_custom_incoming_text_message.xml index bc1bbd96..52d52e7c 100644 --- a/sample/src/main/res/layout/item_custom_incoming_text_message.xml +++ b/sample/src/main/res/layout/item_custom_incoming_text_message.xml @@ -9,7 +9,7 @@ From 8fed5ca90db3f24a946ed768156d26a8851c6070 Mon Sep 17 00:00:00 2001 From: oziomaogbe Date: Tue, 5 Jan 2021 12:02:33 +0100 Subject: [PATCH 2/9] migrate to android x --- build.gradle | 2 +- chatkit/build.gradle | 6 +++--- .../java/com/stfalcon/chatkit/commons/ImageLoader.java | 2 +- .../main/java/com/stfalcon/chatkit/commons/Style.java | 10 +++++----- .../java/com/stfalcon/chatkit/commons/ViewHolder.java | 2 +- .../chatkit/commons/models/MessageContentType.java | 2 +- .../java/com/stfalcon/chatkit/dialogs/DialogsList.java | 10 +++++----- .../stfalcon/chatkit/dialogs/DialogsListAdapter.java | 6 +++--- .../com/stfalcon/chatkit/messages/MessageHolders.java | 6 +++--- .../com/stfalcon/chatkit/messages/MessageInput.java | 4 ++-- .../stfalcon/chatkit/messages/MessageInputStyle.java | 6 +++--- .../com/stfalcon/chatkit/messages/MessagesList.java | 10 +++++----- .../stfalcon/chatkit/messages/MessagesListAdapter.java | 6 +++--- .../stfalcon/chatkit/messages/MessagesListStyle.java | 6 +++--- .../chatkit/messages/RecyclerScrollMoreListener.java | 8 ++++---- .../com/stfalcon/chatkit/utils/RoundedImageView.java | 9 ++++----- .../com/stfalcon/chatkit/utils/ShapeImageView.java | 2 +- chatkit/src/main/res/layout/view_message_input.xml | 4 ++-- gradle.properties | 2 ++ gradle/wrapper/gradle-wrapper.properties | 4 ++-- sample/build.gradle | 10 +++++----- .../chatkit/sample/ExampleInstrumentedTest.java | 4 ++-- .../sample/features/demo/DemoDialogsActivity.java | 4 ++-- .../sample/features/demo/DemoMessagesActivity.java | 4 ++-- .../chatkit/sample/features/main/MainActivity.java | 5 +++-- .../sample/features/main/adapter/DemoCardFragment.java | 3 ++- .../main/adapter/MainActivityPagerAdapter.java | 7 ++++--- .../com/stfalcon/chatkit/sample/utils/AppUtils.java | 2 +- sample/src/main/res/layout/activity_main.xml | 6 +++--- sample/src/main/res/layout/fragment_demo_card.xml | 4 ++-- sample/src/main/res/layout/item_sample.xml | 4 ++-- 31 files changed, 82 insertions(+), 78 deletions(-) diff --git a/build.gradle b/build.gradle index 80103afe..546a3744 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.3' + classpath 'com.android.tools.build:gradle:4.1.1' classpath 'com.novoda:bintray-release:0.8.0' // NOTE: Do not place your application dependencies here; they belong diff --git a/chatkit/build.gradle b/chatkit/build.gradle index f9b50b7f..50701cb3 100644 --- a/chatkit/build.gradle +++ b/chatkit/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.library' apply plugin: 'com.novoda.bintray-release' android { - compileSdkVersion 27 + compileSdkVersion 28 buildToolsVersion "27.0.3" defaultConfig { @@ -36,7 +36,7 @@ ext { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "com.android.support:appcompat-v7:$supportVersion" - implementation "com.android.support:design:$supportVersion" + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.0.0' implementation "com.google.android:flexbox:$flexboxVersion" } diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/commons/ImageLoader.java b/chatkit/src/main/java/com/stfalcon/chatkit/commons/ImageLoader.java index a0f7f44f..9043cb6c 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/commons/ImageLoader.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/commons/ImageLoader.java @@ -16,7 +16,7 @@ package com.stfalcon.chatkit.commons; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import android.widget.ImageView; /** diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/commons/Style.java b/chatkit/src/main/java/com/stfalcon/chatkit/commons/Style.java index fcbd8a77..80489b71 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/commons/Style.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/commons/Style.java @@ -20,11 +20,11 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; -import android.support.annotation.AttrRes; -import android.support.annotation.ColorRes; -import android.support.annotation.DimenRes; -import android.support.annotation.DrawableRes; -import android.support.v4.content.ContextCompat; +import androidx.annotation.AttrRes; +import androidx.annotation.ColorRes; +import androidx.annotation.DimenRes; +import androidx.annotation.DrawableRes; +import androidx.core.content.ContextCompat; import android.util.AttributeSet; import android.util.TypedValue; diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/commons/ViewHolder.java b/chatkit/src/main/java/com/stfalcon/chatkit/commons/ViewHolder.java index dff3193c..e5451012 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/commons/ViewHolder.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/commons/ViewHolder.java @@ -16,7 +16,7 @@ package com.stfalcon.chatkit.commons; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.RecyclerView; import android.view.View; /** diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/MessageContentType.java b/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/MessageContentType.java index b8f2675a..8737d5c0 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/MessageContentType.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/MessageContentType.java @@ -16,7 +16,7 @@ package com.stfalcon.chatkit.commons.models; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import com.stfalcon.chatkit.messages.MessageHolders; /* diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsList.java b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsList.java index 6336203d..4bb5ff75 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsList.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsList.java @@ -17,11 +17,11 @@ package com.stfalcon.chatkit.dialogs; import android.content.Context; -import android.support.annotation.Nullable; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.SimpleItemAnimator; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.recyclerview.widget.SimpleItemAnimator; import android.util.AttributeSet; import com.stfalcon.chatkit.commons.models.IDialog; diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java index dc48e7f0..6f255ca9 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -18,9 +18,9 @@ import android.graphics.Typeface; import android.graphics.drawable.GradientDrawable; -import android.support.annotation.LayoutRes; -import android.support.annotation.Nullable; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.LayoutRes; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.RecyclerView; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java index 88d69545..a1420278 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java @@ -1,8 +1,8 @@ package com.stfalcon.chatkit.messages; -import android.support.annotation.LayoutRes; -import android.support.annotation.NonNull; -import android.support.v4.view.ViewCompat; +import androidx.annotation.LayoutRes; +import androidx.annotation.NonNull; +import androidx.core.view.ViewCompat; import android.text.Spannable; import android.text.method.LinkMovementMethod; import android.util.SparseArray; diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInput.java b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInput.java index 16e42a35..80383041 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInput.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInput.java @@ -19,8 +19,8 @@ import android.content.Context; import android.graphics.drawable.Drawable; import android.os.Build; -import android.support.v4.view.ViewCompat; -import android.support.v4.widget.Space; +import androidx.core.view.ViewCompat; +import androidx.legacy.widget.Space; import android.text.Editable; import android.text.TextWatcher; import android.util.AttributeSet; diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInputStyle.java b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInputStyle.java index 1cea99c8..424e8a14 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInputStyle.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInputStyle.java @@ -20,9 +20,9 @@ import android.content.res.ColorStateList; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; -import android.support.annotation.ColorInt; -import android.support.annotation.DrawableRes; -import android.support.v4.graphics.drawable.DrawableCompat; +import androidx.annotation.ColorInt; +import androidx.annotation.DrawableRes; +import androidx.core.graphics.drawable.DrawableCompat; import android.util.AttributeSet; import com.stfalcon.chatkit.R; diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesList.java b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesList.java index 17b3f8ed..5559b38a 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesList.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesList.java @@ -17,11 +17,11 @@ package com.stfalcon.chatkit.messages; import android.content.Context; -import android.support.annotation.Nullable; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.SimpleItemAnimator; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.recyclerview.widget.SimpleItemAnimator; import android.util.AttributeSet; import com.stfalcon.chatkit.commons.models.IMessage; diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java index b4bfad5f..be984fcb 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -19,9 +19,9 @@ import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; -import android.graphics.Paint; -import android.support.annotation.LayoutRes; -import android.support.v7.widget.RecyclerView; + +import androidx.annotation.LayoutRes; +import androidx.recyclerview.widget.RecyclerView; import android.text.Spannable; import android.text.method.LinkMovementMethod; import android.util.SparseArray; diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListStyle.java b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListStyle.java index 88c6fe15..7bb7182f 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListStyle.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListStyle.java @@ -22,9 +22,9 @@ import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.Drawable; -import android.support.annotation.ColorInt; -import android.support.annotation.DrawableRes; -import android.support.v4.graphics.drawable.DrawableCompat; +import androidx.annotation.ColorInt; +import androidx.annotation.DrawableRes; +import androidx.core.graphics.drawable.DrawableCompat; import android.util.AttributeSet; import com.stfalcon.chatkit.R; diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/messages/RecyclerScrollMoreListener.java b/chatkit/src/main/java/com/stfalcon/chatkit/messages/RecyclerScrollMoreListener.java index 00012084..f6e61998 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/RecyclerScrollMoreListener.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/RecyclerScrollMoreListener.java @@ -16,10 +16,10 @@ package com.stfalcon.chatkit.messages; -import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.StaggeredGridLayoutManager; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.recyclerview.widget.StaggeredGridLayoutManager; class RecyclerScrollMoreListener extends RecyclerView.OnScrollListener { diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/utils/RoundedImageView.java b/chatkit/src/main/java/com/stfalcon/chatkit/utils/RoundedImageView.java index 7770fb13..62954e99 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/utils/RoundedImageView.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/utils/RoundedImageView.java @@ -18,12 +18,11 @@ import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.net.Uri; -import android.support.annotation.DimenRes; -import android.support.annotation.NonNull; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.AppCompatImageView; +import androidx.annotation.DimenRes; +import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; +import androidx.appcompat.widget.AppCompatImageView; import android.util.AttributeSet; -import android.widget.ImageView; /** * Thanks to Joonho Kim (https://github.com/pungrue26) for his lightweight SelectableRoundedImageView, diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/utils/ShapeImageView.java b/chatkit/src/main/java/com/stfalcon/chatkit/utils/ShapeImageView.java index b9f054c5..f212468a 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/utils/ShapeImageView.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/utils/ShapeImageView.java @@ -26,7 +26,7 @@ * ImageView with mask what described with Bézier Curves */ -public class ShapeImageView extends android.support.v7.widget.AppCompatImageView { +public class ShapeImageView extends androidx.appcompat.widget.AppCompatImageView { private Path path; public ShapeImageView(Context context) { diff --git a/chatkit/src/main/res/layout/view_message_input.xml b/chatkit/src/main/res/layout/view_message_input.xml index aaed1f5f..7f01ac9d 100644 --- a/chatkit/src/main/res/layout/view_message_input.xml +++ b/chatkit/src/main/res/layout/view_message_input.xml @@ -10,7 +10,7 @@ android:layout_height="wrap_content" android:layout_centerVertical="true"/> - - - - \ No newline at end of file + \ No newline at end of file diff --git a/sample/src/main/res/layout/fragment_demo_card.xml b/sample/src/main/res/layout/fragment_demo_card.xml index 87290af0..f20809f1 100644 --- a/sample/src/main/res/layout/fragment_demo_card.xml +++ b/sample/src/main/res/layout/fragment_demo_card.xml @@ -1,4 +1,4 @@ - - + diff --git a/sample/src/main/res/layout/item_sample.xml b/sample/src/main/res/layout/item_sample.xml index f970b2e6..8bfce6df 100644 --- a/sample/src/main/res/layout/item_sample.xml +++ b/sample/src/main/res/layout/item_sample.xml @@ -1,4 +1,4 @@ - - \ No newline at end of file + \ No newline at end of file From 924fff17c12543329e27616f91db91d3b776555f Mon Sep 17 00:00:00 2001 From: oziomaogbe Date: Tue, 5 Jan 2021 12:12:23 +0100 Subject: [PATCH 3/9] Add chat kit library as a submodule --- chatkit/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/chatkit/build.gradle b/chatkit/build.gradle index 50701cb3..9af08079 100644 --- a/chatkit/build.gradle +++ b/chatkit/build.gradle @@ -19,6 +19,7 @@ android { } publish { + userOrg = 'egeniq' groupId = 'com.github.stfalcon' artifactId = 'chatkit' publishVersion = '0.3.3' From ef5e1e3e4a363a9bb64ecbf8ce0ff3a70946f732 Mon Sep 17 00:00:00 2001 From: oziomaogbe Date: Tue, 5 Jan 2021 15:08:51 +0100 Subject: [PATCH 4/9] Group items from theame user --- .../chatkit/messages/MessageHolders.java | 42 ++++++++++++++++++- .../chatkit/messages/MessagesListAdapter.java | 38 ++++++++++++++++- 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java index a1420278..0ce976c1 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java @@ -3,6 +3,7 @@ import androidx.annotation.LayoutRes; import androidx.annotation.NonNull; import androidx.core.view.ViewCompat; + import android.text.Spannable; import android.text.method.LinkMovementMethod; import android.util.SparseArray; @@ -563,7 +564,8 @@ protected ViewHolder getHolder(ViewGroup parent, int viewType, MessagesListStyle } @SuppressWarnings("unchecked") - protected void bind(final ViewHolder holder, final Object item, boolean isSelected, boolean isContinuous, + protected void bind(final ViewHolder holder, final Object item, boolean isSelected, + boolean isContinuous, boolean nextIsContinuous, final ImageLoader imageLoader, final View.OnClickListener onMessageClickListener, final View.OnLongClickListener onMessageLongClickListener, @@ -678,6 +680,8 @@ public static abstract class BaseMessageViewHolder ext boolean isSelected; boolean isContinuous; + + boolean nextItemIsContinous; /** * For setting custom data to ViewHolder */ @@ -716,6 +720,22 @@ public boolean isContinuous() { return isContinuous; } + /** + * Returns whether the current item and the next belongs to the same user + */ + public boolean isNextItemIsContinuous() { + return isContinuous; + } + + public List getVisibleViewsForFirstItemInGroup() { + return new ArrayList<>(); + } + + public List getVisibleViewsForLastItemInGroup() { + return new ArrayList<>(); + } + + /** * Returns weather is selection mode enabled * @@ -780,6 +800,26 @@ public void onBind(MESSAGE message) { if (text != null) { text.setText(message.getText()); } + + if (isNextItemIsContinuous()) { + for (View continousView : getVisibleViewsForLastItemInGroup()) { + continousView.setVisibility(View.GONE); + } + } else { + for (View continousView : getVisibleViewsForLastItemInGroup()) { + continousView.setVisibility(View.VISIBLE); + } + } + + if (isContinuous()) { + for (View continousView : getVisibleViewsForFirstItemInGroup()) { + continousView.setVisibility(View.VISIBLE); + } + } else { + for (View continousView : getVisibleViewsForFirstItemInGroup()) { + continousView.setVisibility(View.INVISIBLE); + } + } } @Override diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java index be984fcb..8bdc411c 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -22,6 +22,7 @@ import androidx.annotation.LayoutRes; import androidx.recyclerview.widget.RecyclerView; + import android.text.Spannable; import android.text.method.LinkMovementMethod; import android.util.SparseArray; @@ -106,10 +107,15 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public void onBindViewHolder(ViewHolder holder, int position) { Wrapper wrapper = items.get(position); boolean isContinuous = false; + boolean nextItemIsContinous = false; if (position > 0 && position != items.size() - 1) { isContinuous = isContinuous(items.get(position), items.get(position - 1)); } - holders.bind(holder, wrapper.item, wrapper.isSelected, isContinuous, imageLoader, + + if (position + 1 < items.size() - 1) { + nextItemIsContinous = nextItemIsContinous(items.get(position), items.get(position + 1)); + } + holders.bind(holder, wrapper.item, wrapper.isSelected, isContinuous, nextItemIsContinous, imageLoader, getMessageClickListener(wrapper), getMessageLongClickListener(wrapper), dateHeadersFormatter, @@ -122,7 +128,7 @@ private boolean isContinuous(Wrapper currentMsg, Wrapper precedingMsg) { return false; } - IUser currentUser = null, precedingUser = null; + IUser currentUser, precedingUser; if (currentMsg.item instanceof IMessage) { currentUser = ((IMessage) currentMsg.item).getUser(); } else { @@ -142,6 +148,34 @@ private boolean isContinuous(Wrapper currentMsg, Wrapper precedingMsg) { && currentUser.getId().equals(precedingUser.getId()); + } + + private boolean nextItemIsContinous(Wrapper currentMsg, Wrapper nextMessage) { + // null check + if (currentMsg == null || nextMessage == null) { + return false; + } + + IUser currentUser, precedingUser; + if (currentMsg.item instanceof IMessage) { + currentUser = ((IMessage) currentMsg.item).getUser(); + } else { + return false; + } + if (nextMessage.item instanceof IMessage) { + precedingUser = ((IMessage) nextMessage.item).getUser(); + } else { + return false; + } + + + System.out.println(" ------------------ " + (!(currentUser == null || precedingUser == null) + && currentUser.getId().equals(precedingUser.getId()))); + // If admin message or + return !(currentUser == null || precedingUser == null) + && currentUser.getId().equals(precedingUser.getId()); + + } @Override From 7c08a5ca4c9daba0e0923d22fd0156502d74115e Mon Sep 17 00:00:00 2001 From: oziomaogbe Date: Wed, 6 Jan 2021 10:26:29 +0100 Subject: [PATCH 5/9] Fix bug groupng items --- .../chatkit/messages/MessageHolders.java | 45 +++++++++++----- .../chatkit/messages/MessagesListAdapter.java | 54 ++++++++----------- 2 files changed, 56 insertions(+), 43 deletions(-) diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java index 0ce976c1..f367647a 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java @@ -565,7 +565,7 @@ protected ViewHolder getHolder(ViewGroup parent, int viewType, MessagesListStyle @SuppressWarnings("unchecked") protected void bind(final ViewHolder holder, final Object item, boolean isSelected, - boolean isContinuous, boolean nextIsContinuous, + boolean isContinuous, boolean isLastItemInGroup, final ImageLoader imageLoader, final View.OnClickListener onMessageClickListener, final View.OnLongClickListener onMessageLongClickListener, @@ -574,8 +574,9 @@ protected void bind(final ViewHolder holder, final Object item, boolean isSelect if (item instanceof IMessage) { ((MessageHolders.BaseMessageViewHolder) holder).isSelected = isSelected; - ((BaseMessageViewHolder) holder).isContinuous = isContinuous; ((MessageHolders.BaseMessageViewHolder) holder).imageLoader = imageLoader; + ((BaseMessageViewHolder) holder).isFirstItemInGroup = isContinuous; + ((BaseMessageViewHolder) holder).isLastItemInGroup = isLastItemInGroup; holder.itemView.setOnLongClickListener(onMessageLongClickListener); holder.itemView.setOnClickListener(onMessageClickListener); @@ -679,9 +680,9 @@ public static abstract class BaseMessageViewHolder ext boolean isSelected; - boolean isContinuous; + boolean isFirstItemInGroup; - boolean nextItemIsContinous; + boolean isLastItemInGroup; /** * For setting custom data to ViewHolder */ @@ -716,15 +717,15 @@ public boolean isSelected() { * * @return weather item belongs to the same user. */ - public boolean isContinuous() { - return isContinuous; + public boolean isFirstItemInGroup() { + return isFirstItemInGroup; } /** * Returns whether the current item and the next belongs to the same user */ - public boolean isNextItemIsContinuous() { - return isContinuous; + public boolean isLastItemInGroup() { + return isLastItemInGroup; } public List getVisibleViewsForFirstItemInGroup() { @@ -801,17 +802,17 @@ public void onBind(MESSAGE message) { text.setText(message.getText()); } - if (isNextItemIsContinuous()) { + if (isLastItemInGroup()) { for (View continousView : getVisibleViewsForLastItemInGroup()) { - continousView.setVisibility(View.GONE); + continousView.setVisibility(View.VISIBLE); } } else { for (View continousView : getVisibleViewsForLastItemInGroup()) { - continousView.setVisibility(View.VISIBLE); + continousView.setVisibility(View.GONE); } } - if (isContinuous()) { + if (isFirstItemInGroup()) { for (View continousView : getVisibleViewsForFirstItemInGroup()) { continousView.setVisibility(View.VISIBLE); } @@ -879,6 +880,26 @@ public void onBind(MESSAGE message) { if (text != null) { text.setText(message.getText()); } + + if (isLastItemInGroup()) { + for (View continousView : getVisibleViewsForLastItemInGroup()) { + continousView.setVisibility(View.VISIBLE); + } + } else { + for (View continousView : getVisibleViewsForLastItemInGroup()) { + continousView.setVisibility(View.GONE); + } + } + + if (isFirstItemInGroup()) { + for (View continousView : getVisibleViewsForFirstItemInGroup()) { + continousView.setVisibility(View.VISIBLE); + } + } else { + for (View continousView : getVisibleViewsForFirstItemInGroup()) { + continousView.setVisibility(View.INVISIBLE); + } + } } @Override diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java index 8bdc411c..ec9eed57 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -106,76 +106,68 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { @Override public void onBindViewHolder(ViewHolder holder, int position) { Wrapper wrapper = items.get(position); - boolean isContinuous = false; - boolean nextItemIsContinous = false; - if (position > 0 && position != items.size() - 1) { - isContinuous = isContinuous(items.get(position), items.get(position - 1)); + boolean isFirstItemInGroup = true; + boolean isLastItemInGroup = true; + if (position < items.size() - 1) { + isFirstItemInGroup = isFirstItemInGroup(items.get(position), items.get(position + 1)); } - if (position + 1 < items.size() - 1) { - nextItemIsContinous = nextItemIsContinous(items.get(position), items.get(position + 1)); + if (position > 0) { + isLastItemInGroup = isLastItemInGroup(items.get(position), items.get(position - 1)); } - holders.bind(holder, wrapper.item, wrapper.isSelected, isContinuous, nextItemIsContinous, imageLoader, + holders.bind(holder, wrapper.item, wrapper.isSelected, isFirstItemInGroup, isLastItemInGroup, imageLoader, getMessageClickListener(wrapper), getMessageLongClickListener(wrapper), dateHeadersFormatter, viewClickListenersArray); } - private boolean isContinuous(Wrapper currentMsg, Wrapper precedingMsg) { + private boolean isFirstItemInGroup(Wrapper currentMsg, Wrapper precedingMsg) { // null check if (currentMsg == null || precedingMsg == null) { - return false; + return true; } IUser currentUser, precedingUser; if (currentMsg.item instanceof IMessage) { currentUser = ((IMessage) currentMsg.item).getUser(); } else { - return false; + return true; } if (precedingMsg.item instanceof IMessage) { precedingUser = ((IMessage) precedingMsg.item).getUser(); } else { - return false; + return true; } - - System.out.println(" ------------------ " + (!(currentUser == null || precedingUser == null) - && currentUser.getId().equals(precedingUser.getId()))); // If admin message or - return !(currentUser == null || precedingUser == null) - && currentUser.getId().equals(precedingUser.getId()); - - + if (currentUser == null || precedingUser == null) return true; + return !(currentUser.getId().equals(precedingUser.getId())); } - private boolean nextItemIsContinous(Wrapper currentMsg, Wrapper nextMessage) { + private boolean isLastItemInGroup(Wrapper currentMsg, Wrapper nextMessage) { // null check if (currentMsg == null || nextMessage == null) { - return false; + return true; } - IUser currentUser, precedingUser; + IUser currentUser, nextUser; if (currentMsg.item instanceof IMessage) { currentUser = ((IMessage) currentMsg.item).getUser(); } else { - return false; + return true; } if (nextMessage.item instanceof IMessage) { - precedingUser = ((IMessage) nextMessage.item).getUser(); + nextUser = ((IMessage) nextMessage.item).getUser(); } else { - return false; + return true; } - - System.out.println(" ------------------ " + (!(currentUser == null || precedingUser == null) - && currentUser.getId().equals(precedingUser.getId()))); // If admin message or - return !(currentUser == null || precedingUser == null) - && currentUser.getId().equals(precedingUser.getId()); - - + if (currentUser == null || nextUser == null) { + return true; + } + return !currentUser.getId().equals(nextUser.getId()); } @Override From 54fec16107b7ae83b9d16bc5805b1538582978bd Mon Sep 17 00:00:00 2001 From: oziomaogbe Date: Tue, 12 Jan 2021 16:38:11 +0100 Subject: [PATCH 6/9] setup bubbles to reflect text grouping --- chatkit/src/main/res/layout/item_incoming_text_message.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chatkit/src/main/res/layout/item_incoming_text_message.xml b/chatkit/src/main/res/layout/item_incoming_text_message.xml index 3c35437d..275084eb 100644 --- a/chatkit/src/main/res/layout/item_incoming_text_message.xml +++ b/chatkit/src/main/res/layout/item_incoming_text_message.xml @@ -3,10 +3,10 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginBottom="8dp" + android:layout_marginBottom="4dp" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" - android:layout_marginTop="8dp"> + android:layout_marginTop="4dp"> Date: Mon, 5 Jul 2021 09:13:40 +0100 Subject: [PATCH 7/9] Add improvements to messaging studio tabs 1. Do not recreate message fragment when its already top of the back stack in main activity 2. Do not use the same image cache for both message fragments. 3. Use View Pager 2 for messaging studio tabs. 4. Use new glide app for loading images --- .../java/com/stfalcon/chatkit/messages/MessagesList.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesList.java b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesList.java index 5559b38a..422818fc 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesList.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesList.java @@ -17,11 +17,13 @@ package com.stfalcon.chatkit.messages; import android.content.Context; + import androidx.annotation.Nullable; import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.SimpleItemAnimator; + import android.util.AttributeSet; import com.stfalcon.chatkit.commons.models.IMessage; @@ -75,13 +77,8 @@ void setAdapter(MessagesListAdapter adapter) { */ public void setAdapter(MessagesListAdapter adapter, boolean reverseLayout) { - SimpleItemAnimator itemAnimator = new DefaultItemAnimator(); - itemAnimator.setSupportsChangeAnimations(false); - LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, reverseLayout); - - setItemAnimator(itemAnimator); setLayoutManager(layoutManager); adapter.setLayoutManager(layoutManager); adapter.setStyle(messagesListStyle); From ec319b3b87147af63b22038fce415b5348a4ec45 Mon Sep 17 00:00:00 2001 From: Remy Benza <47558082+rbenza@users.noreply.github.com> Date: Tue, 31 Aug 2021 16:33:04 +0200 Subject: [PATCH 8/9] Remove nova bintray from repo --- build.gradle | 3 +-- chatkit/build.gradle | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index 546a3744..bce8b443 100644 --- a/build.gradle +++ b/build.gradle @@ -10,8 +10,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.1' - classpath 'com.novoda:bintray-release:0.8.0' + classpath 'com.android.tools.build:gradle:4.1.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/chatkit/build.gradle b/chatkit/build.gradle index 9af08079..0256e326 100644 --- a/chatkit/build.gradle +++ b/chatkit/build.gradle @@ -1,5 +1,5 @@ apply plugin: 'com.android.library' -apply plugin: 'com.novoda.bintray-release' + android { compileSdkVersion 28 @@ -18,16 +18,16 @@ android { } } -publish { - userOrg = 'egeniq' - groupId = 'com.github.stfalcon' - artifactId = 'chatkit' - publishVersion = '0.3.3' - desc = 'ChatKit - is a library designed to simplify the development of UI for such a trivial task as chat. It have flexible possibilities for styling, customizing and data management' - licences = ['Apache-2.0'] - uploadName = 'ChatKit' - website = 'https://github.com/stfalcon-studio/ChatKit.git' -} +//publish { +// userOrg = 'egeniq' +// groupId = 'com.github.stfalcon' +// artifactId = 'chatkit' +// publishVersion = '0.3.3' +// desc = 'ChatKit - is a library designed to simplify the development of UI for such a trivial task as chat. It have flexible possibilities for styling, customizing and data management' +// licences = ['Apache-2.0'] +// uploadName = 'ChatKit' +// website = 'https://github.com/stfalcon-studio/ChatKit.git' +//} ext { supportVersion = '27.1.1' From b26fd4381e3d62329f1053ae7815bc1374f6bbdf Mon Sep 17 00:00:00 2001 From: Remy Benza <47558082+rbenza@users.noreply.github.com> Date: Tue, 31 Aug 2021 17:00:15 +0200 Subject: [PATCH 9/9] Removed old libs / updated to new ones --- chatkit/build.gradle | 14 +------------- sample/build.gradle | 4 ++-- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/chatkit/build.gradle b/chatkit/build.gradle index 0256e326..9512c7eb 100644 --- a/chatkit/build.gradle +++ b/chatkit/build.gradle @@ -2,8 +2,7 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 28 - buildToolsVersion "27.0.3" + compileSdkVersion 30 defaultConfig { minSdkVersion 14 @@ -18,17 +17,6 @@ android { } } -//publish { -// userOrg = 'egeniq' -// groupId = 'com.github.stfalcon' -// artifactId = 'chatkit' -// publishVersion = '0.3.3' -// desc = 'ChatKit - is a library designed to simplify the development of UI for such a trivial task as chat. It have flexible possibilities for styling, customizing and data management' -// licences = ['Apache-2.0'] -// uploadName = 'ChatKit' -// website = 'https://github.com/stfalcon-studio/ChatKit.git' -//} - ext { supportVersion = '27.1.1' flexboxVersion = '1.0.0' diff --git a/sample/build.gradle b/sample/build.gradle index 84efa57e..1eea9c85 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,8 +1,8 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 27 - buildToolsVersion "27.0.3" + compileSdkVersion 30 + defaultConfig { applicationId "com.stfalcon.chatkit.sample" minSdkVersion 14