From 0ae005ea558fa71cff31fbe0ad8485f3773977ee Mon Sep 17 00:00:00 2001 From: Alexander Krol Date: Thu, 13 Apr 2017 09:44:06 +0300 Subject: [PATCH 01/96] google play badge --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 0e1e3b38..8260eae7 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,10 @@ ChatKit is a library designed to simplify the development of UI for such a trivi ### Who we are Need iOS and Android apps, MVP development or prototyping? Contact us via info@stfalcon.com. We develop software since 2009, and we're known experts in this field. Check out our [portfolio](https://stfalcon.com/en/portfolio) and see more libraries from [stfalcon-studio](https://stfalcon-studio.github.io/). +## Demo Application + +[![Get it on Google Play](https://play.google.com/intl/en_us/badges/images/badge_new.png)](https://play.google.com/store/apps/details?id=com.stfalcon.chatkit.sample) + ### How to use To implement all of the features above you can use the following components: From 87a0eea9ff2b503e3f38e28293d6387e14cc2f20 Mon Sep 17 00:00:00 2001 From: Matias Radzinski Date: Tue, 2 May 2017 19:56:36 -0300 Subject: [PATCH 02/96] Allow the user to get the current position of a DIALOG This should close issue #29. I believe that providing the user with the whole list of DIALOG objects is a bit "dangerous", users can modify that collection and feed it back to the adapter and given the current implementation that's not something we might want. So having a ```getDialogPosition()``` method should solve the case when the user needs to have the current adapter position of a certain dialog. --- .../com/stfalcon/chatkit/dialogs/DialogsListAdapter.java | 7 +++++++ 1 file changed, 7 insertions(+) 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 87a10784..59421fbb 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -349,6 +349,13 @@ public void setDatesFormatter(DateFormatter.Formatter datesFormatter) { void setStyle(DialogListStyle dialogStyle) { this.dialogStyle = dialogStyle; } + + /** + * @return the position of a dialog in the dialogs list. + */ + public int getDialogPosition(DIALOG dialog) { + return this.items.indexOf(dialog); + } /* * LISTENERS From 2b8e57a5a06e7b694ed8bfd13f19b25d508d3bfd Mon Sep 17 00:00:00 2001 From: troy379 Date: Wed, 3 May 2017 12:31:51 +0300 Subject: [PATCH 03/96] exceptions on holder creating --- .../java/com/stfalcon/chatkit/messages/MessageHolders.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 9c52143a..bd9daed8 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java @@ -341,7 +341,7 @@ ViewHolder getHolder(ViewGroup parent, int viewType, MessagesListStyle messagesL } } } - return null; + throw new IllegalStateException("Wrong message view type. Please, report this issue on GitHub with full stacktrace in description."); } @SuppressWarnings("unchecked") @@ -394,7 +394,7 @@ ViewHolder getHolder(ViewGroup parent, @LayoutRes int layout, Class hold } return holder; } catch (Exception e) { - return null; + throw new RuntimeException("Somehow we couldn't create the ViewHolder for message. Please, report this issue on GitHub with full stacktrace in description.", e); } } From 3c4c85e43238bd9199cd1f4faa9b2d9dddf19bae Mon Sep 17 00:00:00 2001 From: troy379 Date: Wed, 3 May 2017 12:38:44 +0300 Subject: [PATCH 04/96] setAdapter with reverse layout mode --- .../stfalcon/chatkit/dialogs/DialogsList.java | 19 ++++++++++++++++--- .../chatkit/messages/MessagesList.java | 16 ++++++++++++++-- 2 files changed, 30 insertions(+), 5 deletions(-) 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 4ad4aab1..55f531af 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsList.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsList.java @@ -68,17 +68,30 @@ public void setAdapter(Adapter adapter) { } /** - * Set adapter for DialogsList + * Sets adapter for DialogsList * * @param adapter Adapter. Must extend DialogsListAdapter * @param Dialog model class */ - public void setAdapter(DialogsListAdapter adapter) { + public + void setAdapter(DialogsListAdapter adapter) { + setAdapter(adapter, true); + } + + /** + * Sets adapter for DialogsList + * + * @param adapter Adapter. Must extend DialogsListAdapter + * @param reverseLayout weather to use reverse layout for layout manager. + * @param Dialog model class + */ + public + void setAdapter(DialogsListAdapter adapter, boolean reverseLayout) { SimpleItemAnimator itemAnimator = new DefaultItemAnimator(); itemAnimator.setSupportsChangeAnimations(false); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), - LinearLayoutManager.VERTICAL, true); + LinearLayoutManager.VERTICAL, reverseLayout); setItemAnimator(itemAnimator); setLayoutManager(layoutManager); 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 654783e3..17b3f8ed 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesList.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesList.java @@ -56,18 +56,30 @@ public void setAdapter(Adapter adapter) { } /** - * Set adapter for MessagesList + * Sets adapter for MessagesList * * @param adapter Adapter. Must extend MessagesListAdapter * @param Message model class */ public void setAdapter(MessagesListAdapter adapter) { + setAdapter(adapter, true); + } + + /** + * Sets adapter for MessagesList + * + * @param adapter Adapter. Must extend MessagesListAdapter + * @param reverseLayout weather to use reverse layout for layout manager. + * @param Message model class + */ + public + void setAdapter(MessagesListAdapter adapter, boolean reverseLayout) { SimpleItemAnimator itemAnimator = new DefaultItemAnimator(); itemAnimator.setSupportsChangeAnimations(false); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), - LinearLayoutManager.VERTICAL, true); + LinearLayoutManager.VERTICAL, reverseLayout); setItemAnimator(itemAnimator); setLayoutManager(layoutManager); From bcdc6bb8f9741e0ca7c74dcb5f4e7e2dffcf39fe Mon Sep 17 00:00:00 2001 From: troy379 Date: Wed, 3 May 2017 16:04:59 +0300 Subject: [PATCH 05/96] view click listeners --- .../chatkit/dialogs/DialogsListAdapter.java | 100 ++++++++++++++---- .../chatkit/messages/MessagesListAdapter.java | 76 +++++++++++-- 2 files changed, 148 insertions(+), 28 deletions(-) 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 87a10784..444ef76a 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -1,4 +1,4 @@ -/******************************************************************************* +/****************************************************************************** * Copyright 2016 stfalcon.com *

* Licensed under the Apache License, Version 2.0 (the "License"); @@ -54,7 +54,9 @@ public class DialogsListAdapter

private Class holderClass; private ImageLoader imageLoader; private OnDialogClickListener onDialogClickListener; + private OnDialogViewClickListener onDialogViewClickListener; private OnDialogLongClickListener onLongItemClickListener; + private OnDialogViewLongClickListener onDialogViewLongClickListener; private DialogListStyle dialogStyle; private DateFormatter.Formatter datesFormatter; @@ -96,7 +98,9 @@ public DialogsListAdapter(@LayoutRes int itemLayoutId, Class onDialogClick this.onDialogClickListener = onDialogClickListener; } + /** + * @return the view click callback. + */ + public OnDialogViewClickListener getOnDialogViewClickListener() { + return onDialogViewClickListener; + } + + /** + * Register a callback to be invoked when dialog view is clicked. + * + * @param clickListener on click item callback + */ + public void setOnDialogViewClickListener(OnDialogViewClickListener clickListener) { + this.onDialogViewClickListener = clickListener; + } + /** * @return on long click item callback */ @@ -338,6 +359,22 @@ public void setOnDialogLongClickListener(OnDialogLongClickListener onLon this.onLongItemClickListener = onLongItemClickListener; } + /** + * @return on view long click callback + */ + public OnDialogViewLongClickListener getOnDialogViewLongClickListener() { + return onDialogViewLongClickListener; + } + + /** + * Register a callback to be invoked when item view is long clicked. + * + * @param clickListener on long click item callback + */ + public void setOnDialogViewLongClickListener(OnDialogViewLongClickListener clickListener) { + this.onDialogViewLongClickListener = clickListener; + } + /** * Sets custom {@link DateFormatter.Formatter} for text representation of last message date. */ @@ -357,10 +394,18 @@ public interface OnDialogClickListener { void onDialogClick(DIALOG dialog); } + public interface OnDialogViewClickListener { + void onDialogViewClick(View view, DIALOG dialog); + } + public interface OnDialogLongClickListener { void onDialogLongClick(DIALOG dialog); } + public interface OnDialogViewLongClickListener { + void onDialogViewLongClick(View view, DIALOG dialog); + } + /* * HOLDERS * */ @@ -368,8 +413,10 @@ public abstract static class BaseDialogViewHolder extends ViewHolder { protected ImageLoader imageLoader; - protected OnDialogClickListener onDialogClickListener; - protected OnDialogLongClickListener onLongItemClickListener; + protected OnDialogClickListener onDialogClickListener; + protected OnDialogLongClickListener onLongItemClickListener; + protected OnDialogViewClickListener onDialogViewClickListener; + protected OnDialogViewLongClickListener onDialogViewLongClickListener; protected DateFormatter.Formatter datesFormatter; public BaseDialogViewHolder(View itemView) { @@ -380,14 +427,22 @@ void setImageLoader(ImageLoader imageLoader) { this.imageLoader = imageLoader; } - void setOnDialogClickListener(OnDialogClickListener onDialogClickListener) { + void setOnDialogClickListener(OnDialogClickListener onDialogClickListener) { this.onDialogClickListener = onDialogClickListener; } - void setOnLongItemClickListener(OnDialogLongClickListener onLongItemClickListener) { + void setOnDialogViewClickListener(OnDialogViewClickListener onDialogViewClickListener) { + this.onDialogViewClickListener = onDialogViewClickListener; + } + + void setOnLongItemClickListener(OnDialogLongClickListener onLongItemClickListener) { this.onLongItemClickListener = onLongItemClickListener; } + void setOnDialogViewLongClickListener(OnDialogViewLongClickListener onDialogViewLongClickListener) { + this.onDialogViewLongClickListener = onDialogViewLongClickListener; + } + public void setDatesFormatter(DateFormatter.Formatter dateHeadersFormatter) { this.datesFormatter = dateHeadersFormatter; } @@ -553,24 +608,31 @@ public void onBind(final DIALOG dialog) { tvBubble.setVisibility(dialogStyle.isDialogUnreadBubbleEnabled() && dialog.getUnreadCount() > 0 ? VISIBLE : GONE); - if (onDialogClickListener != null) { - container.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { + container.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (onDialogClickListener != null) { onDialogClickListener.onDialogClick(dialog); } - }); - } + if (onDialogViewClickListener != null) { + onDialogViewClickListener.onDialogViewClick(view, dialog); + } + } + }); - if (onLongItemClickListener != null) { - container.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { + + container.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View view) { + if (onLongItemClickListener != null) { onLongItemClickListener.onDialogLongClick(dialog); - return true; } - }); - } + if (onDialogViewLongClickListener != null) { + onDialogViewLongClickListener.onDialogViewLongClick(view, dialog); + } + return onLongItemClickListener != null || onDialogViewLongClickListener != null; + } + }); } protected String getDateString(Date date) { 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 7d690948..45174132 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -58,7 +58,9 @@ public class MessagesListAdapter private OnLoadMoreListener loadMoreListener; private OnMessageClickListener onMessageClickListener; + private OnMessageViewClickListener onMessageViewClickListener; private OnMessageLongClickListener onMessageLongClickListener; + private OnMessageViewLongClickListener onMessageViewLongClickListener; private ImageLoader imageLoader; private RecyclerView.LayoutManager layoutManager; private MessagesListStyle messagesListStyle; @@ -77,9 +79,9 @@ public MessagesListAdapter(String senderId, ImageLoader imageLoader) { /** * For default list item layout and view holder. * - * @param senderId identifier of sender. - * @param holders custom layouts and view holders. See {@link MessageHolders} documentation for details - * @param imageLoader image loading method. + * @param senderId identifier of sender. + * @param holders custom layouts and view holders. See {@link MessageHolders} documentation for details + * @param imageLoader image loading method. */ public MessagesListAdapter(String senderId, MessageHolders holders, ImageLoader imageLoader) { @@ -358,6 +360,15 @@ public void setOnMessageClickListener(OnMessageClickListener onMessageC this.onMessageClickListener = onMessageClickListener; } + /** + * Sets click listener for message view. Fires ONLY if list is not in selection mode. + * + * @param onMessageViewClickListener click listener. + */ + public void setOnMessageViewClickListener(OnMessageViewClickListener onMessageViewClickListener) { + this.onMessageViewClickListener = onMessageViewClickListener; + } + /** * Sets long click listener for item. Fires only if selection mode is disabled. * @@ -367,6 +378,15 @@ public void setOnMessageLongClickListener(OnMessageLongClickListener on this.onMessageLongClickListener = onMessageLongClickListener; } + /** + * Sets long click listener for message view. Fires ONLY if selection mode is disabled. + * + * @param onMessageViewLongClickListener long click listener. + */ + public void setOnMessageViewLongClickListener(OnMessageViewLongClickListener onMessageViewLongClickListener) { + this.onMessageViewLongClickListener = onMessageViewLongClickListener; + } + /** * Set callback to be invoked when list scrolled to top. * @@ -451,10 +471,8 @@ private boolean isPreviousSameDate(int position, Date dateToCompare) { private boolean isPreviousSameAuthor(String id, int position) { int prevPosition = position + 1; if (items.size() <= prevPosition) return false; - - if (items.get(prevPosition).item instanceof IMessage) { - return ((MESSAGE) items.get(prevPosition).item).getUser().getId().contentEquals(id); - } else return false; + else return items.get(prevPosition).item instanceof IMessage + && ((MESSAGE) items.get(prevPosition).item).getUser().getId().contentEquals(id); } private void incrementSelectedItemsCount() { @@ -481,12 +499,24 @@ private void notifyMessageClicked(MESSAGE message) { } } + private void notifyMessageViewClicked(View view, MESSAGE message) { + if (onMessageViewClickListener != null) { + onMessageViewClickListener.onMessageViewClick(view, message); + } + } + private void notifyMessageLongClicked(MESSAGE message) { if (onMessageLongClickListener != null) { onMessageLongClickListener.onMessageLongClick(message); } } + private void notifyMessageViewLongClicked(View view, MESSAGE message) { + if (onMessageViewLongClickListener != null) { + onMessageViewLongClickListener.onMessageViewLongClick(view, message); + } + } + private View.OnClickListener getMessageClickListener(final Wrapper wrapper) { return new View.OnClickListener() { @Override @@ -501,6 +531,7 @@ public void onClick(View view) { notifyItemChanged(getMessagePositionById(message.getId())); } else { notifyMessageClicked(wrapper.item); + notifyMessageViewClicked(view, wrapper.item); } } }; @@ -512,6 +543,7 @@ private View.OnLongClickListener getMessageLongClickListener(final Wrapper { /** - * Fires when message was clicked. + * Fires when message is clicked. * * @param message clicked message. */ void onMessageClick(MESSAGE message); } + /** + * Interface definition for a callback to be invoked when message view is clicked. + */ + public interface OnMessageViewClickListener { + + /** + * Fires when message view is clicked. + * + * @param message clicked message. + */ + void onMessageViewClick(View view, MESSAGE message); + } + /** * Interface definition for a callback to be invoked when message item is long clicked. */ public interface OnMessageLongClickListener { /** - * Fires when message was long clicked. + * Fires when message is long clicked. * * @param message clicked message. */ void onMessageLongClick(MESSAGE message); } + /** + * Interface definition for a callback to be invoked when message view is long clicked. + */ + public interface OnMessageViewLongClickListener { + + /** + * Fires when message view is long clicked. + * + * @param message clicked message. + */ + void onMessageViewLongClick(View view, MESSAGE message); + } + /** * Interface used to format your message model when copying. */ From 7d7763961e464eef32cbe7b4b136d92a49ee08e5 Mon Sep 17 00:00:00 2001 From: troy379 Date: Wed, 3 May 2017 16:05:32 +0300 Subject: [PATCH 06/96] minSdk 14 --- chatkit/build.gradle | 2 +- .../java/com/stfalcon/chatkit/messages/MessagesListAdapter.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/chatkit/build.gradle b/chatkit/build.gradle index db17162b..aa4d2962 100644 --- a/chatkit/build.gradle +++ b/chatkit/build.gradle @@ -6,7 +6,7 @@ android { buildToolsVersion "25.0.2" defaultConfig { - minSdkVersion 16 + minSdkVersion 14 targetSdkVersion 25 versionCode 1 versionName "0.2.0" 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 45174132..aedcf4eb 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -547,7 +547,7 @@ public boolean onLongClick(View view) { return true; } else { isSelectionModeEnabled = true; - view.callOnClick(); + view.performClick(); return true; } } From ddfb6e437e94b9bbf60c8dd0a049b5113e0e8fed Mon Sep 17 00:00:00 2001 From: troy379 Date: Wed, 3 May 2017 16:43:45 +0300 Subject: [PATCH 07/96] #23 fixed --- .../chatkit/messages/MessageInput.java | 32 +++++++++++++++---- .../main/res/drawable/shape_custom_cursor.xml | 8 +++++ .../res/layout/activity_styled_messages.xml | 1 + 3 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 sample/src/main/res/drawable/shape_custom_cursor.xml 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 1d7d58b4..310fafad 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInput.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInput.java @@ -18,6 +18,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 android.text.Editable; import android.text.TextWatcher; @@ -157,22 +159,22 @@ private void init(Context context, AttributeSet attrs) { this.messageInput.setTextSize(TypedValue.COMPLEX_UNIT_PX, style.getInputTextSize()); this.messageInput.setTextColor(style.getInputTextColor()); this.messageInput.setHintTextColor(style.getInputHintColor()); - this.messageInput.setBackground(style.getInputBackground()); + ViewCompat.setBackground(this.messageInput, style.getInputBackground()); setCursor(style.getInputCursorDrawable()); this.attachmentButton.setVisibility(style.showAttachmentButton() ? VISIBLE : GONE); - this.attachmentButton.setBackground(style.getAttachmentButtonBackground()); this.attachmentButton.setImageDrawable(style.getAttachmentButtonIcon()); this.attachmentButton.getLayoutParams().width = style.getAttachmentButtonWidth(); this.attachmentButton.getLayoutParams().height = style.getAttachmentButtonHeight(); + ViewCompat.setBackground(this.attachmentButton, style.getAttachmentButtonBackground()); this.attachmentButtonSpace.setVisibility(style.showAttachmentButton() ? VISIBLE : GONE); this.attachmentButtonSpace.getLayoutParams().width = style.getAttachmentButtonMargin(); - this.messageSendButton.setBackground(style.getInputButtonBackground()); this.messageSendButton.setImageDrawable(style.getInputButtonIcon()); this.messageSendButton.getLayoutParams().width = style.getInputButtonWidth(); this.messageSendButton.getLayoutParams().height = style.getInputButtonHeight(); + ViewCompat.setBackground(messageSendButton, style.getInputButtonBackground()); this.sendButtonSpace.getLayoutParams().width = style.getInputButtonMargin(); if (getPaddingLeft() == 0 @@ -204,11 +206,27 @@ private void init(Context context) { } private void setCursor(Drawable drawable) { + if (drawable == null) return; + try { - Field f = TextView.class.getDeclaredField("mCursorDrawableRes"); - f.setAccessible(true); - f.set(this.messageInput, drawable); - } catch (Exception ignore) { + final Field drawableResField = TextView.class.getDeclaredField("mCursorDrawableRes"); + drawableResField.setAccessible(true); + + final Object drawableFieldOwner; + final Class drawableFieldClass; + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { + drawableFieldOwner = this.messageInput; + drawableFieldClass = TextView.class; + } else { + final Field editorField = TextView.class.getDeclaredField("mEditor"); + editorField.setAccessible(true); + drawableFieldOwner = editorField.get(this.messageInput); + drawableFieldClass = drawableFieldOwner.getClass(); + } + final Field drawableField = drawableFieldClass.getDeclaredField("mCursorDrawable"); + drawableField.setAccessible(true); + drawableField.set(drawableFieldOwner, new Drawable[]{drawable, drawable}); + } catch (Exception ignored) { } } diff --git a/sample/src/main/res/drawable/shape_custom_cursor.xml b/sample/src/main/res/drawable/shape_custom_cursor.xml new file mode 100644 index 00000000..c60888f9 --- /dev/null +++ b/sample/src/main/res/drawable/shape_custom_cursor.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_styled_messages.xml b/sample/src/main/res/layout/activity_styled_messages.xml index 57d47dd8..62e217d3 100644 --- a/sample/src/main/res/layout/activity_styled_messages.xml +++ b/sample/src/main/res/layout/activity_styled_messages.xml @@ -46,6 +46,7 @@ app:attachmentButtonDefaultIconPressedColor="@color/green_dark" app:inputButtonDefaultBgColor="@color/green" app:inputButtonDefaultBgPressedColor="@color/green_dark" + app:inputCursorDrawable="@drawable/shape_custom_cursor" app:inputHint="@string/hint_enter_a_message" app:showAttachmentButton="true"/> From 3850704181266c0522e0e597a91815d998c3832a Mon Sep 17 00:00:00 2001 From: troy379 Date: Wed, 3 May 2017 16:44:23 +0300 Subject: [PATCH 08/96] set background for lower sdk --- .../com/stfalcon/chatkit/messages/MessageHolders.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 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 bd9daed8..bfe459ac 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java @@ -2,6 +2,7 @@ import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; +import android.support.v4.view.ViewCompat; import android.text.Spannable; import android.text.method.LinkMovementMethod; import android.util.TypedValue; @@ -521,7 +522,7 @@ public void applyStyle(MessagesListStyle style) { style.getIncomingDefaultBubblePaddingTop(), style.getIncomingDefaultBubblePaddingRight(), style.getIncomingDefaultBubblePaddingBottom()); - bubble.setBackground(style.getIncomingBubbleDrawable()); + ViewCompat.setBackground(bubble, style.getIncomingBubbleDrawable()); } if (text != null) { @@ -570,7 +571,7 @@ public final void applyStyle(MessagesListStyle style) { style.getOutcomingDefaultBubblePaddingTop(), style.getOutcomingDefaultBubblePaddingRight(), style.getOutcomingDefaultBubblePaddingBottom()); - bubble.setBackground(style.getOutcomingBubbleDrawable()); + ViewCompat.setBackground(bubble, style.getOutcomingBubbleDrawable()); } if (text != null) { @@ -630,7 +631,7 @@ public final void applyStyle(MessagesListStyle style) { } if (imageOverlay != null) { - imageOverlay.setBackground(style.getIncomingImageOverlayDrawable()); + ViewCompat.setBackground(imageOverlay, style.getIncomingImageOverlayDrawable()); } } } @@ -681,7 +682,7 @@ public final void applyStyle(MessagesListStyle style) { } if (imageOverlay != null) { - imageOverlay.setBackground(style.getOutcomingImageOverlayDrawable()); + ViewCompat.setBackground(imageOverlay, style.getOutcomingImageOverlayDrawable()); } } } From 866429055e9898d9b8ec04133cbccfc66c08f15e Mon Sep 17 00:00:00 2001 From: troy379 Date: Wed, 3 May 2017 17:17:07 +0300 Subject: [PATCH 09/96] gradle update --- chatkit/build.gradle | 11 ++++++++--- sample/build.gradle | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/chatkit/build.gradle b/chatkit/build.gradle index aa4d2962..1e84dc76 100644 --- a/chatkit/build.gradle +++ b/chatkit/build.gradle @@ -30,10 +30,15 @@ publish { website = 'https://github.com/stfalcon-studio/ChatKit.git' } +ext { + supportVersion = '25.3.1' + flexboxVersion = '0.2.5' +} + dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:25.1.1' - compile 'com.android.support:design:25.1.1' - compile 'com.google.android:flexbox:0.2.5' + compile "com.android.support:appcompat-v7:$supportVersion" + compile "com.android.support:design:$supportVersion" + compile "com.google.android:flexbox:$flexboxVersion" } diff --git a/sample/build.gradle b/sample/build.gradle index d000b209..13d52cae 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -5,7 +5,7 @@ android { buildToolsVersion "25.0.2" defaultConfig { applicationId "com.stfalcon.chatkit.sample" - minSdkVersion 16 + minSdkVersion 14 targetSdkVersion 25 versionCode 1 versionName "1.0" @@ -25,7 +25,7 @@ android { } ext { - supportVersion = '25.1.1' + supportVersion = '25.3.1' picassoVersion = '2.5.2' circleImageViewVersion = '2.1.0' shapeImageViewVersion = '0.9.3' From 4c20300e70421eaf94fc50aa87cd2c66a7f03063 Mon Sep 17 00:00:00 2001 From: troy379 Date: Wed, 3 May 2017 17:21:46 +0300 Subject: [PATCH 10/96] 0.2.1 release --- chatkit/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chatkit/build.gradle b/chatkit/build.gradle index 1e84dc76..a7b3e3f7 100644 --- a/chatkit/build.gradle +++ b/chatkit/build.gradle @@ -9,7 +9,7 @@ android { minSdkVersion 14 targetSdkVersion 25 versionCode 1 - versionName "0.2.0" + versionName "0.2.1" consumerProguardFiles 'proguard.txt' } @@ -23,7 +23,7 @@ android { publish { groupId = 'com.github.stfalcon' artifactId = 'chatkit' - publishVersion = '0.2.0' + publishVersion = '0.2.1' 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' From c2a471de81ca06ef8faf76fff4e2efb656465bd8 Mon Sep 17 00:00:00 2001 From: Alexander Krol Date: Wed, 3 May 2017 18:13:48 +0300 Subject: [PATCH 11/96] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8260eae7..4cd90e41 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ To implement all of the features above you can use the following components: Download via Gradle: ```gradle -compile 'com.github.stfalcon:chatkit:0.2.0' +compile 'com.github.stfalcon:chatkit:0.2.1' ``` or Maven: @@ -51,7 +51,7 @@ or Maven: com.github.stfalcon chatkit - 0.2.0 + 0.2.1 pom ``` From b75ae624d53457d3fa88fb1b46fef4600735a38f Mon Sep 17 00:00:00 2001 From: Nagarjuna Yelisetty Date: Tue, 9 May 2017 12:05:00 +0530 Subject: [PATCH 12/96] Update COMPONENT_DIALOGS_LIST.MD Just small change here `* adapter.addItem(DIALOG dialog) - adds one dialog to the end of the list * adapter.addItem(int position, DIALOG dialog) - adds a new dialog to the specified position.` --- docs/COMPONENT_DIALOGS_LIST.MD | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/COMPONENT_DIALOGS_LIST.MD b/docs/COMPONENT_DIALOGS_LIST.MD index 9b4f72ce..673457b2 100644 --- a/docs/COMPONENT_DIALOGS_LIST.MD +++ b/docs/COMPONENT_DIALOGS_LIST.MD @@ -113,8 +113,8 @@ When your models are ready to be used by adapter, you can simply add them to the * adapter.setItems(List items) - replaces existing list with a new dialog list; * adapter.addItems(List items) - adds a new dialog list to the end of the list; -* adapter.addItem(DIALOG dialog) - adds a new dialog to the specified position; -* adapter.addItem(int position, DIALOG dialog) - adds one dialog to the end of the list. +* adapter.addItem(DIALOG dialog) - adds one dialog to the end of the list +* adapter.addItem(int position, DIALOG dialog) - adds a new dialog to the specified position. #### Updating dialogs If dialog has changed, you can update it by position in list by calling `adapter.updateItem(int position, DIALOG item)` or update it by dialog id by calling `adapter.updateItemById(DIALOG item)` From 43d816d9c96d57a5b4e4cc0a9dbcc2f4078333ca Mon Sep 17 00:00:00 2001 From: Toan Pv Date: Fri, 19 May 2017 22:35:08 +0700 Subject: [PATCH 13/96] Add TypingListener to MessageInput Add sample --- .../chatkit/messages/MessageInput.java | 56 ++++++++++++++++++- .../demo/def/DefaultMessagesActivity.java | 15 ++++- sample/src/main/res/values/strings.xml | 3 + 3 files changed, 72 insertions(+), 2 deletions(-) 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 1d7d58b4..269cded7 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInput.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInput.java @@ -37,7 +37,7 @@ * Component for input outcoming messages */ public class MessageInput extends RelativeLayout - implements View.OnClickListener, TextWatcher { + implements View.OnClickListener, TextWatcher, View.OnFocusChangeListener { protected EditText messageInput; protected ImageButton messageSendButton; @@ -47,6 +47,18 @@ public class MessageInput extends RelativeLayout private CharSequence input; private InputListener inputListener; private AttachmentsListener attachmentsListener; + private boolean isTyping; + private TypingListener typingListener; + private Runnable typingTimerRunnable = new Runnable() { + @Override + public void run() { + if (isTyping) { + isTyping = false; + if (typingListener != null) typingListener.onStopTyping(); + } + } + }; + private boolean lastFocus; public MessageInput(Context context) { super(context); @@ -107,6 +119,8 @@ public void onClick(View view) { if (isSubmitted) { messageInput.setText(""); } + removeCallbacks(typingTimerRunnable); + post(typingTimerRunnable); } else if (id == R.id.attachmentButton) { onAddAttachments(); } @@ -120,6 +134,16 @@ public void onClick(View view) { public void onTextChanged(CharSequence s, int start, int count, int after) { input = s; messageSendButton.setEnabled(input.length() > 0); + if (s.length() > 0) { + + if (!isTyping) { + isTyping = true; + if (typingListener != null) typingListener.onStartTyping(); + } + + removeCallbacks(typingTimerRunnable); + postDelayed(typingTimerRunnable, 1500); + } } /** @@ -139,6 +163,14 @@ public void afterTextChanged(Editable editable) { } + @Override + public void onFocusChange(View v, boolean hasFocus) { + if (lastFocus && !hasFocus && typingListener != null) { + typingListener.onStopTyping(); + } + lastFocus = hasFocus; + } + private boolean onSubmit() { return inputListener != null && inputListener.onSubmit(input); } @@ -201,6 +233,7 @@ private void init(Context context) { attachmentButton.setOnClickListener(this); messageInput.addTextChangedListener(this); messageInput.setText(""); + messageInput.setOnFocusChangeListener(this); } private void setCursor(Drawable drawable) { @@ -212,6 +245,10 @@ private void setCursor(Drawable drawable) { } } + public void setTypingListener(TypingListener typingListener) { + this.typingListener = typingListener; + } + /** * Interface definition for a callback to be invoked when user pressed 'submit' button */ @@ -236,4 +273,21 @@ public interface AttachmentsListener { */ void onAddAttachments(); } + + /** + * Interface definition for a callback to be invoked when user typing + */ + public interface TypingListener { + + /** + * Fires when user presses start typing + */ + void onStartTyping(); + + /** + * Fires when user presses stop typing + */ + void onStopTyping(); + + } } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java index 0dcb32f7..6ab641b8 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java @@ -3,6 +3,7 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.widget.Toast; import com.stfalcon.chatkit.messages.MessageInput; import com.stfalcon.chatkit.messages.MessagesList; @@ -13,7 +14,8 @@ public class DefaultMessagesActivity extends DemoMessagesActivity implements MessageInput.InputListener, - MessageInput.AttachmentsListener { + MessageInput.AttachmentsListener, + MessageInput.TypingListener { public static void open(Context context) { context.startActivity(new Intent(context, DefaultMessagesActivity.class)); @@ -31,6 +33,7 @@ protected void onCreate(Bundle savedInstanceState) { MessageInput input = (MessageInput) findViewById(R.id.input); input.setInputListener(this); + input.setTypingListener(this); } @Override @@ -52,4 +55,14 @@ private void initAdapter() { super.messagesAdapter.setLoadMoreListener(this); this.messagesList.setAdapter(super.messagesAdapter); } + + @Override + public void onStartTyping() { + Toast.makeText(this, R.string.start_typing_status, Toast.LENGTH_SHORT).show(); + } + + @Override + public void onStopTyping() { + Toast.makeText(this, R.string.stop_typing_status, Toast.LENGTH_SHORT).show(); + } } diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index 060953e4..f731bbcb 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -29,4 +29,7 @@ Voice message (custom) + Start typing + Stop typing + From f1f9e6d56e40e7188389bf67031ddb8232ecbe20 Mon Sep 17 00:00:00 2001 From: Toan Pv Date: Fri, 19 May 2017 22:37:21 +0700 Subject: [PATCH 14/96] Remove spaces --- .../main/java/com/stfalcon/chatkit/messages/MessageInput.java | 2 -- 1 file changed, 2 deletions(-) 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 269cded7..5bd3d5a0 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInput.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInput.java @@ -135,12 +135,10 @@ public void onTextChanged(CharSequence s, int start, int count, int after) { input = s; messageSendButton.setEnabled(input.length() > 0); if (s.length() > 0) { - if (!isTyping) { isTyping = true; if (typingListener != null) typingListener.onStartTyping(); } - removeCallbacks(typingTimerRunnable); postDelayed(typingTimerRunnable, 1500); } From 9be17d7a23ce13d418d87940e963e4b2f65f0a12 Mon Sep 17 00:00:00 2001 From: Toan Pv Date: Fri, 19 May 2017 23:27:33 +0700 Subject: [PATCH 15/96] Add delay typing to attr Add TypingListener to docs --- .../chatkit/messages/MessageInput.java | 4 +++- .../chatkit/messages/MessageInputStyle.java | 9 +++++++++ chatkit/src/main/res/values/attrs.xml | 2 ++ docs/COMPONENT_MESSAGE_INPUT.MD | 18 ++++++++++++++++++ docs/STYLES_ATTR.md | 3 ++- 5 files changed, 34 insertions(+), 2 deletions(-) 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 5bd3d5a0..db15a715 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInput.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInput.java @@ -49,6 +49,7 @@ public class MessageInput extends RelativeLayout private AttachmentsListener attachmentsListener; private boolean isTyping; private TypingListener typingListener; + private int delayTypingStatusMillis; private Runnable typingTimerRunnable = new Runnable() { @Override public void run() { @@ -140,7 +141,7 @@ public void onTextChanged(CharSequence s, int start, int count, int after) { if (typingListener != null) typingListener.onStartTyping(); } removeCallbacks(typingTimerRunnable); - postDelayed(typingTimerRunnable, 1500); + postDelayed(typingTimerRunnable, delayTypingStatusMillis); } } @@ -216,6 +217,7 @@ && getPaddingBottom() == 0) { style.getInputDefaultPaddingBottom() ); } + this.delayTypingStatusMillis = style.getDelayTypingStatus(); } private void init(Context context) { 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 0c6d3248..1453a2f9 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInputStyle.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInputStyle.java @@ -34,6 +34,7 @@ class MessageInputStyle extends Style { private static final int DEFAULT_MAX_LINES = 5; + private static final int DEFAULT_DELAY_TYPING_STATUS = 1500; private boolean showAttachmentButton; @@ -81,6 +82,8 @@ class MessageInputStyle extends Style { private int inputDefaultPaddingTop; private int inputDefaultPaddingBottom; + private int delayTypingStatus; + static MessageInputStyle parse(Context context, AttributeSet attrs) { MessageInputStyle style = new MessageInputStyle(context, attrs); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MessageInput); @@ -138,6 +141,8 @@ static MessageInputStyle parse(Context context, AttributeSet attrs) { style.inputBackground = typedArray.getDrawable(R.styleable.MessageInput_inputBackground); style.inputCursorDrawable = typedArray.getDrawable(R.styleable.MessageInput_inputCursorDrawable); + style.delayTypingStatus = typedArray.getInt(R.styleable.MessageInput_delayTypingStatus, DEFAULT_DELAY_TYPING_STATUS); + typedArray.recycle(); style.inputDefaultPaddingLeft = style.getDimension(R.dimen.input_padding_left); @@ -281,4 +286,8 @@ int getInputDefaultPaddingBottom() { return inputDefaultPaddingBottom; } + int getDelayTypingStatus() { + return delayTypingStatus; + } + } diff --git a/chatkit/src/main/res/values/attrs.xml b/chatkit/src/main/res/values/attrs.xml index dca85be2..1cd0a317 100644 --- a/chatkit/src/main/res/values/attrs.xml +++ b/chatkit/src/main/res/values/attrs.xml @@ -42,6 +42,8 @@ + + diff --git a/docs/COMPONENT_MESSAGE_INPUT.MD b/docs/COMPONENT_MESSAGE_INPUT.MD index 6c49542e..72165205 100644 --- a/docs/COMPONENT_MESSAGE_INPUT.MD +++ b/docs/COMPONENT_MESSAGE_INPUT.MD @@ -47,6 +47,24 @@ messageInput.setAttachmentsListener(new MessageInput.AttachmentsListener() { }); ``` +#### Typing Listener + +If you want to track typing event: +```java +messageInput.setTypingListener(new MessageInput.TypingListener() { + @Override + public void onStartTyping() { + + } + + @Override + public void onStopTyping() { + + } + }); +``` +Default delay typing is 1500, you can change it with only one line `delayTypingStatus="delayInMilis"` + #### Make it look the way you want By using available widget attribute you can change color and size of text and input hint, maximum number of permitted lines, size and indents “submit” button, and its icon and background. diff --git a/docs/STYLES_ATTR.md b/docs/STYLES_ATTR.md index df2075e4..8d2f5856 100644 --- a/docs/STYLES_ATTR.md +++ b/docs/STYLES_ATTR.md @@ -126,4 +126,5 @@ | `inputTextColor` | Sets input message text color| | `inputHintColor` | Sets text color of hint in message input field| | `inputBackground` | Sets background for input message view | -| `inputCursorDrawable` | Sets cursor drawable for input message EditText | \ No newline at end of file +| `inputCursorDrawable` | Sets cursor drawable for input message EditText | +| `delayTypingStatus` | Sets delay typing for TypingListener| \ No newline at end of file From 423f15c4ab223116915dc6d8f378c39f8a504ef6 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 29 Jun 2017 15:55:49 +0300 Subject: [PATCH 16/96] DialogList: fixed changing text style to normal --- .../chatkit/dialogs/DialogsListAdapter.java | 13 +++++++------ .../chatkit/sample/common/data/model/Dialog.java | 4 ++++ .../features/demo/styled/StyledDialogsActivity.java | 8 +++++++- .../src/main/res/layout/activity_styled_dialogs.xml | 1 - 4 files changed, 18 insertions(+), 8 deletions(-) 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 444ef76a..ad895480 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -16,6 +16,7 @@ package com.stfalcon.chatkit.dialogs; +import android.graphics.Typeface; import android.graphics.drawable.GradientDrawable; import android.support.annotation.LayoutRes; import android.support.v7.widget.RecyclerView; @@ -530,17 +531,17 @@ private void applyDefaultStyle() { if (tvName != null) { tvName.setTextColor(dialogStyle.getDialogTitleTextColor()); - tvName.setTypeface(tvName.getTypeface(), dialogStyle.getDialogTitleTextStyle()); + tvName.setTypeface(Typeface.DEFAULT, dialogStyle.getDialogTitleTextStyle()); } if (tvDate != null) { tvDate.setTextColor(dialogStyle.getDialogDateColor()); - tvDate.setTypeface(tvDate.getTypeface(), dialogStyle.getDialogDateStyle()); + tvDate.setTypeface(Typeface.DEFAULT, dialogStyle.getDialogDateStyle()); } if (tvLastMessage != null) { tvLastMessage.setTextColor(dialogStyle.getDialogMessageTextColor()); - tvLastMessage.setTypeface(tvLastMessage.getTypeface(), dialogStyle.getDialogMessageTextStyle()); + tvLastMessage.setTypeface(Typeface.DEFAULT, dialogStyle.getDialogMessageTextStyle()); } } } @@ -553,17 +554,17 @@ private void applyUnreadStyle() { if (tvName != null) { tvName.setTextColor(dialogStyle.getDialogUnreadTitleTextColor()); - tvName.setTypeface(tvName.getTypeface(), dialogStyle.getDialogUnreadTitleTextStyle()); + tvName.setTypeface(Typeface.DEFAULT, dialogStyle.getDialogUnreadTitleTextStyle()); } if (tvDate != null) { tvDate.setTextColor(dialogStyle.getDialogUnreadDateColor()); - tvDate.setTypeface(tvDate.getTypeface(), dialogStyle.getDialogUnreadDateStyle()); + tvDate.setTypeface(Typeface.DEFAULT, dialogStyle.getDialogUnreadDateStyle()); } if (tvLastMessage != null) { tvLastMessage.setTextColor(dialogStyle.getDialogUnreadMessageTextColor()); - tvLastMessage.setTypeface(tvLastMessage.getTypeface(), dialogStyle.getDialogUnreadMessageTextStyle()); + tvLastMessage.setTypeface(Typeface.DEFAULT, dialogStyle.getDialogUnreadMessageTextStyle()); } } } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/common/data/model/Dialog.java b/sample/src/main/java/com/stfalcon/chatkit/sample/common/data/model/Dialog.java index 36584756..7f239df6 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/common/data/model/Dialog.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/common/data/model/Dialog.java @@ -62,4 +62,8 @@ public void setLastMessage(Message lastMessage) { public int getUnreadCount() { return unreadCount; } + + public void setUnreadCount(int unreadCount) { + this.unreadCount = unreadCount; + } } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/styled/StyledDialogsActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/styled/StyledDialogsActivity.java index 1d8d2865..9c9e1bf6 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/styled/StyledDialogsActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/styled/StyledDialogsActivity.java @@ -54,7 +54,13 @@ private void initAdapter() { super.dialogsAdapter = new DialogsListAdapter<>(super.imageLoader); super.dialogsAdapter.setItems(DialogsFixtures.getDialogs()); - super.dialogsAdapter.setOnDialogClickListener(this); + super.dialogsAdapter.setOnDialogClickListener(new DialogsListAdapter.OnDialogClickListener() { + @Override + public void onDialogClick(Dialog dialog) { + dialog.setUnreadCount(0); + dialogsAdapter.updateItemById(dialog); + } + }); super.dialogsAdapter.setOnDialogLongClickListener(this); super.dialogsAdapter.setDatesFormatter(this); diff --git a/sample/src/main/res/layout/activity_styled_dialogs.xml b/sample/src/main/res/layout/activity_styled_dialogs.xml index 81eb8ecd..50ce217a 100644 --- a/sample/src/main/res/layout/activity_styled_dialogs.xml +++ b/sample/src/main/res/layout/activity_styled_dialogs.xml @@ -11,7 +11,6 @@ android:layout_height="match_parent" app:dialogDividerLeftPadding="0dp" app:dialogMessageTextSize="17sp" - app:dialogTitleTextStyle="bold" app:dialogUnreadBubbleBackgroundColor="@color/red" app:dialogUnreadItemBackground="@color/gray_transparent" app:dialogUnreadTitleTextStyle="bold"/> From 1da8fe6e54e8b0f6c002c37d1c6d5d888aeb1e21 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 29 Jun 2017 17:10:19 +0300 Subject: [PATCH 17/96] MessageList new feature: registering click listener for view by id --- chatkit/build.gradle | 4 ++-- .../chatkit/messages/MessageHolders.java | 24 +++++++++++++++---- .../chatkit/messages/MessagesListAdapter.java | 14 ++++++++++- .../demo/def/DefaultMessagesActivity.java | 12 ++++++++++ 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/chatkit/build.gradle b/chatkit/build.gradle index a7b3e3f7..54b43859 100644 --- a/chatkit/build.gradle +++ b/chatkit/build.gradle @@ -9,7 +9,7 @@ android { minSdkVersion 14 targetSdkVersion 25 versionCode 1 - versionName "0.2.1" + versionName "0.2.2" consumerProguardFiles 'proguard.txt' } @@ -23,7 +23,7 @@ android { publish { groupId = 'com.github.stfalcon' artifactId = 'chatkit' - publishVersion = '0.2.1' + publishVersion = '0.2.2' 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' 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 bfe459ac..f24fb444 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java @@ -5,6 +5,7 @@ import android.support.v4.view.ViewCompat; import android.text.Spannable; import android.text.method.LinkMovementMethod; +import android.util.SparseArray; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -346,16 +347,31 @@ ViewHolder getHolder(ViewGroup parent, int viewType, MessagesListStyle messagesL } @SuppressWarnings("unchecked") - void bind(ViewHolder holder, Object item, boolean isSelected, ImageLoader imageLoader, - View.OnClickListener onMessageClickListener, - View.OnLongClickListener onMessageLongClickListener, - DateFormatter.Formatter dateHeadersFormatter) { + void bind(final ViewHolder holder, final Object item, boolean isSelected, + final ImageLoader imageLoader, + final View.OnClickListener onMessageClickListener, + final View.OnLongClickListener onMessageLongClickListener, + final DateFormatter.Formatter dateHeadersFormatter, + final SparseArray clickListenersArray) { if (item instanceof IMessage) { ((MessageHolders.BaseMessageViewHolder) holder).isSelected = isSelected; ((MessageHolders.BaseMessageViewHolder) holder).imageLoader = imageLoader; holder.itemView.setOnLongClickListener(onMessageLongClickListener); holder.itemView.setOnClickListener(onMessageClickListener); + + for (int i = 0; i < clickListenersArray.size(); i++) { + final int key = clickListenersArray.keyAt(i); + final View view = holder.itemView.findViewById(key); + if (view != null) { + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + clickListenersArray.get(key).onMessageViewClick(view, (IMessage) item); + } + }); + } + } } else if (item instanceof Date) { ((MessageHolders.DefaultDateHeaderViewHolder) holder).dateHeadersFormatter = dateHeadersFormatter; } 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 aedcf4eb..4e1ec338 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -23,6 +23,7 @@ import android.support.v7.widget.RecyclerView; import android.text.Spannable; import android.text.method.LinkMovementMethod; +import android.util.SparseArray; import android.util.TypedValue; import android.view.MotionEvent; import android.view.View; @@ -65,6 +66,7 @@ public class MessagesListAdapter private RecyclerView.LayoutManager layoutManager; private MessagesListStyle messagesListStyle; private DateFormatter.Formatter dateHeadersFormatter; + private SparseArray viewClickListenersArray = new SparseArray<>(); /** * For default list item layout and view holder. @@ -103,7 +105,8 @@ public void onBindViewHolder(ViewHolder holder, int position) { holders.bind(holder, wrapper.item, wrapper.isSelected, imageLoader, getMessageClickListener(wrapper), getMessageLongClickListener(wrapper), - dateHeadersFormatter); + dateHeadersFormatter, + viewClickListenersArray); } @Override @@ -369,6 +372,15 @@ public void setOnMessageViewClickListener(OnMessageViewClickListener on this.onMessageViewClickListener = onMessageViewClickListener; } + /** + * Registers click listener for view by id + * @param viewId view + * @param onMessageViewClickListener click listener. + */ + public void registerViewClickListener(int viewId, OnMessageViewClickListener onMessageViewClickListener) { + this.viewClickListenersArray.append(viewId, onMessageViewClickListener); + } + /** * Sets long click listener for item. Fires only if selection mode is disabled. * diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java index 0dcb32f7..f4fd9b36 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java @@ -3,13 +3,16 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.view.View; import com.stfalcon.chatkit.messages.MessageInput; import com.stfalcon.chatkit.messages.MessagesList; import com.stfalcon.chatkit.messages.MessagesListAdapter; import com.stfalcon.chatkit.sample.R; import com.stfalcon.chatkit.sample.common.data.fixtures.MessagesFixtures; +import com.stfalcon.chatkit.sample.common.data.model.Message; import com.stfalcon.chatkit.sample.features.demo.DemoMessagesActivity; +import com.stfalcon.chatkit.sample.utils.AppUtils; public class DefaultMessagesActivity extends DemoMessagesActivity implements MessageInput.InputListener, @@ -50,6 +53,15 @@ private void initAdapter() { super.messagesAdapter = new MessagesListAdapter<>(super.senderId, super.imageLoader); super.messagesAdapter.enableSelectionMode(this); super.messagesAdapter.setLoadMoreListener(this); + super.messagesAdapter.registerViewClickListener(R.id.messageUserAvatar, + new MessagesListAdapter.OnMessageViewClickListener() { + @Override + public void onMessageViewClick(View view, Message message) { + AppUtils.showToast(DefaultMessagesActivity.this, + message.getUser().getName() + " avatar click", + false); + } + }); this.messagesList.setAdapter(super.messagesAdapter); } } From 0da3d74f2500853bd7b46c2ed87018444a04a4e2 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 29 Jun 2017 17:15:38 +0300 Subject: [PATCH 18/96] removed some unnecessary sample code --- .../features/demo/styled/StyledDialogsActivity.java | 8 +------- sample/src/main/res/layout/activity_styled_dialogs.xml | 1 + 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/styled/StyledDialogsActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/styled/StyledDialogsActivity.java index 9c9e1bf6..1d8d2865 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/styled/StyledDialogsActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/styled/StyledDialogsActivity.java @@ -54,13 +54,7 @@ private void initAdapter() { super.dialogsAdapter = new DialogsListAdapter<>(super.imageLoader); super.dialogsAdapter.setItems(DialogsFixtures.getDialogs()); - super.dialogsAdapter.setOnDialogClickListener(new DialogsListAdapter.OnDialogClickListener() { - @Override - public void onDialogClick(Dialog dialog) { - dialog.setUnreadCount(0); - dialogsAdapter.updateItemById(dialog); - } - }); + super.dialogsAdapter.setOnDialogClickListener(this); super.dialogsAdapter.setOnDialogLongClickListener(this); super.dialogsAdapter.setDatesFormatter(this); diff --git a/sample/src/main/res/layout/activity_styled_dialogs.xml b/sample/src/main/res/layout/activity_styled_dialogs.xml index 50ce217a..81eb8ecd 100644 --- a/sample/src/main/res/layout/activity_styled_dialogs.xml +++ b/sample/src/main/res/layout/activity_styled_dialogs.xml @@ -11,6 +11,7 @@ android:layout_height="match_parent" app:dialogDividerLeftPadding="0dp" app:dialogMessageTextSize="17sp" + app:dialogTitleTextStyle="bold" app:dialogUnreadBubbleBackgroundColor="@color/red" app:dialogUnreadItemBackground="@color/gray_transparent" app:dialogUnreadTitleTextStyle="bold"/> From e1f6ef83db9d1640fa60a7609fe44aa9020c9c1e Mon Sep 17 00:00:00 2001 From: Anton Bevza Date: Thu, 29 Jun 2017 17:23:07 +0300 Subject: [PATCH 19/96] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4cd90e41..66fc6909 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ To implement all of the features above you can use the following components: Download via Gradle: ```gradle -compile 'com.github.stfalcon:chatkit:0.2.1' +compile 'com.github.stfalcon:chatkit:0.2.2' ``` or Maven: @@ -51,7 +51,7 @@ or Maven: com.github.stfalcon chatkit - 0.2.1 + 0.2.2 pom ``` From 0987b4d676a0f7ea6742abe67ec4439eef36a2e2 Mon Sep 17 00:00:00 2001 From: Anton Bevza Date: Thu, 29 Jun 2017 17:43:12 +0300 Subject: [PATCH 20/96] Update COMPONENT_MESSAGES_LIST.md --- docs/COMPONENT_MESSAGES_LIST.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/COMPONENT_MESSAGES_LIST.md b/docs/COMPONENT_MESSAGES_LIST.md index 707a9d5e..38a4453e 100644 --- a/docs/COMPONENT_MESSAGES_LIST.md +++ b/docs/COMPONENT_MESSAGES_LIST.md @@ -147,7 +147,7 @@ If message has changed, you can update it by calling `adapter.update(IMessage me #### Click listeners -Of course, the adapter have listeners for such important actions as short and long clicks. They just returns a message object that has been pressed, with a type that is specified as the generic type of adapter: +Of course, the adapter has listeners for such important actions as short and long clicks. They just returns a message object that has been pressed, with a type that is specified as the generic type of adapter: ```java public interface OnMessageClickListener { @@ -157,6 +157,12 @@ public interface OnMessageLongClickListener { void onMessageLongClick(MESSAGE message); } ``` + +Also here is an ability to set listeners on separate Views in message item: +``` +public void registerViewClickListener(int viewId, OnMessageViewClickListener onMessageViewClickListener) +``` + #### Links highlighting In 99% of cases the user is confused, when he can not follow the link or call the phone, indicated in the message. If you think the same way, just include `textAutoLink="all"`, like in the ordinary `TextView`. Similarly, you can specify highlighting for certain types, for example, `email|phone|web`:

@@ -369,4 +375,4 @@ If the `hasContentFor` method returns `true` for the selected type, the correspo As the result, well get the following:

-

\ No newline at end of file +

From 4bdd9842aebaf87c16dfbee759108ccc70b33700 Mon Sep 17 00:00:00 2001 From: Alexander Krol Date: Wed, 19 Jul 2017 11:38:00 +0300 Subject: [PATCH 21/96] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 66fc6909..bb59cb6d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -[ ![Download](https://api.bintray.com/packages/troy379/maven/ChatKit/images/download.svg) ](https://bintray.com/troy379/maven/ChatKit/_latestVersion) - # ChatKit for Android +[ ![Download](https://api.bintray.com/packages/troy379/maven/ChatKit/images/download.svg) ](https://bintray.com/troy379/maven/ChatKit/_latestVersion) + ChatKit is a library designed to simplify the development of UI for such a trivial task as chat. It has flexible possibilities for styling, customizing and data management

From 14c84e74a9999e310b915e270d05e0618f090ea2 Mon Sep 17 00:00:00 2001 From: troy379 Date: Thu, 20 Jul 2017 17:45:55 +0300 Subject: [PATCH 22/96] tiny refactoring --- .../commons/models/MessageContentType.java | 16 + .../chatkit/dialogs/DialogListStyle.java | 294 ++++++------------ .../chatkit/dialogs/DialogsListAdapter.java | 9 +- .../chatkit/messages/MessageHolders.java | 25 +- .../chatkit/messages/MessageInput.java | 5 +- .../chatkit/messages/MessageInputStyle.java | 47 +-- .../chatkit/messages/MessagesListAdapter.java | 10 +- .../chatkit/messages/MessagesListStyle.java | 81 ++--- .../chatkit/utils/RoundedImageView.java | 13 +- 9 files changed, 202 insertions(+), 298 deletions(-) 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 943623c1..f5b63995 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 @@ -1,3 +1,19 @@ +/******************************************************************************* + * Copyright 2016 stfalcon.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ + package com.stfalcon.chatkit.commons.models; import com.stfalcon.chatkit.messages.MessageHolders; diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogListStyle.java b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogListStyle.java index 539d3227..b8ea3eca 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogListStyle.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogListStyle.java @@ -27,7 +27,7 @@ /** * Style for DialogList customization by xml attributes */ - +@SuppressWarnings("WeakerAccess") class DialogListStyle extends Style { private int dialogTitleTextColor; @@ -75,75 +75,79 @@ static DialogListStyle parse(Context context, AttributeSet attrs) { TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DialogsList); //Item background - style.setDialogItemBackground(typedArray.getColor(R.styleable.DialogsList_dialogItemBackground, - style.getColor(R.color.transparent))); - style.setDialogUnreadItemBackground(typedArray.getColor(R.styleable.DialogsList_dialogUnreadItemBackground, - style.getColor(R.color.transparent))); + style.dialogItemBackground = typedArray.getColor(R.styleable.DialogsList_dialogItemBackground, + style.getColor(R.color.transparent)); + style.dialogUnreadItemBackground = typedArray.getColor(R.styleable.DialogsList_dialogUnreadItemBackground, + style.getColor(R.color.transparent)); + //Title text - style.setDialogTitleTextColor(typedArray.getColor(R.styleable.DialogsList_dialogTitleTextColor, - style.getColor(R.color.dialog_title_text))); - style.setDialogTitleTextSize(typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogTitleTextSize, - context.getResources().getDimensionPixelSize(R.dimen.dialog_title_text_size))); - style.setDialogTitleTextStyle(typedArray.getInt(R.styleable.DialogsList_dialogTitleTextStyle, Typeface.NORMAL)); + style.dialogTitleTextColor = typedArray.getColor(R.styleable.DialogsList_dialogTitleTextColor, + style.getColor(R.color.dialog_title_text)); + style.dialogTitleTextSize = typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogTitleTextSize, + context.getResources().getDimensionPixelSize(R.dimen.dialog_title_text_size)); + style.dialogTitleTextStyle = typedArray.getInt(R.styleable.DialogsList_dialogTitleTextStyle, Typeface.NORMAL); + //Title unread text - style.setDialogUnreadTitleTextColor(typedArray.getColor(R.styleable.DialogsList_dialogUnreadTitleTextColor, - style.getColor(R.color.dialog_title_text))); - style.setDialogUnreadTitleTextStyle(typedArray.getInt(R.styleable.DialogsList_dialogUnreadTitleTextStyle, Typeface.NORMAL)); + style.dialogUnreadTitleTextColor = typedArray.getColor(R.styleable.DialogsList_dialogUnreadTitleTextColor, + style.getColor(R.color.dialog_title_text)); + style.dialogUnreadTitleTextStyle = typedArray.getInt(R.styleable.DialogsList_dialogUnreadTitleTextStyle, Typeface.NORMAL); //Message text - style.setDialogMessageTextColor(typedArray.getColor(R.styleable.DialogsList_dialogMessageTextColor, - style.getColor(R.color.dialog_message_text))); - style.setDialogMessageTextSize(typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogMessageTextSize, - context.getResources().getDimensionPixelSize(R.dimen.dialog_message_text_size))); - style.setDialogMessageTextStyle(typedArray.getInt(R.styleable.DialogsList_dialogMessageTextStyle, Typeface.NORMAL)); + style.dialogMessageTextColor = typedArray.getColor(R.styleable.DialogsList_dialogMessageTextColor, + style.getColor(R.color.dialog_message_text)); + style.dialogMessageTextSize = typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogMessageTextSize, + context.getResources().getDimensionPixelSize(R.dimen.dialog_message_text_size)); + style.dialogMessageTextStyle = typedArray.getInt(R.styleable.DialogsList_dialogMessageTextStyle, Typeface.NORMAL); + //Message unread text - style.setDialogUnreadMessageTextColor(typedArray.getColor(R.styleable.DialogsList_dialogUnreadMessageTextColor, - style.getColor(R.color.dialog_message_text))); - style.setDialogUnreadMessageTextStyle(typedArray.getInt(R.styleable.DialogsList_dialogUnreadMessageTextStyle, Typeface.NORMAL)); + style.dialogUnreadMessageTextColor = typedArray.getColor(R.styleable.DialogsList_dialogUnreadMessageTextColor, + style.getColor(R.color.dialog_message_text)); + style.dialogUnreadMessageTextStyle = typedArray.getInt(R.styleable.DialogsList_dialogUnreadMessageTextStyle, Typeface.NORMAL); //Date text - style.setDialogDateColor(typedArray.getColor(R.styleable.DialogsList_dialogDateColor, - style.getColor(R.color.dialog_date_text))); - style.setDialogDateSize(typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogDateSize, - context.getResources().getDimensionPixelSize(R.dimen.dialog_date_text_size))); - style.setDialogDateStyle(typedArray.getInt(R.styleable.DialogsList_dialogDateStyle, Typeface.NORMAL)); + style.dialogDateColor = typedArray.getColor(R.styleable.DialogsList_dialogDateColor, + style.getColor(R.color.dialog_date_text)); + style.dialogDateSize = typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogDateSize, + context.getResources().getDimensionPixelSize(R.dimen.dialog_date_text_size)); + style.dialogDateStyle = typedArray.getInt(R.styleable.DialogsList_dialogDateStyle, Typeface.NORMAL); + //Date unread text - style.setDialogUnreadDateColor(typedArray.getColor(R.styleable.DialogsList_dialogUnreadDateColor, - style.getColor(R.color.dialog_date_text))); - style.setDialogUnreadDateStyle(typedArray.getInt(R.styleable.DialogsList_dialogUnreadDateStyle, Typeface.NORMAL)); + style.dialogUnreadDateColor = typedArray.getColor(R.styleable.DialogsList_dialogUnreadDateColor, + style.getColor(R.color.dialog_date_text)); + style.dialogUnreadDateStyle = typedArray.getInt(R.styleable.DialogsList_dialogUnreadDateStyle, Typeface.NORMAL); //Unread bubble - style.setDialogUnreadBubbleEnabled(typedArray.getBoolean(R.styleable.DialogsList_dialogUnreadBubbleEnabled, true)); - style.setDialogUnreadBubbleBackgroundColor(typedArray.getColor(R.styleable.DialogsList_dialogUnreadBubbleBackgroundColor, - style.getColor(R.color.dialog_unread_bubble))); + style.dialogUnreadBubbleEnabled = typedArray.getBoolean(R.styleable.DialogsList_dialogUnreadBubbleEnabled, true); + style.dialogUnreadBubbleBackgroundColor = typedArray.getColor(R.styleable.DialogsList_dialogUnreadBubbleBackgroundColor, + style.getColor(R.color.dialog_unread_bubble)); //Unread bubble text - style.setDialogUnreadBubbleTextColor(typedArray.getColor(R.styleable.DialogsList_dialogUnreadBubbleTextColor, - style.getColor(R.color.dialog_unread_text))); - style.setDialogUnreadBubbleTextSize(typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogUnreadBubbleTextSize, - context.getResources().getDimensionPixelSize(R.dimen.dialog_unread_bubble_text_size))); - style.setDialogUnreadBubbleTextStyle(typedArray.getInt(R.styleable.DialogsList_dialogUnreadBubbleTextStyle, Typeface.NORMAL)); + style.dialogUnreadBubbleTextColor = typedArray.getColor(R.styleable.DialogsList_dialogUnreadBubbleTextColor, + style.getColor(R.color.dialog_unread_text)); + style.dialogUnreadBubbleTextSize = typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogUnreadBubbleTextSize, + context.getResources().getDimensionPixelSize(R.dimen.dialog_unread_bubble_text_size)); + style.dialogUnreadBubbleTextStyle = typedArray.getInt(R.styleable.DialogsList_dialogUnreadBubbleTextStyle, Typeface.NORMAL); //Avatar - style.setDialogAvatarWidth(typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogAvatarWidth, - context.getResources().getDimensionPixelSize(R.dimen.dialog_avatar_width))); - style.setDialogAvatarHeight(typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogAvatarHeight, - context.getResources().getDimensionPixelSize(R.dimen.dialog_avatar_height))); + style.dialogAvatarWidth = typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogAvatarWidth, + context.getResources().getDimensionPixelSize(R.dimen.dialog_avatar_width)); + style.dialogAvatarHeight = typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogAvatarHeight, + context.getResources().getDimensionPixelSize(R.dimen.dialog_avatar_height)); //Last message avatar - style.setDialogMessageAvatarEnabled(typedArray.getBoolean(R.styleable.DialogsList_dialogMessageAvatarEnabled, true)); - style.setDialogMessageAvatarWidth(typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogMessageAvatarWidth, - context.getResources().getDimensionPixelSize(R.dimen.dialog_last_message_avatar_width))); - style.setDialogMessageAvatarHeight(typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogMessageAvatarHeight, - context.getResources().getDimensionPixelSize(R.dimen.dialog_last_message_avatar_height))); + style.dialogMessageAvatarEnabled = typedArray.getBoolean(R.styleable.DialogsList_dialogMessageAvatarEnabled, true); + style.dialogMessageAvatarWidth = typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogMessageAvatarWidth, + context.getResources().getDimensionPixelSize(R.dimen.dialog_last_message_avatar_width)); + style.dialogMessageAvatarHeight = typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogMessageAvatarHeight, + context.getResources().getDimensionPixelSize(R.dimen.dialog_last_message_avatar_height)); //Divider - style.setDialogDividerEnabled(typedArray.getBoolean(R.styleable.DialogsList_dialogDividerEnabled, true)); - style.setDialogDividerColor(typedArray.getColor(R.styleable.DialogsList_dialogDividerColor, style.getColor(R.color.dialog_divider))); - style.setDialogDividerLeftPadding(typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogDividerLeftPadding, - context.getResources().getDimensionPixelSize(R.dimen.dialog_divider_margin_left))); - style.setDialogDividerRightPadding(typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogDividerRightPadding, - context.getResources().getDimensionPixelSize(R.dimen.dialog_divider_margin_right))); + style.dialogDividerEnabled = typedArray.getBoolean(R.styleable.DialogsList_dialogDividerEnabled, true); + style.dialogDividerColor = typedArray.getColor(R.styleable.DialogsList_dialogDividerColor, style.getColor(R.color.dialog_divider)); + style.dialogDividerLeftPadding = typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogDividerLeftPadding, + context.getResources().getDimensionPixelSize(R.dimen.dialog_divider_margin_left)); + style.dialogDividerRightPadding = typedArray.getDimensionPixelSize(R.styleable.DialogsList_dialogDividerRightPadding, + context.getResources().getDimensionPixelSize(R.dimen.dialog_divider_margin_right)); typedArray.recycle(); @@ -154,251 +158,127 @@ private DialogListStyle(Context context, AttributeSet attrs) { super(context, attrs); } - int getDialogTitleTextColor() { + protected int getDialogTitleTextColor() { return dialogTitleTextColor; } - void setDialogTitleTextColor(int dialogTitleTextColor) { - this.dialogTitleTextColor = dialogTitleTextColor; - } - - int getDialogTitleTextSize() { + protected int getDialogTitleTextSize() { return dialogTitleTextSize; } - void setDialogTitleTextSize(int dialogTitleTextSize) { - this.dialogTitleTextSize = dialogTitleTextSize; - } - - int getDialogTitleTextStyle() { + protected int getDialogTitleTextStyle() { return dialogTitleTextStyle; } - void setDialogTitleTextStyle(int dialogTitleTextStyle) { - this.dialogTitleTextStyle = dialogTitleTextStyle; - } - - int getDialogUnreadTitleTextColor() { + protected int getDialogUnreadTitleTextColor() { return dialogUnreadTitleTextColor; } - void setDialogUnreadTitleTextColor(int dialogUnreadTitleTextColor) { - this.dialogUnreadTitleTextColor = dialogUnreadTitleTextColor; - } - - int getDialogUnreadTitleTextStyle() { + protected int getDialogUnreadTitleTextStyle() { return dialogUnreadTitleTextStyle; } - void setDialogUnreadTitleTextStyle(int dialogUnreadTitleTextStyle) { - this.dialogUnreadTitleTextStyle = dialogUnreadTitleTextStyle; - } - - int getDialogMessageTextColor() { + protected int getDialogMessageTextColor() { return dialogMessageTextColor; } - void setDialogMessageTextColor(int dialogMessageTextColor) { - this.dialogMessageTextColor = dialogMessageTextColor; - } - - int getDialogMessageTextSize() { + protected int getDialogMessageTextSize() { return dialogMessageTextSize; } - void setDialogMessageTextSize(int dialogMessageTextSize) { - this.dialogMessageTextSize = dialogMessageTextSize; - } - - int getDialogMessageTextStyle() { + protected int getDialogMessageTextStyle() { return dialogMessageTextStyle; } - void setDialogMessageTextStyle(int dialogMessageTextStyle) { - this.dialogMessageTextStyle = dialogMessageTextStyle; - } - - int getDialogUnreadMessageTextColor() { + protected int getDialogUnreadMessageTextColor() { return dialogUnreadMessageTextColor; } - void setDialogUnreadMessageTextColor(int dialogUnreadMessageTextColor) { - this.dialogUnreadMessageTextColor = dialogUnreadMessageTextColor; - } - - int getDialogUnreadMessageTextStyle() { + protected int getDialogUnreadMessageTextStyle() { return dialogUnreadMessageTextStyle; } - void setDialogUnreadMessageTextStyle(int dialogUnreadMessageTextStyle) { - this.dialogUnreadMessageTextStyle = dialogUnreadMessageTextStyle; - } - - int getDialogDateColor() { + protected int getDialogDateColor() { return dialogDateColor; } - void setDialogDateColor(int dialogDateColor) { - this.dialogDateColor = dialogDateColor; - } - - int getDialogDateSize() { + protected int getDialogDateSize() { return dialogDateSize; } - void setDialogDateSize(int dialogDateSize) { - this.dialogDateSize = dialogDateSize; - } - - int getDialogDateStyle() { + protected int getDialogDateStyle() { return dialogDateStyle; } - void setDialogDateStyle(int dialogDateStyle) { - this.dialogDateStyle = dialogDateStyle; - } - - int getDialogUnreadDateColor() { + protected int getDialogUnreadDateColor() { return dialogUnreadDateColor; } - void setDialogUnreadDateColor(int dialogUnreadDateColor) { - this.dialogUnreadDateColor = dialogUnreadDateColor; - } - - int getDialogUnreadDateStyle() { + protected int getDialogUnreadDateStyle() { return dialogUnreadDateStyle; } - void setDialogUnreadDateStyle(int dialogUnreadDateStyle) { - this.dialogUnreadDateStyle = dialogUnreadDateStyle; - } - - boolean isDialogUnreadBubbleEnabled() { + protected boolean isDialogUnreadBubbleEnabled() { return dialogUnreadBubbleEnabled; } - void setDialogUnreadBubbleEnabled(boolean dialogUnreadBubbleEnabled) { - this.dialogUnreadBubbleEnabled = dialogUnreadBubbleEnabled; - } - - int getDialogUnreadBubbleTextColor() { + protected int getDialogUnreadBubbleTextColor() { return dialogUnreadBubbleTextColor; } - void setDialogUnreadBubbleTextColor(int dialogUnreadBubbleTextColor) { - this.dialogUnreadBubbleTextColor = dialogUnreadBubbleTextColor; - } - - int getDialogUnreadBubbleTextSize() { + protected int getDialogUnreadBubbleTextSize() { return dialogUnreadBubbleTextSize; } - void setDialogUnreadBubbleTextSize(int dialogUnreadBubbleTextSize) { - this.dialogUnreadBubbleTextSize = dialogUnreadBubbleTextSize; - } - - int getDialogUnreadBubbleTextStyle() { + protected int getDialogUnreadBubbleTextStyle() { return dialogUnreadBubbleTextStyle; } - void setDialogUnreadBubbleTextStyle(int dialogUnreadBubbleTextStyle) { - this.dialogUnreadBubbleTextStyle = dialogUnreadBubbleTextStyle; - } - - int getDialogUnreadBubbleBackgroundColor() { + protected int getDialogUnreadBubbleBackgroundColor() { return dialogUnreadBubbleBackgroundColor; } - void setDialogUnreadBubbleBackgroundColor(int dialogUnreadBubbleBackgroundColor) { - this.dialogUnreadBubbleBackgroundColor = dialogUnreadBubbleBackgroundColor; - } - - int getDialogAvatarWidth() { + protected int getDialogAvatarWidth() { return dialogAvatarWidth; } - void setDialogAvatarWidth(int dialogAvatarWidth) { - this.dialogAvatarWidth = dialogAvatarWidth; - } - - int getDialogAvatarHeight() { + protected int getDialogAvatarHeight() { return dialogAvatarHeight; } - void setDialogAvatarHeight(int dialogAvatarHeight) { - this.dialogAvatarHeight = dialogAvatarHeight; - } - - boolean isDialogDividerEnabled() { + protected boolean isDialogDividerEnabled() { return dialogDividerEnabled; } - void setDialogDividerEnabled(boolean dialogDividerEnabled) { - this.dialogDividerEnabled = dialogDividerEnabled; - } - - int getDialogDividerColor() { + protected int getDialogDividerColor() { return dialogDividerColor; } - void setDialogDividerColor(int dialogDividerColor) { - this.dialogDividerColor = dialogDividerColor; - } - - int getDialogDividerLeftPadding() { + protected int getDialogDividerLeftPadding() { return dialogDividerLeftPadding; } - void setDialogDividerLeftPadding(int dialogDividerLeftMargin) { - this.dialogDividerLeftPadding = dialogDividerLeftMargin; - } - - int getDialogDividerRightPadding() { + protected int getDialogDividerRightPadding() { return dialogDividerRightPadding; } - void setDialogDividerRightPadding(int dialogDividerRightMargin) { - this.dialogDividerRightPadding = dialogDividerRightMargin; - } - - int getDialogItemBackground() { + protected int getDialogItemBackground() { return dialogItemBackground; } - void setDialogItemBackground(int dialogItemBackground) { - this.dialogItemBackground = dialogItemBackground; - } - - int getDialogUnreadItemBackground() { + protected int getDialogUnreadItemBackground() { return dialogUnreadItemBackground; } - void setDialogUnreadItemBackground(int dialogUnreadItemBackground) { - this.dialogUnreadItemBackground = dialogUnreadItemBackground; - } - - void setDialogMessageAvatarEnabled(boolean dialogMessageAvatarEnabled) { - this.dialogMessageAvatarEnabled = dialogMessageAvatarEnabled; - } - - boolean isDialogMessageAvatarEnabled() { + protected boolean isDialogMessageAvatarEnabled() { return dialogMessageAvatarEnabled; } - int getDialogMessageAvatarWidth() { + protected int getDialogMessageAvatarWidth() { return dialogMessageAvatarWidth; } - void setDialogMessageAvatarWidth(int dialogMessageAvatarWidth) { - this.dialogMessageAvatarWidth = dialogMessageAvatarWidth; - } - - int getDialogMessageAvatarHeight() { + protected int getDialogMessageAvatarHeight() { return dialogMessageAvatarHeight; } - - void setDialogMessageAvatarHeight(int dialogMessageAvatarHeight) { - this.dialogMessageAvatarHeight = dialogMessageAvatarHeight; - } } 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 ad895480..9638ff7e 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -47,6 +47,7 @@ /** * Adapter for {@link DialogsList} */ +@SuppressWarnings("WeakerAccess") public class DialogsListAdapter

extends RecyclerView.Adapter { @@ -428,19 +429,19 @@ void setImageLoader(ImageLoader imageLoader) { this.imageLoader = imageLoader; } - void setOnDialogClickListener(OnDialogClickListener onDialogClickListener) { + protected void setOnDialogClickListener(OnDialogClickListener onDialogClickListener) { this.onDialogClickListener = onDialogClickListener; } - void setOnDialogViewClickListener(OnDialogViewClickListener onDialogViewClickListener) { + protected void setOnDialogViewClickListener(OnDialogViewClickListener onDialogViewClickListener) { this.onDialogViewClickListener = onDialogViewClickListener; } - void setOnLongItemClickListener(OnDialogLongClickListener onLongItemClickListener) { + protected void setOnLongItemClickListener(OnDialogLongClickListener onLongItemClickListener) { this.onLongItemClickListener = onLongItemClickListener; } - void setOnDialogViewLongClickListener(OnDialogViewLongClickListener onDialogViewLongClickListener) { + protected void setOnDialogViewLongClickListener(OnDialogViewLongClickListener onDialogViewLongClickListener) { this.onDialogViewLongClickListener = onDialogViewLongClickListener; } 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 f24fb444..8f126cd3 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java @@ -30,6 +30,7 @@ /* * Created by troy379 on 31.03.17. */ +@SuppressWarnings("WeakerAccess") public class MessageHolders { private static final short VIEW_TYPE_DATE_HEADER = 130; @@ -321,7 +322,7 @@ public interface ContentChecker { * PRIVATE METHODS * */ - ViewHolder getHolder(ViewGroup parent, int viewType, MessagesListStyle messagesListStyle) { + protected ViewHolder getHolder(ViewGroup parent, int viewType, MessagesListStyle messagesListStyle) { switch (viewType) { case VIEW_TYPE_DATE_HEADER: return getHolder(parent, dateHeaderLayout, dateHeaderHolder, messagesListStyle); @@ -347,12 +348,12 @@ ViewHolder getHolder(ViewGroup parent, int viewType, MessagesListStyle messagesL } @SuppressWarnings("unchecked") - void bind(final ViewHolder holder, final Object item, boolean isSelected, - final ImageLoader imageLoader, - final View.OnClickListener onMessageClickListener, - final View.OnLongClickListener onMessageLongClickListener, - final DateFormatter.Formatter dateHeadersFormatter, - final SparseArray clickListenersArray) { + protected void bind(final ViewHolder holder, final Object item, boolean isSelected, + final ImageLoader imageLoader, + final View.OnClickListener onMessageClickListener, + final View.OnLongClickListener onMessageLongClickListener, + final DateFormatter.Formatter dateHeadersFormatter, + final SparseArray clickListenersArray) { if (item instanceof IMessage) { ((MessageHolders.BaseMessageViewHolder) holder).isSelected = isSelected; @@ -380,7 +381,7 @@ public void onClick(View v) { } - int getViewType(Object item, String senderId) { + protected int getViewType(Object item, String senderId) { boolean isOutcoming = false; int viewType; @@ -411,7 +412,7 @@ ViewHolder getHolder(ViewGroup parent, @LayoutRes int layout, Class hold } return holder; } catch (Exception e) { - throw new RuntimeException("Somehow we couldn't create the ViewHolder for message. Please, report this issue on GitHub with full stacktrace in description.", e); + throw new UnsupportedOperationException("Somehow we couldn't create the ViewHolder for message. Please, report this issue on GitHub with full stacktrace in description.", e); } } @@ -453,7 +454,7 @@ public static abstract class BaseMessageViewHolder ext /** * Callback for implementing images loading in message list */ - ImageLoader imageLoader; + protected ImageLoader imageLoader; public BaseMessageViewHolder(View itemView) { super(itemView); @@ -877,8 +878,8 @@ private ContentTypeConfig( private class HolderConfig { - Class> holder; - int layout; + protected Class> holder; + protected int layout; HolderConfig(Class> holder, int layout) { this.holder = holder; 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 310fafad..92fe2d5a 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInput.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInput.java @@ -38,6 +38,7 @@ /** * Component for input outcoming messages */ +@SuppressWarnings({"WeakerAccess", "unused"}) public class MessageInput extends RelativeLayout implements View.OnClickListener, TextWatcher { @@ -130,7 +131,7 @@ public void onTextChanged(CharSequence s, int start, int count, int after) { */ @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { - + //do nothing } /** @@ -138,7 +139,7 @@ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) */ @Override public void afterTextChanged(Editable editable) { - + //do nothing } private boolean onSubmit() { 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 0c6d3248..99b4e7c9 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInputStyle.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInputStyle.java @@ -31,6 +31,7 @@ /** * Style for MessageInputStyle customization by xml attributes */ +@SuppressWarnings("WeakerAccess") class MessageInputStyle extends Style { private static final int DEFAULT_MAX_LINES = 5; @@ -169,11 +170,11 @@ private Drawable getSelector(@ColorInt int normalColor, @ColorInt int pressedCol return drawable; } - boolean showAttachmentButton() { + protected boolean showAttachmentButton() { return showAttachmentButton; } - Drawable getAttachmentButtonBackground() { + protected Drawable getAttachmentButtonBackground() { if (attachmentButtonBackground == -1) { return getSelector(attachmentButtonDefaultBgColor, attachmentButtonDefaultBgPressedColor, attachmentButtonDefaultBgDisabledColor, R.drawable.mask); @@ -182,7 +183,7 @@ Drawable getAttachmentButtonBackground() { } } - Drawable getAttachmentButtonIcon() { + protected Drawable getAttachmentButtonIcon() { if (attachmentButtonIcon == -1) { return getSelector(attachmentButtonDefaultIconColor, attachmentButtonDefaultIconPressedColor, attachmentButtonDefaultIconDisabledColor, R.drawable.ic_add_attachment); @@ -191,19 +192,19 @@ Drawable getAttachmentButtonIcon() { } } - int getAttachmentButtonWidth() { + protected int getAttachmentButtonWidth() { return attachmentButtonWidth; } - int getAttachmentButtonHeight() { + protected int getAttachmentButtonHeight() { return attachmentButtonHeight; } - int getAttachmentButtonMargin() { + protected int getAttachmentButtonMargin() { return attachmentButtonMargin; } - Drawable getInputButtonBackground() { + protected Drawable getInputButtonBackground() { if (inputButtonBackground == -1) { return getSelector(inputButtonDefaultBgColor, inputButtonDefaultBgPressedColor, inputButtonDefaultBgDisabledColor, R.drawable.mask); @@ -212,7 +213,7 @@ Drawable getInputButtonBackground() { } } - Drawable getInputButtonIcon() { + protected Drawable getInputButtonIcon() { if (inputButtonIcon == -1) { return getSelector(inputButtonDefaultIconColor, inputButtonDefaultIconPressedColor, inputButtonDefaultIconDisabledColor, R.drawable.ic_send); @@ -221,63 +222,63 @@ Drawable getInputButtonIcon() { } } - int getInputButtonMargin() { + protected int getInputButtonMargin() { return inputButtonMargin; } - int getInputButtonWidth() { + protected int getInputButtonWidth() { return inputButtonWidth; } - int getInputButtonHeight() { + protected int getInputButtonHeight() { return inputButtonHeight; } - int getInputMaxLines() { + protected int getInputMaxLines() { return inputMaxLines; } - String getInputHint() { + protected String getInputHint() { return inputHint; } - String getInputText() { + protected String getInputText() { return inputText; } - int getInputTextSize() { + protected int getInputTextSize() { return inputTextSize; } - int getInputTextColor() { + protected int getInputTextColor() { return inputTextColor; } - int getInputHintColor() { + protected int getInputHintColor() { return inputHintColor; } - Drawable getInputBackground() { + protected Drawable getInputBackground() { return inputBackground; } - Drawable getInputCursorDrawable() { + protected Drawable getInputCursorDrawable() { return inputCursorDrawable; } - int getInputDefaultPaddingLeft() { + protected int getInputDefaultPaddingLeft() { return inputDefaultPaddingLeft; } - int getInputDefaultPaddingRight() { + protected int getInputDefaultPaddingRight() { return inputDefaultPaddingRight; } - int getInputDefaultPaddingTop() { + protected int getInputDefaultPaddingTop() { return inputDefaultPaddingTop; } - int getInputDefaultPaddingBottom() { + protected int getInputDefaultPaddingBottom() { return inputDefaultPaddingBottom; } 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 4e1ec338..0533f221 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -44,6 +44,7 @@ /** * Adapter for {@link MessagesList}. */ +@SuppressWarnings("WeakerAccess") public class MessagesListAdapter extends RecyclerView.Adapter implements RecyclerScrollMoreListener.OnLoadMoreListener { @@ -55,7 +56,7 @@ public class MessagesListAdapter private int selectedItemsCount; private SelectionListener selectionListener; - static boolean isSelectionModeEnabled; + protected static boolean isSelectionModeEnabled; private OnLoadMoreListener loadMoreListener; private OnMessageClickListener onMessageClickListener; @@ -374,7 +375,8 @@ public void setOnMessageViewClickListener(OnMessageViewClickListener on /** * Registers click listener for view by id - * @param viewId view + * + * @param viewId view * @param onMessageViewClickListener click listener. */ public void registerViewClickListener(int viewId, OnMessageViewClickListener onMessageViewClickListener) { @@ -601,8 +603,8 @@ void setStyle(MessagesListStyle style) { * WRAPPER * */ private class Wrapper { - DATA item; - boolean isSelected; + protected DATA item; + protected boolean isSelected; Wrapper(DATA item) { this.item = item; 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 a1c06a59..88c6fe15 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListStyle.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListStyle.java @@ -33,6 +33,7 @@ /** * Style for MessagesListStyle customization by xml attributes */ +@SuppressWarnings("WeakerAccess") class MessagesListStyle extends Style { private int textAutoLinkMask; @@ -230,55 +231,55 @@ private Drawable getMessageSelector(@ColorInt int normalColor, @ColorInt int sel return drawable; } - int getTextAutoLinkMask() { + protected int getTextAutoLinkMask() { return textAutoLinkMask; } - int getIncomingTextLinkColor() { + protected int getIncomingTextLinkColor() { return incomingTextLinkColor; } - int getOutcomingTextLinkColor() { + protected int getOutcomingTextLinkColor() { return outcomingTextLinkColor; } - int getIncomingAvatarWidth() { + protected int getIncomingAvatarWidth() { return incomingAvatarWidth; } - int getIncomingAvatarHeight() { + protected int getIncomingAvatarHeight() { return incomingAvatarHeight; } - int getIncomingDefaultBubblePaddingLeft() { + protected int getIncomingDefaultBubblePaddingLeft() { return incomingDefaultBubblePaddingLeft; } - int getIncomingDefaultBubblePaddingRight() { + protected int getIncomingDefaultBubblePaddingRight() { return incomingDefaultBubblePaddingRight; } - int getIncomingDefaultBubblePaddingTop() { + protected int getIncomingDefaultBubblePaddingTop() { return incomingDefaultBubblePaddingTop; } - int getIncomingDefaultBubblePaddingBottom() { + protected int getIncomingDefaultBubblePaddingBottom() { return incomingDefaultBubblePaddingBottom; } - int getIncomingTextColor() { + protected int getIncomingTextColor() { return incomingTextColor; } - int getIncomingTextSize() { + protected int getIncomingTextSize() { return incomingTextSize; } - int getIncomingTextStyle() { + protected int getIncomingTextStyle() { return incomingTextStyle; } - Drawable getOutcomingBubbleDrawable() { + protected Drawable getOutcomingBubbleDrawable() { if (outcomingBubbleDrawable == -1) { return getMessageSelector(outcomingDefaultBubbleColor, outcomingDefaultBubbleSelectedColor, outcomingDefaultBubblePressedColor, R.drawable.shape_outcoming_message); @@ -287,7 +288,7 @@ Drawable getOutcomingBubbleDrawable() { } } - Drawable getOutcomingImageOverlayDrawable() { + protected Drawable getOutcomingImageOverlayDrawable() { if (outcomingImageOverlayDrawable == -1) { return getMessageSelector(Color.TRANSPARENT, outcomingDefaultImageOverlaySelectedColor, outcomingDefaultImageOverlayPressedColor, R.drawable.shape_outcoming_message); @@ -296,103 +297,103 @@ Drawable getOutcomingImageOverlayDrawable() { } } - int getOutcomingDefaultBubblePaddingLeft() { + protected int getOutcomingDefaultBubblePaddingLeft() { return outcomingDefaultBubblePaddingLeft; } - int getOutcomingDefaultBubblePaddingRight() { + protected int getOutcomingDefaultBubblePaddingRight() { return outcomingDefaultBubblePaddingRight; } - int getOutcomingDefaultBubblePaddingTop() { + protected int getOutcomingDefaultBubblePaddingTop() { return outcomingDefaultBubblePaddingTop; } - int getOutcomingDefaultBubblePaddingBottom() { + protected int getOutcomingDefaultBubblePaddingBottom() { return outcomingDefaultBubblePaddingBottom; } - int getOutcomingTextColor() { + protected int getOutcomingTextColor() { return outcomingTextColor; } - int getOutcomingTextSize() { + protected int getOutcomingTextSize() { return outcomingTextSize; } - int getOutcomingTextStyle() { + protected int getOutcomingTextStyle() { return outcomingTextStyle; } - int getOutcomingTimeTextColor() { + protected int getOutcomingTimeTextColor() { return outcomingTimeTextColor; } - int getOutcomingTimeTextSize() { + protected int getOutcomingTimeTextSize() { return outcomingTimeTextSize; } - int getOutcomingTimeTextStyle() { + protected int getOutcomingTimeTextStyle() { return outcomingTimeTextStyle; } - int getOutcomingImageTimeTextColor() { + protected int getOutcomingImageTimeTextColor() { return outcomingImageTimeTextColor; } - int getOutcomingImageTimeTextSize() { + protected int getOutcomingImageTimeTextSize() { return outcomingImageTimeTextSize; } - int getOutcomingImageTimeTextStyle() { + protected int getOutcomingImageTimeTextStyle() { return outcomingImageTimeTextStyle; } - int getDateHeaderTextColor() { + protected int getDateHeaderTextColor() { return dateHeaderTextColor; } - int getDateHeaderTextSize() { + protected int getDateHeaderTextSize() { return dateHeaderTextSize; } - int getDateHeaderTextStyle() { + protected int getDateHeaderTextStyle() { return dateHeaderTextStyle; } - int getDateHeaderPadding() { + protected int getDateHeaderPadding() { return dateHeaderPadding; } - String getDateHeaderFormat() { + protected String getDateHeaderFormat() { return dateHeaderFormat; } - int getIncomingTimeTextSize() { + protected int getIncomingTimeTextSize() { return incomingTimeTextSize; } - int getIncomingTimeTextStyle() { + protected int getIncomingTimeTextStyle() { return incomingTimeTextStyle; } - int getIncomingTimeTextColor() { + protected int getIncomingTimeTextColor() { return incomingTimeTextColor; } - int getIncomingImageTimeTextColor() { + protected int getIncomingImageTimeTextColor() { return incomingImageTimeTextColor; } - int getIncomingImageTimeTextSize() { + protected int getIncomingImageTimeTextSize() { return incomingImageTimeTextSize; } - int getIncomingImageTimeTextStyle() { + protected int getIncomingImageTimeTextStyle() { return incomingImageTimeTextStyle; } - Drawable getIncomingBubbleDrawable() { + protected Drawable getIncomingBubbleDrawable() { if (incomingBubbleDrawable == -1) { return getMessageSelector(incomingDefaultBubbleColor, incomingDefaultBubbleSelectedColor, incomingDefaultBubblePressedColor, R.drawable.shape_incoming_message); @@ -401,7 +402,7 @@ Drawable getIncomingBubbleDrawable() { } } - Drawable getIncomingImageOverlayDrawable() { + protected Drawable getIncomingImageOverlayDrawable() { if (incomingImageOverlayDrawable == -1) { return getMessageSelector(Color.TRANSPARENT, incomingDefaultImageOverlaySelectedColor, incomingDefaultImageOverlayPressedColor, R.drawable.shape_incoming_message); 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 91e85142..7770fb13 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/utils/RoundedImageView.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/utils/RoundedImageView.java @@ -21,6 +21,7 @@ import android.support.annotation.DimenRes; import android.support.annotation.NonNull; import android.support.v4.content.ContextCompat; +import android.support.v7.widget.AppCompatImageView; import android.util.AttributeSet; import android.widget.ImageView; @@ -28,7 +29,7 @@ * Thanks to Joonho Kim (https://github.com/pungrue26) for his lightweight SelectableRoundedImageView, * that was used as default image message representation */ -public class RoundedImageView extends ImageView { +public class RoundedImageView extends AppCompatImageView { private int mResource = 0; private Drawable mDrawable; @@ -124,7 +125,7 @@ private void updateDrawable() { ((RoundedCornerDrawable) mDrawable).setCornerRadii(mRadii); } - static class RoundedCornerDrawable extends Drawable { + private static class RoundedCornerDrawable extends Drawable { private RectF mBounds = new RectF(); private final RectF mBitmapRect = new RectF(); @@ -141,7 +142,7 @@ static class RoundedCornerDrawable extends Drawable { private Bitmap mBitmap; private boolean mBoundsConfigured = false; - RoundedCornerDrawable(Bitmap bitmap, Resources r) { + private RoundedCornerDrawable(Bitmap bitmap, Resources r) { mBitmap = bitmap; mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); @@ -155,12 +156,12 @@ static class RoundedCornerDrawable extends Drawable { mBitmapPaint.setShader(mBitmapShader); } - static RoundedCornerDrawable fromBitmap(Bitmap bitmap, Resources r) { + private static RoundedCornerDrawable fromBitmap(Bitmap bitmap, Resources r) { if (bitmap != null) return new RoundedCornerDrawable(bitmap, r); else return null; } - static Drawable fromDrawable(Drawable drawable, Resources r) { + private static Drawable fromDrawable(Drawable drawable, Resources r) { if (drawable != null) { if (drawable instanceof RoundedCornerDrawable) { return drawable; @@ -180,7 +181,7 @@ static Drawable fromDrawable(Drawable drawable, Resources r) { return drawable; } - static Bitmap drawableToBitmap(Drawable drawable) { + private static Bitmap drawableToBitmap(Drawable drawable) { if (drawable == null) return null; if (drawable instanceof BitmapDrawable) { From 7e3148c2744594138d6e6e473373786e37be06fe Mon Sep 17 00:00:00 2001 From: Harold Martin Date: Thu, 20 Jul 2017 17:31:02 -0700 Subject: [PATCH 23/96] Added upsert(Message) method to add or update message to adapter as appropriate Useful when connecting adapter directly to streaming data source Changed update methods to return boolean --- .../chatkit/messages/MessagesListAdapter.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) 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 0533f221..d5d957ad 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -178,8 +178,8 @@ public void addToEnd(List messages, boolean reverse) { * * @param message updated message object. */ - public void update(MESSAGE message) { - update(message.getId(), message); + public boolean update(MESSAGE message) { + return update(message.getId(), message); } /** @@ -188,12 +188,26 @@ public void update(MESSAGE message) { * @param oldId an identifier of message to update. * @param newMessage new message object. */ - public void update(String oldId, MESSAGE newMessage) { + public boolean update(String oldId, MESSAGE newMessage) { int position = getMessagePositionById(oldId); if (position >= 0) { Wrapper element = new Wrapper<>(newMessage); items.set(position, element); notifyItemChanged(position); + return true; + } else { + return false; + } + } + + /** + * Updates message by its id if it exists, add to start if not + * + * @param message message object to insert or update. + */ + public void upsert(MESSAGE message) { + if (!update(message)) { + addToStart(message, false); } } From 86b2a86102f57d460166504bdaa9dcaab0e94a0c Mon Sep 17 00:00:00 2001 From: Harold Martin Date: Fri, 21 Jul 2017 14:57:19 -0700 Subject: [PATCH 24/96] remove application tag from manifest --- chatkit/src/main/AndroidManifest.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/chatkit/src/main/AndroidManifest.xml b/chatkit/src/main/AndroidManifest.xml index 9f22fb31..1b8f973d 100644 --- a/chatkit/src/main/AndroidManifest.xml +++ b/chatkit/src/main/AndroidManifest.xml @@ -1,8 +1,4 @@ - - From a0d3cec62a5333b9cfe55ebe5cc66386e99412cf Mon Sep 17 00:00:00 2001 From: Mindaugas Date: Fri, 4 Aug 2017 13:58:46 +0300 Subject: [PATCH 25/96] npe check in DialofsListAdapter.java for last message when exists none --- .../chatkit/dialogs/DialogsListAdapter.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) 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 9638ff7e..1a1c8851 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -584,26 +584,31 @@ public void onBind(final DIALOG dialog) { //Set Date String formattedDate = null; - Date lastMessageDate = dialog.getLastMessage().getCreatedAt(); - if (datesFormatter != null) formattedDate = datesFormatter.format(lastMessageDate); - tvDate.setText(formattedDate == null - ? getDateString(lastMessageDate) - : formattedDate); + + if (dialog.getLastMessage() != null) { + Date lastMessageDate = dialog.getLastMessage().getCreatedAt(); + if (datesFormatter != null) formattedDate = datesFormatter.format(lastMessageDate); + tvDate.setText(formattedDate == null + ? getDateString(lastMessageDate) + : formattedDate); + } //Set Dialog avatar if (imageLoader != null) { imageLoader.loadImage(ivAvatar, dialog.getDialogPhoto()); } - //Set Last message user avatar - if (imageLoader != null) { + //Set Last message user avatar with check if there is last message + if (imageLoader != null && dialog.getLastMessage() != null) { imageLoader.loadImage(ivLastMessageUser, dialog.getLastMessage().getUser().getAvatar()); } ivLastMessageUser.setVisibility(dialogStyle.isDialogMessageAvatarEnabled() && dialog.getUsers().size() > 1 ? VISIBLE : GONE); //Set Last message text - tvLastMessage.setText(dialog.getLastMessage().getText()); + if (dialog.getLastMessage() != null) { + tvLastMessage.setText(dialog.getLastMessage().getText()); + } //Set Unread message count bubble tvBubble.setText(String.valueOf(dialog.getUnreadCount())); From 25ec6be9ce373e941ebad9ff254d7cb9fc5962aa Mon Sep 17 00:00:00 2001 From: Philippe Auriach Date: Wed, 9 Aug 2017 10:13:18 +0200 Subject: [PATCH 26/96] added get item by id method --- .../chatkit/dialogs/DialogsListAdapter.java | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) 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 9638ff7e..697ad343 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -19,6 +19,7 @@ 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 android.util.TypedValue; import android.view.LayoutInflater; @@ -245,6 +246,29 @@ public void updateItemById(DIALOG item) { } } + /** + * Find an item by its id + * + * @param id the wanted item's id + * @return the found item, or null + */ + @Nullable + public DIALOG getItemById(String id) { + if (items == null) { + items = new ArrayList<>(); + } + for (DIALOG item : items) { + if (item.getId() == null) { + if (id == null) { + return item; + } + } else if (item.getId().equals(id)) { + return item; + } + } + return null; + } + /** * Update last message in dialog and swap item to top of list. * @@ -297,6 +321,13 @@ public void sort(Comparator comparator) { notifyDataSetChanged(); } + /** + * @return registered image loader + */ + public ImageLoader getImageLoader() { + return imageLoader; + } + /** * Register a callback to be invoked when image need to load. * @@ -306,13 +337,6 @@ public void setImageLoader(ImageLoader imageLoader) { this.imageLoader = imageLoader; } - /** - * @return registered image loader - */ - public ImageLoader getImageLoader() { - return imageLoader; - } - /** * @return the item click callback. */ From b80f3a336a2702eb56191f206592e613b28420d0 Mon Sep 17 00:00:00 2001 From: Philippe Auriach Date: Wed, 9 Aug 2017 10:38:49 +0200 Subject: [PATCH 27/96] allow moving an item from position x to position y --- .../stfalcon/chatkit/dialogs/DialogsListAdapter.java | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 697ad343..4fcad21e 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -214,6 +214,17 @@ public void addItem(int position, DIALOG dialog) { notifyItemInserted(position); } + /** + * Move an item + * @param fromPosition the actual position of the item + * @param toPosition the new position of the item + */ + public void moveItem(int fromPosition, int toPosition) { + DIALOG dialog = items.remove(fromPosition); + items.add(toPosition, dialog); + notifyItemMoved(fromPosition, toPosition); + } + /** * Update dialog by position in dialogs list * From f2e5cc7ce237130799b365ddd705448fe07b877e Mon Sep 17 00:00:00 2001 From: Philippe Auriach Date: Wed, 9 Aug 2017 11:24:42 +0200 Subject: [PATCH 28/96] test jitpack compile --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index f0f8043a..111c8fe5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':sample', ':chatkit' +include 'chatkit' From f906bb2db76ce8bfe0ac6b6c06342eda937e7cc2 Mon Sep 17 00:00:00 2001 From: Philippe Auriach Date: Wed, 9 Aug 2017 11:26:55 +0200 Subject: [PATCH 29/96] Revert "test jitpack compile" This reverts commit f2e5cc7ce237130799b365ddd705448fe07b877e. --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 111c8fe5..f0f8043a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include 'chatkit' +include ':sample', ':chatkit' From f268da6959a9081165a763bc9735cb73066755e2 Mon Sep 17 00:00:00 2001 From: Philippe Auriach Date: Wed, 9 Aug 2017 14:49:42 +0200 Subject: [PATCH 30/96] please codebeat --- .../com/stfalcon/chatkit/dialogs/DialogsListAdapter.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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 4fcad21e..78636868 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -269,11 +269,9 @@ public DIALOG getItemById(String id) { items = new ArrayList<>(); } for (DIALOG item : items) { - if (item.getId() == null) { - if (id == null) { - return item; - } - } else if (item.getId().equals(id)) { + if (item.getId() == null && id == null) { + return item; + } else if (item.getId() != null && item.getId().equals(id)) { return item; } } From a0c43a728a8a0a4f478e73c6bf899ac58d231ee6 Mon Sep 17 00:00:00 2001 From: Iyanu Adelekan Date: Tue, 21 Nov 2017 16:19:01 +0100 Subject: [PATCH 31/96] Made correction to DialogList documentation A typographic error was made in the documentation for the DialogList component under the 'Prepare your model' section. "IDialog" was written as "IDealog". This pull request corrects that error. --- docs/COMPONENT_DIALOGS_LIST.MD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/COMPONENT_DIALOGS_LIST.MD b/docs/COMPONENT_DIALOGS_LIST.MD index 673457b2..61bea52d 100644 --- a/docs/COMPONENT_DIALOGS_LIST.MD +++ b/docs/COMPONENT_DIALOGS_LIST.MD @@ -36,7 +36,7 @@ dialogsListView.setAdapter(dialogsListAdapter); #### Prepare your model -To be able to add dialog, you must implement the `IDealog` interface to your existing model and override its methods: +To be able to add dialog, you must implement the `IDialog` interface to your existing model and override its methods: ```java public class DefaultDialog implements IDialog { From ca015bb774ccfca33ba1591c534f4327f60456bc Mon Sep 17 00:00:00 2001 From: Daniel Mathews Date: Wed, 20 Dec 2017 18:22:21 -0800 Subject: [PATCH 32/96] Add nullable for getImageUrl() Add the option for nullable to distinguish between a message and image. Useful for when using Kotlin. --- .../com/stfalcon/chatkit/commons/models/MessageContentType.java | 2 ++ 1 file changed, 2 insertions(+) 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 f5b63995..b8f2675a 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,6 +16,7 @@ package com.stfalcon.chatkit.commons.models; +import android.support.annotation.Nullable; import com.stfalcon.chatkit.messages.MessageHolders; /* @@ -32,6 +33,7 @@ public interface MessageContentType extends IMessage { * Default media type for image message. */ interface Image extends IMessage { + @Nullable String getImageUrl(); } From 1044829af2dbb49546c6c19ec362ed85dc06734d Mon Sep 17 00:00:00 2001 From: Mohamed Alouane Date: Sat, 17 Feb 2018 00:24:05 +0000 Subject: [PATCH 33/96] fix link in docs --- docs/STYLES_ATTR.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/STYLES_ATTR.md b/docs/STYLES_ATTR.md index df2075e4..790de29b 100644 --- a/docs/STYLES_ATTR.md +++ b/docs/STYLES_ATTR.md @@ -37,7 +37,7 @@ | `dialogItemBackground` | Sets background of dialogs items| | `dialogItemBackground` | Sets background of dialogs items when has unread messages | -## [MessagesList]](COMPONENT_MESSAGES_LIST.md) xml attributes: +## [MessagesList](COMPONENT_MESSAGES_LIST.md) xml attributes: | Attribute | Description| | ------------- |-------------| @@ -126,4 +126,4 @@ | `inputTextColor` | Sets input message text color| | `inputHintColor` | Sets text color of hint in message input field| | `inputBackground` | Sets background for input message view | -| `inputCursorDrawable` | Sets cursor drawable for input message EditText | \ No newline at end of file +| `inputCursorDrawable` | Sets cursor drawable for input message EditText | From 2fbf4dce2e19f3e40731c147aa1c1ebde3637047 Mon Sep 17 00:00:00 2001 From: Thibault Guegan Date: Mon, 26 Feb 2018 11:21:25 +0000 Subject: [PATCH 34/96] wording --- .../java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9638ff7e..8234133b 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -206,7 +206,7 @@ public void addItem(DIALOG dialog) { * Add dialog to dialogs list * * @param dialog dialog item - * @param position position in dialogs lost + * @param position position in dialogs list */ public void addItem(int position, DIALOG dialog) { items.add(position, dialog); From d93d0de20ed305eea71db9e0ea10dece98f5aef8 Mon Sep 17 00:00:00 2001 From: Christian Olcina <17082246+Sulfkain@users.noreply.github.com> Date: Tue, 13 Mar 2018 17:39:57 +0100 Subject: [PATCH 35/96] Avoid Crash on empty list If some empty list passed to insert at the end, will crash with a indexOutOfBounds. To avoid this, it's recomended to add a check to see if the list is empty or not. And adding a @NotNull anotation to the param will be useful to use it with Kotlin. If you don't like a "fast" return, do it with a tipical if. --- .../java/com/stfalcon/chatkit/messages/MessagesListAdapter.java | 2 ++ 1 file changed, 2 insertions(+) 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 0533f221..2cac43c2 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -157,6 +157,8 @@ public void addToStart(MESSAGE message, boolean scroll) { * @param reverse {@code true} if need to reverse messages before adding. */ public void addToEnd(List messages, boolean reverse) { + if (messages.isEmpty()) return + if (reverse) Collections.reverse(messages); if (!items.isEmpty()) { From 2b806f3d95d5e5938ef27ee6a572e13667b7b026 Mon Sep 17 00:00:00 2001 From: "andrii.zhumela" Date: Tue, 3 Jul 2018 14:41:53 +0300 Subject: [PATCH 36/96] update support library version --- build.gradle | 8 ++++++++ chatkit/build.gradle | 10 +++++----- sample/build.gradle | 17 ++++++++++++----- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 3c9f496e..0accc142 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,10 @@ buildscript { repositories { jcenter() + maven { + url 'https://maven.google.com/' + name 'Google' + } } dependencies { classpath 'com.android.tools.build:gradle:2.3.1' @@ -16,6 +20,10 @@ buildscript { allprojects { repositories { jcenter() + maven { + url 'https://maven.google.com/' + name 'Google' + } } } diff --git a/chatkit/build.gradle b/chatkit/build.gradle index 54b43859..6a94c06f 100644 --- a/chatkit/build.gradle +++ b/chatkit/build.gradle @@ -2,12 +2,12 @@ apply plugin: 'com.android.library' apply plugin: 'com.novoda.bintray-release' android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" + compileSdkVersion 27 + buildToolsVersion "27.0.3" defaultConfig { minSdkVersion 14 - targetSdkVersion 25 + targetSdkVersion 27 versionCode 1 versionName "0.2.2" @@ -31,8 +31,8 @@ publish { } ext { - supportVersion = '25.3.1' - flexboxVersion = '0.2.5' + supportVersion = '27.1.1' + flexboxVersion = '1.0.0' } dependencies { diff --git a/sample/build.gradle b/sample/build.gradle index 13d52cae..aea17b5c 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" + compileSdkVersion 27 + buildToolsVersion "27.0.3" defaultConfig { applicationId "com.stfalcon.chatkit.sample" minSdkVersion 14 - targetSdkVersion 25 + targetSdkVersion 27 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -25,9 +25,9 @@ android { } ext { - supportVersion = '25.3.1' + supportVersion = '27.1.1' picassoVersion = '2.5.2' - circleImageViewVersion = '2.1.0' + circleImageViewVersion = '2.2.0' shapeImageViewVersion = '0.9.3' circleindicatorVersion = '1.2.2@aar' } @@ -54,4 +54,11 @@ dependencies { //Utils compile "me.relex:circleindicator:$circleindicatorVersion" + + compile "com.android.support:support-v4:$supportVersion" + compile "com.android.support:design:$supportVersion" + compile "com.android.support:support-vector-drawable:$supportVersion" + compile 'com.android.support.constraint:constraint-layout:1.1.2' + compile "com.android.support:gridlayout-v7:$supportVersion" + compile "com.android.support:recyclerview-v7:$supportVersion" } From 0a7287fcdf9114eb49db8c56938be0ec0c2a6c87 Mon Sep 17 00:00:00 2001 From: "andrii.zhumela" Date: Tue, 3 Jul 2018 14:53:04 +0300 Subject: [PATCH 37/96] update gradle version version --- build.gradle | 5 +++-- gradle/wrapper/gradle-wrapper.properties | 4 ++-- sample/build.gradle | 12 ++++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 0accc142..80103afe 100644 --- a/build.gradle +++ b/build.gradle @@ -7,10 +7,11 @@ buildscript { url 'https://maven.google.com/' name 'Google' } + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.1' - classpath 'com.novoda:bintray-release:0.4.0' + classpath 'com.android.tools.build:gradle:3.1.3' + classpath 'com.novoda:bintray-release:0.8.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fb4882dc..d0edd216 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Apr 06 11:02:19 EEST 2017 +#Tue Jul 03 14:43:10 EEST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/sample/build.gradle b/sample/build.gradle index aea17b5c..a3c9774d 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -55,10 +55,10 @@ dependencies { //Utils compile "me.relex:circleindicator:$circleindicatorVersion" - compile "com.android.support:support-v4:$supportVersion" - compile "com.android.support:design:$supportVersion" - compile "com.android.support:support-vector-drawable:$supportVersion" - compile 'com.android.support.constraint:constraint-layout:1.1.2' - compile "com.android.support:gridlayout-v7:$supportVersion" - compile "com.android.support:recyclerview-v7:$supportVersion" + implementation "com.android.support:support-v4:$supportVersion" + implementation "com.android.support:design:$supportVersion" + implementation "com.android.support:support-vector-drawable:$supportVersion" + implementation 'com.android.support.constraint:constraint-layout:1.1.2' + implementation "com.android.support:gridlayout-v7:$supportVersion" + implementation "com.android.support:recyclerview-v7:$supportVersion" } From c31034838543d370cfa41d8d0e4673efe14122f5 Mon Sep 17 00:00:00 2001 From: "andrii.zhumela" Date: Tue, 3 Jul 2018 15:06:59 +0300 Subject: [PATCH 38/96] remove old command from gradle --- chatkit/build.gradle | 6 +++--- sample/build.gradle | 24 +++++++++--------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/chatkit/build.gradle b/chatkit/build.gradle index 6a94c06f..09ca8a04 100644 --- a/chatkit/build.gradle +++ b/chatkit/build.gradle @@ -38,7 +38,7 @@ ext { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile "com.android.support:appcompat-v7:$supportVersion" - compile "com.android.support:design:$supportVersion" - compile "com.google.android:flexbox:$flexboxVersion" + implementation "com.android.support:appcompat-v7:$supportVersion" + implementation "com.android.support:design:$supportVersion" + implementation "com.google.android:flexbox:$flexboxVersion" } diff --git a/sample/build.gradle b/sample/build.gradle index a3c9774d..2799ea4d 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -36,29 +36,23 @@ dependencies { compile project(':chatkit') compile fileTree(dir: 'libs', include: ['*.jar']) - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - testCompile 'junit:junit:4.12' + testImplementation 'junit:junit:4.12' - compile "com.android.support:appcompat-v7:$supportVersion" - compile "com.android.support:cardview-v7:$supportVersion" - compile "com.android.support:design:$supportVersion" + implementation "com.android.support:appcompat-v7:$supportVersion" + implementation "com.android.support:cardview-v7:$supportVersion" + implementation "com.android.support:design:$supportVersion" //Picasso - compile "com.squareup.picasso:picasso:$picassoVersion" + implementation "com.squareup.picasso:picasso:$picassoVersion" //ImageViews - compile "de.hdodenhof:circleimageview:$circleImageViewVersion" - compile "com.github.siyamed:android-shape-imageview:$shapeImageViewVersion" + implementation "de.hdodenhof:circleimageview:$circleImageViewVersion" + implementation "com.github.siyamed:android-shape-imageview:$shapeImageViewVersion" //Utils - compile "me.relex:circleindicator:$circleindicatorVersion" + implementation "me.relex:circleindicator:$circleindicatorVersion" - implementation "com.android.support:support-v4:$supportVersion" - implementation "com.android.support:design:$supportVersion" - implementation "com.android.support:support-vector-drawable:$supportVersion" - implementation 'com.android.support.constraint:constraint-layout:1.1.2' - implementation "com.android.support:gridlayout-v7:$supportVersion" - implementation "com.android.support:recyclerview-v7:$supportVersion" } From 8511efd0cd8ac233e828c6d99eb1fa2e2a035da4 Mon Sep 17 00:00:00 2001 From: "andrii.zhumela" Date: Tue, 3 Jul 2018 15:09:45 +0300 Subject: [PATCH 39/96] remove old tags from gradle --- chatkit/build.gradle | 3 +-- sample/build.gradle | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/chatkit/build.gradle b/chatkit/build.gradle index 09ca8a04..2d058c2f 100644 --- a/chatkit/build.gradle +++ b/chatkit/build.gradle @@ -7,7 +7,6 @@ android { defaultConfig { minSdkVersion 14 - targetSdkVersion 27 versionCode 1 versionName "0.2.2" @@ -36,7 +35,7 @@ ext { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) + implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "com.android.support:appcompat-v7:$supportVersion" implementation "com.android.support:design:$supportVersion" diff --git a/sample/build.gradle b/sample/build.gradle index 2799ea4d..dbed4d4e 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -6,7 +6,6 @@ android { defaultConfig { applicationId "com.stfalcon.chatkit.sample" minSdkVersion 14 - targetSdkVersion 27 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -33,9 +32,9 @@ ext { } dependencies { - compile project(':chatkit') + implementation project(':chatkit') - compile fileTree(dir: 'libs', include: ['*.jar']) + implementation fileTree(dir: 'libs', include: ['*.jar']) androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) From bafd2e19069a3f0ce7efd410c593ff287a6caade Mon Sep 17 00:00:00 2001 From: Anton Date: Tue, 10 Jul 2018 11:14:29 +0300 Subject: [PATCH 40/96] Fixed artifacts on some devices in ShapeImageView. Changed fixture message image. --- .../stfalcon/chatkit/utils/ShapeImageView.java | 15 +++++++++++---- .../sample/common/data/fixtures/FixturesData.java | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) 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 d9717f64..b9f054c5 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/utils/ShapeImageView.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/utils/ShapeImageView.java @@ -20,21 +20,23 @@ import android.graphics.Canvas; import android.graphics.Path; import android.util.AttributeSet; -import android.widget.ImageView; +import android.view.View; /** * ImageView with mask what described with Bézier Curves */ -public class ShapeImageView extends ImageView { +public class ShapeImageView extends android.support.v7.widget.AppCompatImageView { private Path path; public ShapeImageView(Context context) { super(context); + setLayerType(View.LAYER_TYPE_SOFTWARE, null); } public ShapeImageView(Context context, AttributeSet attrs) { super(context, attrs); + setLayerType(View.LAYER_TYPE_SOFTWARE, null); } @Override @@ -56,9 +58,14 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { @Override protected void onDraw(Canvas canvas) { - if (canvas != null) { - canvas.clipPath(path); + if (path.isEmpty()) { super.onDraw(canvas); + return; } + + int saveCount = canvas.save(); + canvas.clipPath(path); + super.onDraw(canvas); + canvas.restoreToCount(saveCount); } } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/common/data/fixtures/FixturesData.java b/sample/src/main/java/com/stfalcon/chatkit/sample/common/data/fixtures/FixturesData.java index 6f7d35bc..ead984e3 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/common/data/fixtures/FixturesData.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/common/data/fixtures/FixturesData.java @@ -71,7 +71,7 @@ abstract class FixturesData { static final ArrayList images = new ArrayList() { { add("https://habrastorage.org/getpro/habr/post_images/e4b/067/b17/e4b067b17a3e414083f7420351db272b.jpg"); - add("http://www.designboom.com/wp-content/uploads/2015/11/stefano-boeri-architetti-vertical-forest-residential-tower-lausanne-switzerland-designboom-01.jpg"); + add("https://cdn.pixabay.com/photo/2017/12/25/17/48/waters-3038803_1280.jpg"); } }; From bad7494fc78777f4640880c4915279063162ef2f Mon Sep 17 00:00:00 2001 From: Anton Date: Tue, 10 Jul 2018 12:34:46 +0300 Subject: [PATCH 41/96] Version 0.2.3 --- chatkit/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chatkit/build.gradle b/chatkit/build.gradle index 2d058c2f..9b5ab0ed 100644 --- a/chatkit/build.gradle +++ b/chatkit/build.gradle @@ -8,7 +8,7 @@ android { defaultConfig { minSdkVersion 14 versionCode 1 - versionName "0.2.2" + versionName "0.2.3" consumerProguardFiles 'proguard.txt' } @@ -22,7 +22,7 @@ android { publish { groupId = 'com.github.stfalcon' artifactId = 'chatkit' - publishVersion = '0.2.2' + publishVersion = '0.2.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' From 91fd6997c2cb51e7a91628a0096e7c4a79e6e63d Mon Sep 17 00:00:00 2001 From: Anton Date: Tue, 10 Jul 2018 12:38:22 +0300 Subject: [PATCH 42/96] hot fix --- .../java/com/stfalcon/chatkit/messages/MessagesListAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2cac43c2..4f0ee777 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -157,7 +157,7 @@ public void addToStart(MESSAGE message, boolean scroll) { * @param reverse {@code true} if need to reverse messages before adding. */ public void addToEnd(List messages, boolean reverse) { - if (messages.isEmpty()) return + if (messages.isEmpty()) return; if (reverse) Collections.reverse(messages); From 784766caf3789875a0332bb9d71bb5d97d88f3fe Mon Sep 17 00:00:00 2001 From: Anton Bevza Date: Tue, 10 Jul 2018 12:42:06 +0300 Subject: [PATCH 43/96] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bb59cb6d..b40aaf8d 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ To implement all of the features above you can use the following components: Download via Gradle: ```gradle -compile 'com.github.stfalcon:chatkit:0.2.2' +compile 'com.github.stfalcon:chatkit:0.2.3' ``` or Maven: @@ -51,7 +51,7 @@ or Maven: com.github.stfalcon chatkit - 0.2.2 + 0.2.3 pom ``` From 9f3ebe2d745dd7c85c9e06135d54cc31ff3396a5 Mon Sep 17 00:00:00 2001 From: Anton Date: Tue, 10 Jul 2018 14:32:14 +0300 Subject: [PATCH 44/96] Fixed Add attachments button in default view demo --- .../sample/features/demo/def/DefaultMessagesActivity.java | 1 + 1 file changed, 1 insertion(+) diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java index f4fd9b36..86b8ee8f 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java @@ -34,6 +34,7 @@ protected void onCreate(Bundle savedInstanceState) { MessageInput input = (MessageInput) findViewById(R.id.input); input.setInputListener(this); + input.setAttachmentsListener(this); } @Override From 5a22499e55e281b3abf643fe3b8e9e43f72dd23a Mon Sep 17 00:00:00 2001 From: Anton Bevza Date: Tue, 10 Jul 2018 14:39:59 +0300 Subject: [PATCH 45/96] Create LICENSE --- LICENSE | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..261eeb9e --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. From 9b0abf37aed276420b23fb5eeb1ae4ef3b88a9c8 Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 11 Jul 2018 11:01:18 +0300 Subject: [PATCH 46/96] Merge branch 'add_typing_listener' of https://github.com/toanpv/ChatKit into toanpv-add_typing_listener # Conflicts: # docs/STYLES_ATTR.md # sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java --- .../sample/features/demo/def/DefaultMessagesActivity.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java index 847fc76c..f13b839f 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java @@ -3,8 +3,8 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.util.Log; import android.view.View; -import android.widget.Toast; import com.stfalcon.chatkit.messages.MessageInput; import com.stfalcon.chatkit.messages.MessagesList; @@ -71,11 +71,11 @@ public void onMessageViewClick(View view, Message message) { @Override public void onStartTyping() { - Toast.makeText(this, R.string.start_typing_status, Toast.LENGTH_SHORT).show(); + Log.v("Typing listener", getString(R.string.start_typing_status)); } @Override public void onStopTyping() { - Toast.makeText(this, R.string.stop_typing_status, Toast.LENGTH_SHORT).show(); + Log.v("Typing listener", getString(R.string.stop_typing_status)); } } From da51c5f15f707c64e8fd1acca0b9cc3fed61c06e Mon Sep 17 00:00:00 2001 From: Anton Bevza Date: Wed, 11 Jul 2018 11:51:23 +0300 Subject: [PATCH 47/96] Update LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 261eeb9e..de57238b 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright 2018 stfalcon.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From 6848a6e09930fe96d2e9370b3c311399e197776f Mon Sep 17 00:00:00 2001 From: Anton Bevza Date: Wed, 11 Jul 2018 11:54:15 +0300 Subject: [PATCH 48/96] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b40aaf8d..d4a56118 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at -http://www.apache.org/licenses/LICENSE-2.0 +https://github.com/stfalcon-studio/ChatKit/blob/master/LICENSE Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, From 95fc88e83c3119bc1466098d3069cb6c4059c65c Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 11 Jul 2018 11:56:08 +0300 Subject: [PATCH 49/96] Fixed artifacts with bubble background in message list. DialogList: reverseLayout=false for default --- .../main/java/com/stfalcon/chatkit/dialogs/DialogsList.java | 2 +- .../main/java/com/stfalcon/chatkit/messages/MessagesList.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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 55f531af..6336203d 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsList.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsList.java @@ -75,7 +75,7 @@ public void setAdapter(Adapter adapter) { */ public void setAdapter(DialogsListAdapter adapter) { - setAdapter(adapter, true); + setAdapter(adapter, false); } /** 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..e68f0906 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesList.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesList.java @@ -23,6 +23,7 @@ import android.support.v7.widget.RecyclerView; import android.support.v7.widget.SimpleItemAnimator; import android.util.AttributeSet; +import android.view.View; import com.stfalcon.chatkit.commons.models.IMessage; @@ -34,16 +35,19 @@ public class MessagesList extends RecyclerView { public MessagesList(Context context) { super(context); + setLayerType(View.LAYER_TYPE_SOFTWARE, null); } public MessagesList(Context context, @Nullable AttributeSet attrs) { super(context, attrs); parseStyle(context, attrs); + setLayerType(View.LAYER_TYPE_SOFTWARE, null); } public MessagesList(Context context, @Nullable AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); parseStyle(context, attrs); + setLayerType(View.LAYER_TYPE_SOFTWARE, null); } /** From 208e3e8b2bb9520a02448adb4e13c4fbbcb7402a Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 11 Jul 2018 12:04:38 +0300 Subject: [PATCH 50/96] MessageListAdapter: added notifyDataSetChanged to method "clear" --- .../chatkit/messages/MessagesListAdapter.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) 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 e45a50e4..ff8aa0b8 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -128,8 +128,8 @@ public void onLoadMore(int page, int total) { } /* - * PUBLIC METHODS - * */ + * PUBLIC METHODS + * */ /** * Adds message to bottom of list and scroll if needed. @@ -158,7 +158,7 @@ public void addToStart(MESSAGE message, boolean scroll) { */ public void addToEnd(List messages, boolean reverse) { if (messages.isEmpty()) return; - + if (reverse) Collections.reverse(messages); if (!items.isEmpty()) { @@ -205,7 +205,7 @@ public boolean update(String oldId, MESSAGE newMessage) { /** * Updates message by its id if it exists, add to start if not * - * @param message message object to insert or update. + * @param message message object to insert or update. */ public void upsert(MESSAGE message) { if (!update(message)) { @@ -277,7 +277,10 @@ public boolean isEmpty() { * Clears the messages list. */ public void clear() { - items.clear(); + if (items != null) { + items.clear(); + notifyDataSetChanged(); + } } /** @@ -434,8 +437,8 @@ public void setDateHeadersFormatter(DateFormatter.Formatter dateHeadersFormatter } /* - * PRIVATE METHODS - * */ + * PRIVATE METHODS + * */ private void recountDateHeaders() { List indicesToDelete = new ArrayList<>(); @@ -616,8 +619,8 @@ void setStyle(MessagesListStyle style) { } /* - * WRAPPER - * */ + * WRAPPER + * */ private class Wrapper { protected DATA item; protected boolean isSelected; @@ -628,8 +631,8 @@ private class Wrapper { } /* - * LISTENERS - * */ + * LISTENERS + * */ /** * Interface definition for a callback to be invoked when next part of messages need to be loaded. From 3461ab348867d6db7e165330a6779f2aa7592b1c Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 11 Jul 2018 14:35:32 +0300 Subject: [PATCH 51/96] Fixed bug "The totalItemsCount parameter in OnLoadMore callback contains date header." Issue #86 Added separate method MessagesListAdapter.clear(notifyDataSetChanged). Method MessagesListAdapter.clear() does notifyDataSetChanged by default. Issue #89 --- .../chatkit/messages/MessagesListAdapter.java | 28 ++++++++++++++++--- .../messages/RecyclerScrollMoreListener.java | 4 ++- .../features/demo/DemoMessagesActivity.java | 2 ++ 3 files changed, 29 insertions(+), 5 deletions(-) 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 ff8aa0b8..cbc403d2 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -49,6 +49,8 @@ public class MessagesListAdapter extends RecyclerView.Adapter implements RecyclerScrollMoreListener.OnLoadMoreListener { + protected static boolean isSelectionModeEnabled; + private MessageHolders holders; private String senderId; private List items; @@ -56,8 +58,6 @@ public class MessagesListAdapter private int selectedItemsCount; private SelectionListener selectionListener; - protected static boolean isSelectionModeEnabled; - private OnLoadMoreListener loadMoreListener; private OnMessageClickListener onMessageClickListener; private OnMessageViewClickListener onMessageViewClickListener; @@ -127,6 +127,17 @@ public void onLoadMore(int page, int total) { } } + @Override + public int getMessagesCount() { + int count = 0; + for (Wrapper item : items) { + if (item.item instanceof IMessage) { + count++; + } + } + return count; + } + /* * PUBLIC METHODS * */ @@ -274,12 +285,21 @@ public boolean isEmpty() { } /** - * Clears the messages list. + * Clears the messages list. With notifyDataSetChanged */ public void clear() { + clear(true); + } + + /** + * Clears the messages list. + */ + public void clear(boolean notifyDataSetChanged) { if (items != null) { items.clear(); - notifyDataSetChanged(); + if (notifyDataSetChanged) { + notifyDataSetChanged(); + } } } 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 92cffc38..00012084 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/RecyclerScrollMoreListener.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/RecyclerScrollMoreListener.java @@ -79,7 +79,7 @@ public void onScrolled(RecyclerView view, int dx, int dy) { int visibleThreshold = 5; if (!loading && (lastVisibleItemPosition + visibleThreshold) > totalItemCount) { currentPage++; - loadMoreListener.onLoadMore(currentPage, totalItemCount); + loadMoreListener.onLoadMore(loadMoreListener.getMessagesCount(), totalItemCount); loading = true; } } @@ -87,5 +87,7 @@ public void onScrolled(RecyclerView view, int dx, int dy) { interface OnLoadMoreListener { void onLoadMore(int page, int total); + + int getMessagesCount(); } } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoMessagesActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoMessagesActivity.java index 0fedc8cf..310f9444 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoMessagesActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoMessagesActivity.java @@ -4,6 +4,7 @@ import android.os.Handler; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; +import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.ImageView; @@ -89,6 +90,7 @@ public void onBackPressed() { @Override public void onLoadMore(int page, int totalItemsCount) { + Log.i("TAG", "onLoadMore: " + page + " " + totalItemsCount); if (totalItemsCount < TOTAL_MESSAGES_COUNT) { loadMessages(); } From 351e23cee8819943f636206af54d9f4d12bd54eb Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 11 Jul 2018 14:52:45 +0300 Subject: [PATCH 52/96] v0.3.0 --- chatkit/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chatkit/build.gradle b/chatkit/build.gradle index 9b5ab0ed..0e785c17 100644 --- a/chatkit/build.gradle +++ b/chatkit/build.gradle @@ -8,7 +8,7 @@ android { defaultConfig { minSdkVersion 14 versionCode 1 - versionName "0.2.3" + versionName "0.3.0" consumerProguardFiles 'proguard.txt' } @@ -22,7 +22,7 @@ android { publish { groupId = 'com.github.stfalcon' artifactId = 'chatkit' - publishVersion = '0.2.3' + publishVersion = '0.3.0' 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' From 160dff9bba1077a0492a59d2e2285037ecb11eb7 Mon Sep 17 00:00:00 2001 From: Anton Bevza Date: Wed, 11 Jul 2018 15:01:48 +0300 Subject: [PATCH 53/96] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d4a56118..d4d31d5c 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ To implement all of the features above you can use the following components: Download via Gradle: ```gradle -compile 'com.github.stfalcon:chatkit:0.2.3' +compile 'com.github.stfalcon:chatkit:0.3.0' ``` or Maven: @@ -51,7 +51,7 @@ or Maven: com.github.stfalcon chatkit - 0.2.3 + 0.3.0 pom ``` From 0c3083a8cb5e18aa8175c98bc2f35a5dd690b4d2 Mon Sep 17 00:00:00 2001 From: Anton Bevza Date: Fri, 13 Jul 2018 10:21:09 +0300 Subject: [PATCH 54/96] Update CHANGELOG.md --- docs/CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 0c0bb994..78ae166c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,20 @@ +## Version 0.3.0 (2018/07/12) +* [Added Typing Listener to MessageInput](https://github.com/stfalcon-studio/ChatKit/blob/master/docs/COMPONENT_MESSAGE_INPUT.MD#typing-listener). Thanks to [toanpv](https://github.com/toanpv); +* Fixed artifacts with bubble background in message list; +* Added separate method MessagesListAdapter.clear(notifyDataSetChanged). Method MessagesListAdapter.clear() does notifyDataSetChanged by default. [#89](https://github.com/stfalcon-studio/ChatKit/issues/86); +* Fixed "The totalItemsCount parameter in OnLoadMore callback contains date header." [#86](https://github.com/stfalcon-studio/ChatKit/issues/86); +* Merged pull requests: + * Avoid Crash on empty list in addToEnd [#146](https://github.com/stfalcon-studio/ChatKit/pull/146); + * Fix link typo in docs [#134](https://github.com/stfalcon-studio/ChatKit/pull/134); + * Add nullable for getImageUrl() [#119](https://github.com/stfalcon-studio/ChatKit/pull/119); + * Made correction to DialogList documentation [#112](https://github.com/stfalcon-studio/ChatKit/pull/112); + * Allow moving Dialog item and get Dialog by id [#70](https://github.com/stfalcon-studio/ChatKit/pull/70); + * Allow the user to get the current position of a DIALOG [#32](https://github.com/stfalcon-studio/ChatKit/pull/32); + * Added upsert(Message) method to add or update message to adapter as appropriate [#61](https://github.com/stfalcon-studio/ChatKit/pull/61); + * Create LICENSE [#167](https://github.com/stfalcon-studio/ChatKit/pull/167); + * NPE check in DialofsListAdapter.java when there is no last message (is null) [#75](https://github.com/stfalcon-studio/ChatKit/pull/75); +* Sample: Fixed artifacts on some devices in ShapeImageView. Changed fixture message image. + ## Version 0.2.0 (2017/04/07) * [Default image type](COMPONENT_MESSAGES_LIST.md#adding-image-message); From 1c17fcc2e9ccf6ed7a3cd4c03f79d0c226b8adb9 Mon Sep 17 00:00:00 2001 From: Joost Funke Kupper Date: Fri, 3 Aug 2018 10:26:41 +1000 Subject: [PATCH 55/96] Removal of forced software layer rendering --- .../main/java/com/stfalcon/chatkit/messages/MessagesList.java | 4 ---- 1 file changed, 4 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 e68f0906..17b3f8ed 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesList.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesList.java @@ -23,7 +23,6 @@ import android.support.v7.widget.RecyclerView; import android.support.v7.widget.SimpleItemAnimator; import android.util.AttributeSet; -import android.view.View; import com.stfalcon.chatkit.commons.models.IMessage; @@ -35,19 +34,16 @@ public class MessagesList extends RecyclerView { public MessagesList(Context context) { super(context); - setLayerType(View.LAYER_TYPE_SOFTWARE, null); } public MessagesList(Context context, @Nullable AttributeSet attrs) { super(context, attrs); parseStyle(context, attrs); - setLayerType(View.LAYER_TYPE_SOFTWARE, null); } public MessagesList(Context context, @Nullable AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); parseStyle(context, attrs); - setLayerType(View.LAYER_TYPE_SOFTWARE, null); } /** From 123f9ac2aef8176f56cb74328cb8c3a2b5c467a0 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 16 Aug 2018 09:52:08 +0300 Subject: [PATCH 56/96] add ability to passing custom data to ViewHolder. Version 0.3.1 --- chatkit/build.gradle | 4 +- .../chatkit/messages/MessageHolders.java | 349 +++++++++++++++--- .../holder/CustomHolderMessagesActivity.java | 16 +- .../CustomIncomingTextMessageViewHolder.java | 23 +- 4 files changed, 345 insertions(+), 47 deletions(-) diff --git a/chatkit/build.gradle b/chatkit/build.gradle index 0e785c17..f970a58f 100644 --- a/chatkit/build.gradle +++ b/chatkit/build.gradle @@ -8,7 +8,7 @@ android { defaultConfig { minSdkVersion 14 versionCode 1 - versionName "0.3.0" + versionName "0.3.1" consumerProguardFiles 'proguard.txt' } @@ -22,7 +22,7 @@ android { publish { groupId = 'com.github.stfalcon' artifactId = 'chatkit' - publishVersion = '0.3.0' + publishVersion = '0.3.1' 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' 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 8f126cd3..0437b54b 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java @@ -73,6 +73,24 @@ public MessageHolders setIncomingTextConfig( return this; } + /** + * Sets both of custom view holder class and layout resource for incoming text message. + * + * @param holder holder class. + * @param layout layout resource. + * @param payload custom data. + * @return {@link MessageHolders} for subsequent configuration. + */ + public MessageHolders setIncomingTextConfig( + @NonNull Class> holder, + @LayoutRes int layout, + Object payload) { + this.incomingTextConfig.holder = holder; + this.incomingTextConfig.layout = layout; + this.incomingTextConfig.payload = payload; + return this; + } + /** * Sets custom view holder class for incoming text message. * @@ -85,6 +103,21 @@ public MessageHolders setIncomingTextHolder( return this; } + /** + * Sets custom view holder class for incoming text message. + * + * @param holder holder class. + * @param payload custom data. + * @return {@link MessageHolders} for subsequent configuration. + */ + public MessageHolders setIncomingTextHolder( + @NonNull Class> holder, + Object payload) { + this.incomingTextConfig.holder = holder; + this.incomingTextConfig.payload = payload; + return this; + } + /** * Sets custom layout resource for incoming text message. * @@ -96,6 +129,19 @@ public MessageHolders setIncomingTextLayout(@LayoutRes int layout) { return this; } + /** + * Sets custom layout resource for incoming text message. + * + * @param layout layout resource. + * @param payload custom data. + * @return {@link MessageHolders} for subsequent configuration. + */ + public MessageHolders setIncomingTextLayout(@LayoutRes int layout, Object payload) { + this.incomingTextConfig.layout = layout; + this.incomingTextConfig.payload = payload; + return this; + } + /** * Sets both of custom view holder class and layout resource for outcoming text message. * @@ -111,6 +157,24 @@ public MessageHolders setOutcomingTextConfig( return this; } + /** + * Sets both of custom view holder class and layout resource for outcoming text message. + * + * @param holder holder class. + * @param layout layout resource. + * @param payload custom data. + * @return {@link MessageHolders} for subsequent configuration. + */ + public MessageHolders setOutcomingTextConfig( + @NonNull Class> holder, + @LayoutRes int layout, + Object payload) { + this.outcomingTextConfig.holder = holder; + this.outcomingTextConfig.layout = layout; + this.outcomingTextConfig.payload = payload; + return this; + } + /** * Sets custom view holder class for outcoming text message. * @@ -123,6 +187,21 @@ public MessageHolders setOutcomingTextHolder( return this; } + /** + * Sets custom view holder class for outcoming text message. + * + * @param holder holder class. + * @param payload custom data. + * @return {@link MessageHolders} for subsequent configuration. + */ + public MessageHolders setOutcomingTextHolder( + @NonNull Class> holder, + Object payload) { + this.outcomingTextConfig.holder = holder; + this.outcomingTextConfig.payload = payload; + return this; + } + /** * Sets custom layout resource for outcoming text message. * @@ -134,6 +213,19 @@ public MessageHolders setOutcomingTextLayout(@LayoutRes int layout) { return this; } + /** + * Sets custom layout resource for outcoming text message. + * + * @param layout layout resource. + * @param payload custom data. + * @return {@link MessageHolders} for subsequent configuration. + */ + public MessageHolders setOutcomingTextLayout(@LayoutRes int layout, Object payload) { + this.outcomingTextConfig.layout = layout; + this.outcomingTextConfig.payload = payload; + return this; + } + /** * Sets both of custom view holder class and layout resource for incoming image message. * @@ -149,6 +241,24 @@ public MessageHolders setIncomingImageConfig( return this; } + /** + * Sets both of custom view holder class and layout resource for incoming image message. + * + * @param holder holder class. + * @param layout layout resource. + * @param payload custom data. + * @return {@link MessageHolders} for subsequent configuration. + */ + public MessageHolders setIncomingImageConfig( + @NonNull Class> holder, + @LayoutRes int layout, + Object payload) { + this.incomingImageConfig.holder = holder; + this.incomingImageConfig.layout = layout; + this.incomingImageConfig.payload = payload; + return this; + } + /** * Sets custom view holder class for incoming image message. * @@ -161,6 +271,21 @@ public MessageHolders setIncomingImageHolder( return this; } + /** + * Sets custom view holder class for incoming image message. + * + * @param holder holder class. + * @param payload custom data. + * @return {@link MessageHolders} for subsequent configuration. + */ + public MessageHolders setIncomingImageHolder( + @NonNull Class> holder, + Object payload) { + this.incomingImageConfig.holder = holder; + this.incomingImageConfig.payload = payload; + return this; + } + /** * Sets custom layout resource for incoming image message. * @@ -172,6 +297,19 @@ public MessageHolders setIncomingImageLayout(@LayoutRes int layout) { return this; } + /** + * Sets custom layout resource for incoming image message. + * + * @param layout layout resource. + * @param payload custom data. + * @return {@link MessageHolders} for subsequent configuration. + */ + public MessageHolders setIncomingImageLayout(@LayoutRes int layout, Object payload) { + this.incomingImageConfig.layout = layout; + this.incomingImageConfig.payload = payload; + return this; + } + /** * Sets both of custom view holder class and layout resource for outcoming image message. * @@ -187,6 +325,24 @@ public MessageHolders setOutcomingImageConfig( return this; } + /** + * Sets both of custom view holder class and layout resource for outcoming image message. + * + * @param holder holder class. + * @param layout layout resource. + * @param payload custom data. + * @return {@link MessageHolders} for subsequent configuration. + */ + public MessageHolders setOutcomingImageConfig( + @NonNull Class> holder, + @LayoutRes int layout, + Object payload) { + this.outcomingImageConfig.holder = holder; + this.outcomingImageConfig.layout = layout; + this.outcomingImageConfig.payload = payload; + return this; + } + /** * Sets custom view holder class for outcoming image message. * @@ -199,6 +355,21 @@ public MessageHolders setOutcomingImageHolder( return this; } + /** + * Sets custom view holder class for outcoming image message. + * + * @param holder holder class. + * @param payload custom data. + * @return {@link MessageHolders} for subsequent configuration. + */ + public MessageHolders setOutcomingImageHolder( + @NonNull Class> holder, + Object payload) { + this.outcomingImageConfig.holder = holder; + this.outcomingImageConfig.payload = payload; + return this; + } + /** * Sets custom layout resource for outcoming image message. * @@ -210,6 +381,19 @@ public MessageHolders setOutcomingImageLayout(@LayoutRes int layout) { return this; } + /** + * Sets custom layout resource for outcoming image message. + * + * @param layout layout resource. + * @param payload custom data. + * @return {@link MessageHolders} for subsequent configuration. + */ + public MessageHolders setOutcomingImageLayout(@LayoutRes int layout, Object payload) { + this.outcomingImageConfig.layout = layout; + this.outcomingImageConfig.payload = payload; + return this; + } + /** * Sets both of custom view holder class and layout resource for date header. * @@ -300,8 +484,8 @@ MessageHolders registerContentType( } /* - * INTERFACES - * */ + * INTERFACES + * */ /** * The interface, which contains logic for checking the availability of content. @@ -319,13 +503,13 @@ public interface ContentChecker { } /* - * PRIVATE METHODS - * */ + * PRIVATE METHODS + * */ protected ViewHolder getHolder(ViewGroup parent, int viewType, MessagesListStyle messagesListStyle) { switch (viewType) { case VIEW_TYPE_DATE_HEADER: - return getHolder(parent, dateHeaderLayout, dateHeaderHolder, messagesListStyle); + return getHolder(parent, dateHeaderLayout, dateHeaderHolder, messagesListStyle, null); case VIEW_TYPE_TEXT_MESSAGE: return getHolder(parent, incomingTextConfig, messagesListStyle); case -VIEW_TYPE_TEXT_MESSAGE: @@ -395,18 +579,28 @@ protected int getViewType(Object item, String senderId) { return isOutcoming ? viewType * -1 : viewType; } - private ViewHolder getHolder(ViewGroup parent, HolderConfig holderConfig, MessagesListStyle style) { - return getHolder(parent, holderConfig.layout, holderConfig.holder, style); + private ViewHolder getHolder(ViewGroup parent, HolderConfig holderConfig, + MessagesListStyle style) { + return getHolder(parent, holderConfig.layout, holderConfig.holder, style, holderConfig.payload); } private - ViewHolder getHolder(ViewGroup parent, @LayoutRes int layout, Class holderClass, MessagesListStyle style) { + ViewHolder getHolder(ViewGroup parent, @LayoutRes int layout, Class holderClass, + MessagesListStyle style, Object payload) { View v = LayoutInflater.from(parent.getContext()).inflate(layout, parent, false); try { - Constructor constructor = holderClass.getDeclaredConstructor(View.class); - constructor.setAccessible(true); - HOLDER holder = constructor.newInstance(v); + Constructor constructor = null; + HOLDER holder; + try { + constructor = holderClass.getDeclaredConstructor(View.class, Object.class); + constructor.setAccessible(true); + holder = constructor.newInstance(v, payload); + } catch (NoSuchMethodException e) { + constructor = holderClass.getDeclaredConstructor(View.class); + constructor.setAccessible(true); + holder = constructor.newInstance(v); + } if (holder instanceof DefaultMessageViewHolder && style != null) { ((DefaultMessageViewHolder) holder).applyStyle(style); } @@ -440,8 +634,8 @@ private short getContentViewType(IMessage message) { } /* - * HOLDERS - * */ + * HOLDERS + * */ /** * The base class for view holders for incoming and outcoming message. @@ -451,6 +645,11 @@ public static abstract class BaseMessageViewHolder ext boolean isSelected; + /** + * For setting custom data to ViewHolder + */ + protected Object payload; + /** * Callback for implementing images loading in message list */ @@ -460,6 +659,11 @@ public BaseMessageViewHolder(View itemView) { super(itemView); } + public BaseMessageViewHolder(View itemView, Object payload) { + this(itemView); + this.payload = payload; + } + /** * Returns whether is item selected * @@ -515,8 +719,12 @@ public static class IncomingTextMessageViewHolder public IncomingTextMessageViewHolder(View itemView) { super(itemView); - bubble = (ViewGroup) itemView.findViewById(R.id.bubble); - text = (TextView) itemView.findViewById(R.id.messageText); + init(itemView); + } + + public IncomingTextMessageViewHolder(View itemView, Object payload) { + super(itemView, payload); + init(itemView); } @Override @@ -551,6 +759,11 @@ public void applyStyle(MessagesListStyle style) { configureLinksBehavior(text); } } + + private void init(View itemView) { + bubble = (ViewGroup) itemView.findViewById(R.id.bubble); + text = (TextView) itemView.findViewById(R.id.messageText); + } } /** @@ -564,8 +777,12 @@ public static class OutcomingTextMessageViewHolder public OutcomingTextMessageViewHolder(View itemView) { super(itemView); - bubble = (ViewGroup) itemView.findViewById(R.id.bubble); - text = (TextView) itemView.findViewById(R.id.messageText); + init(itemView); + } + + public OutcomingTextMessageViewHolder(View itemView, Object payload) { + super(itemView, payload); + init(itemView); } @Override @@ -600,6 +817,11 @@ public final void applyStyle(MessagesListStyle style) { configureLinksBehavior(text); } } + + private void init(View itemView) { + bubble = (ViewGroup) itemView.findViewById(R.id.bubble); + text = (TextView) itemView.findViewById(R.id.messageText); + } } /** @@ -613,17 +835,12 @@ public static class IncomingImageMessageViewHolder { protected Class> holder; protected int layout; + protected Object payload; HolderConfig(Class> holder, int layout) { this.holder = holder; this.layout = layout; } + + HolderConfig(Class> holder, int layout, Object payload) { + this.holder = holder; + this.layout = layout; + this.payload = payload; + } } } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/CustomHolderMessagesActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/CustomHolderMessagesActivity.java index 6ec42903..835dcf21 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/CustomHolderMessagesActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/CustomHolderMessagesActivity.java @@ -3,6 +3,7 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.widget.Toast; import com.stfalcon.chatkit.messages.MessageHolders; import com.stfalcon.chatkit.messages.MessageInput; @@ -60,10 +61,23 @@ public void onMessageLongClick(Message message) { } private void initAdapter() { + + //We can pass any data to ViewHolder with payload + CustomIncomingTextMessageViewHolder.Payload payload = new CustomIncomingTextMessageViewHolder.Payload(); + //For example click listener + payload.avatarClickListener = new CustomIncomingTextMessageViewHolder.OnAvatarClickListener() { + @Override + public void onAvatarClick() { + Toast.makeText(CustomHolderMessagesActivity.this, + "Text message avatar clicked", Toast.LENGTH_SHORT).show(); + } + }; + MessageHolders holdersConfig = new MessageHolders() .setIncomingTextConfig( CustomIncomingTextMessageViewHolder.class, - R.layout.item_custom_incoming_text_message) + R.layout.item_custom_incoming_text_message, + payload) .setOutcomingTextConfig( CustomOutcomingTextMessageViewHolder.class, R.layout.item_custom_outcoming_text_message) 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 c4df3e95..a846a840 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 @@ -11,8 +11,8 @@ public class CustomIncomingTextMessageViewHolder private View onlineIndicator; - public CustomIncomingTextMessageViewHolder(View itemView) { - super(itemView); + public CustomIncomingTextMessageViewHolder(View itemView, Object payload) { + super(itemView, payload); onlineIndicator = itemView.findViewById(R.id.onlineIndicator); } @@ -26,5 +26,24 @@ public void onBind(Message message) { } else { onlineIndicator.setBackgroundResource(R.drawable.shape_bubble_offline); } + + //We can set click listener on view from payload + final Payload payload = (Payload) this.payload; + userAvatar.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (payload != null && payload.avatarClickListener != null) { + payload.avatarClickListener.onAvatarClick(); + } + } + }); + } + + public static class Payload { + public OnAvatarClickListener avatarClickListener; + } + + public interface OnAvatarClickListener { + void onAvatarClick(); } } From 36e4cc97f43ee561799a05c0f2d42e2bc49acc92 Mon Sep 17 00:00:00 2001 From: Anton Bevza Date: Thu, 16 Aug 2018 10:38:30 +0300 Subject: [PATCH 57/96] Update documentation --- docs/COMPONENT_MESSAGES_LIST.md | 56 +++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/docs/COMPONENT_MESSAGES_LIST.md b/docs/COMPONENT_MESSAGES_LIST.md index 38a4453e..d424767f 100644 --- a/docs/COMPONENT_MESSAGES_LIST.md +++ b/docs/COMPONENT_MESSAGES_LIST.md @@ -321,8 +321,8 @@ For example, you can add status for outgoing messages with only few lines: public class CustomOutcomingMessageViewHolder extends MessagesListAdapter.OutcomingMessageViewHolder { - public CustomOutcomingMessageViewHolder(View itemView) { - super(itemView); + public CustomOutcomingMessageViewHolder(View itemView, Object payload) { + super(itemView, payload); } @Override @@ -338,6 +338,58 @@ public class CustomOutcomingMessageViewHolder
Pay attention to outgoing message’ status and online indicator.

+#### Passing custom data to your ViewHolder +You can pass any data to your custom ViewHolder. To do this, firstly you need override the constructor `super(View itemView, Object payload)` (the constructor `super(View itemView)` is deprecated and will be deleted in one of the new version of library). After that you can pass data as third parameter in method `MessageHolders().setXXXConfig`. +For example, let's add click listener in incoming text message on avatar click. +Create interface for click callback and payload class to store it: +```java +public interface OnAvatarClickListener { + void onAvatarClick(); +} + +public class Payload { + public OnAvatarClickListener avatarClickListener; +} +``` +Then in our custom ViewHolder in method `onBind`: +```java +@Override + public void onBind(Message message) { + super.onBind(message); + ... + //We can set click listener on view from payload + final Payload payload = (Payload) this.payload; + userAvatar.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (payload != null && payload.avatarClickListener != null) { + payload.avatarClickListener.onAvatarClick(); + } + } + }); + } +``` +Then create Payload and set it and our ViewHolder class to MessageHolders config. +``` +//We can pass any data to ViewHolder with payload +CustomIncomingTextMessageViewHolder.Payload payload = new CustomIncomingTextMessageViewHolder.Payload(); +//For example click listener +payload.avatarClickListener = new CustomIncomingTextMessageViewHolder.OnAvatarClickListener() { + @Override + public void onAvatarClick() { + Toast.makeText(CustomHolderMessagesActivity.this, + "Text message avatar clicked", Toast.LENGTH_SHORT).show(); + } +}; + +MessageHolders holdersConfig = new MessageHolders() + .setIncomingTextConfig( + CustomIncomingTextMessageViewHolder.class, + R.layout.item_custom_incoming_text_message, + payload) + ... +``` + #### Custom content types We understand that ony images as media messages are often not enough. Therefore, we implemented the ability to add custom content types for displaying different types of content (geopoints, video, voice messages etc.). From 5d213ca8746a5041712be9694712d18b094ab480 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 16 Aug 2018 11:01:10 +0300 Subject: [PATCH 58/96] set deprecated ViewHolder constructor. Update sample. --- .../chatkit/messages/MessageHolders.java | 17 ++++++++++++----- .../CustomIncomingImageMessageViewHolder.java | 4 ++-- .../CustomOutcomingImageMessageViewHolder.java | 4 ++-- .../CustomOutcomingTextMessageViewHolder.java | 4 ++-- .../holders/IncomingVoiceMessageViewHolder.java | 4 ++-- .../OutcomingVoiceMessageViewHolder.java | 4 ++-- 6 files changed, 22 insertions(+), 15 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 0437b54b..4fce59d3 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java @@ -655,12 +655,13 @@ public static abstract class BaseMessageViewHolder ext */ protected ImageLoader imageLoader; + @Deprecated public BaseMessageViewHolder(View itemView) { super(itemView); } public BaseMessageViewHolder(View itemView, Object payload) { - this(itemView); + super(itemView); this.payload = payload; } @@ -717,6 +718,7 @@ public static class IncomingTextMessageViewHolder protected ViewGroup bubble; protected TextView text; + @Deprecated public IncomingTextMessageViewHolder(View itemView) { super(itemView); init(itemView); @@ -775,6 +777,7 @@ public static class OutcomingTextMessageViewHolder protected ViewGroup bubble; protected TextView text; + @Deprecated public OutcomingTextMessageViewHolder(View itemView) { super(itemView); init(itemView); @@ -833,6 +836,7 @@ public static class IncomingImageMessageViewHolder { public DefaultIncomingTextMessageViewHolder(View itemView) { - super(itemView); + super(itemView, null); } } @@ -1099,7 +1106,7 @@ private static class DefaultOutcomingTextMessageViewHolder extends OutcomingTextMessageViewHolder { public DefaultOutcomingTextMessageViewHolder(View itemView) { - super(itemView); + super(itemView, null); } } @@ -1107,7 +1114,7 @@ private static class DefaultIncomingImageMessageViewHolder extends IncomingImageMessageViewHolder { public DefaultIncomingImageMessageViewHolder(View itemView) { - super(itemView); + super(itemView, null); } } @@ -1115,7 +1122,7 @@ private static class DefaultOutcomingImageMessageViewHolder extends OutcomingImageMessageViewHolder { public DefaultOutcomingImageMessageViewHolder(View itemView) { - super(itemView); + super(itemView, null); } } 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 47e9282a..124b4cc4 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 @@ -14,8 +14,8 @@ public class CustomIncomingImageMessageViewHolder private View onlineIndicator; - public CustomIncomingImageMessageViewHolder(View itemView) { - super(itemView); + public CustomIncomingImageMessageViewHolder(View itemView, Object payload) { + super(itemView, payload); onlineIndicator = itemView.findViewById(R.id.onlineIndicator); } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomOutcomingImageMessageViewHolder.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomOutcomingImageMessageViewHolder.java index 36a22359..9b520b85 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomOutcomingImageMessageViewHolder.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomOutcomingImageMessageViewHolder.java @@ -11,8 +11,8 @@ public class CustomOutcomingImageMessageViewHolder extends MessageHolders.OutcomingImageMessageViewHolder { - public CustomOutcomingImageMessageViewHolder(View itemView) { - super(itemView); + public CustomOutcomingImageMessageViewHolder(View itemView, Object payload) { + super(itemView, payload); } @Override diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomOutcomingTextMessageViewHolder.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomOutcomingTextMessageViewHolder.java index 81c319d2..aa3a445b 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomOutcomingTextMessageViewHolder.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomOutcomingTextMessageViewHolder.java @@ -8,8 +8,8 @@ public class CustomOutcomingTextMessageViewHolder extends MessageHolders.OutcomingTextMessageViewHolder { - public CustomOutcomingTextMessageViewHolder(View itemView) { - super(itemView); + public CustomOutcomingTextMessageViewHolder(View itemView, Object payload) { + super(itemView, payload); } @Override diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/holders/IncomingVoiceMessageViewHolder.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/holders/IncomingVoiceMessageViewHolder.java index c87e395f..80c64b5b 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/holders/IncomingVoiceMessageViewHolder.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/holders/IncomingVoiceMessageViewHolder.java @@ -18,8 +18,8 @@ public class IncomingVoiceMessageViewHolder private TextView tvDuration; private TextView tvTime; - public IncomingVoiceMessageViewHolder(View itemView) { - super(itemView); + public IncomingVoiceMessageViewHolder(View itemView, Object payload) { + super(itemView, payload); tvDuration = (TextView) itemView.findViewById(R.id.duration); tvTime = (TextView) itemView.findViewById(R.id.time); } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/holders/OutcomingVoiceMessageViewHolder.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/holders/OutcomingVoiceMessageViewHolder.java index 556e1fcf..6d3dcbf8 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/holders/OutcomingVoiceMessageViewHolder.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/holders/OutcomingVoiceMessageViewHolder.java @@ -18,8 +18,8 @@ public class OutcomingVoiceMessageViewHolder private TextView tvDuration; private TextView tvTime; - public OutcomingVoiceMessageViewHolder(View itemView) { - super(itemView); + public OutcomingVoiceMessageViewHolder(View itemView, Object payload) { + super(itemView, payload); tvDuration = (TextView) itemView.findViewById(R.id.duration); tvTime = (TextView) itemView.findViewById(R.id.time); } From 4a810bbd6d3d5834c3e19f8b3147ff6da364e390 Mon Sep 17 00:00:00 2001 From: Anton Bevza Date: Thu, 16 Aug 2018 15:18:10 +0300 Subject: [PATCH 59/96] Update README.md --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index d4d31d5c..48f10f47 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,27 @@ or Maven: ``` +### Proguard +If you are using ProGuard you might need to add rules: +``` +-keep class * extends com.stfalcon.chatkit.messages.MessageHolders$OutcomingTextMessageViewHolder { + public (android.view.View, java.lang.Object); + public (android.view.View); + } +-keep class * extends com.stfalcon.chatkit.messages.MessageHolders$IncomingTextMessageViewHolder { + public (android.view.View, java.lang.Object); + public (android.view.View); + } +-keep class * extends com.stfalcon.chatkit.messages.MessageHolders$IncomingImageMessageViewHolder { + public (android.view.View, java.lang.Object); + public (android.view.View); + } +-keep class * extends com.stfalcon.chatkit.messages.MessageHolders$OutcomingImageMessageViewHolder { + public (android.view.View, java.lang.Object); + public (android.view.View); + } +``` + ### Try it Check out the [sample project](/sample/src/main) to try it yourself! :wink: From 769eb0d8e9fd190cb633dac8540d1a35d3ba5190 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 16 Aug 2018 15:23:28 +0300 Subject: [PATCH 60/96] add proguard rules --- sample/build.gradle | 2 +- sample/proguard-rules.pro | 101 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) diff --git a/sample/build.gradle b/sample/build.gradle index dbed4d4e..fa1fced7 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -12,7 +12,7 @@ android { } buildTypes { release { - minifyEnabled false + minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } diff --git a/sample/proguard-rules.pro b/sample/proguard-rules.pro index 7e694d20..50d21ef8 100644 --- a/sample/proguard-rules.pro +++ b/sample/proguard-rules.pro @@ -15,3 +15,104 @@ #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} +# JSR 305 annotations are for embedding nullability information. +-dontwarn javax.annotation.** + +# A resource is loaded with a relative path so the package of this class must be preserved. +-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase + +# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java. +-dontwarn org.codehaus.mojo.animal_sniffer.* + +# OkHttp platform used only on JVM and when Conscrypt dependency is available. +-dontwarn okhttp3.internal.platform.ConscryptPlatform + + +-dontwarn okio.** +-dontwarn com.squareup.okhttp.** +-dontwarn okhttp3.** +-dontwarn javax.annotation.** +-dontwarn com.android.volley.toolbox.** +-dontwarn com.facebook.infer.** + +-keep public class * extends android.app.Activity +-keep public class * extends android.app.Application +-keep public class * extends android.app.Service +-keep public class * extends android.content.BroadcastReceiver +-keep public class * extends android.content.ContentProvider +-keep public class * extends android.app.backup.BackupAgent +-keep public class * extends android.preference.Preference +-keep public class * extends android.support.v4.app.Fragment +-keep public class * extends android.support.v4.app.DialogFragment +-keep public class * extends com.actionbarsherlock.app.SherlockListFragment +-keep public class * extends com.actionbarsherlock.app.SherlockFragment +-keep public class * extends com.actionbarsherlock.app.SherlockFragmentActivity +-keep public class * extends android.app.Fragment +-keep public class com.android.vending.licensing.ILicensingService + +# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native +-keepclasseswithmembernames class * { + native ; +} + +-keep public class * extends android.view.View { + public (android.content.Context); + public (android.content.Context, android.util.AttributeSet); + public (android.content.Context, android.util.AttributeSet, int); + public void set*(...); +} + +-keepclasseswithmembers class * { + public (android.content.Context, android.util.AttributeSet); +} + +-keepclasseswithmembers class * { + public (android.content.Context, android.util.AttributeSet, int); +} + +-keepclassmembers class * extends android.app.Activity { + public void *(android.view.View); +} + +# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +-keep class * implements android.os.Parcelable { + public static final android.os.Parcelable$Creator *; +} + +-keepclassmembers class **.R$* { + public static ; +} +-keep class android.support.v7.internal.** { *; } +-keep interface android.support.v7.internal.** { *; } +-keep class android.support.v7.** { *; } +-keep interface android.support.v7.** { *; } +# The support library contains references to newer platform versions. +# Don't warn about those in case this app is linking against an older +# platform version. We know about them, and they are safe. +-dontwarn android.support.** + + + +#FOR CHATKIT + +-keep class * extends com.stfalcon.chatkit.messages.MessageHolders$OutcomingTextMessageViewHolder { + public (android.view.View, java.lang.Object); + public (android.view.View); + } +-keep class * extends com.stfalcon.chatkit.messages.MessageHolders$IncomingTextMessageViewHolder { + public (android.view.View, java.lang.Object); + public (android.view.View); + } +-keep class * extends com.stfalcon.chatkit.messages.MessageHolders$IncomingImageMessageViewHolder { + public (android.view.View, java.lang.Object); + public (android.view.View); + } +-keep class * extends com.stfalcon.chatkit.messages.MessageHolders$OutcomingImageMessageViewHolder { + public (android.view.View, java.lang.Object); + public (android.view.View); + } From 37b1695788b18ccee08a12b629b4927afb97581d Mon Sep 17 00:00:00 2001 From: Anton Bevza Date: Thu, 16 Aug 2018 16:04:09 +0300 Subject: [PATCH 61/96] Update CHANGELOG.md --- docs/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 78ae166c..15c85c0c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,8 @@ +## Version 0.3.1 (2018/08/16) +* [Passing custom data to your ViewHolder](https://github.com/stfalcon-studio/ChatKit/blob/master/docs/COMPONENT_MESSAGES_LIST.md#passing-custom-data-to-your-viewholder) [#180](https://github.com/stfalcon-studio/ChatKit/issues/180) +* Added Proguard rules to [Readme](https://github.com/stfalcon-studio/ChatKit#proguard) and [sample project](https://github.com/stfalcon-studio/ChatKit/blob/master/sample/proguard-rules.pro). [#122](https://github.com/stfalcon-studio/ChatKit/issues/122) +* Fixed [#174](https://github.com/stfalcon-studio/ChatKit/issues/174) + ## Version 0.3.0 (2018/07/12) * [Added Typing Listener to MessageInput](https://github.com/stfalcon-studio/ChatKit/blob/master/docs/COMPONENT_MESSAGE_INPUT.MD#typing-listener). Thanks to [toanpv](https://github.com/toanpv); * Fixed artifacts with bubble background in message list; From 067b6a05ceb626122f211685f52e9f9aa414688b Mon Sep 17 00:00:00 2001 From: Anton Bevza Date: Thu, 16 Aug 2018 17:16:23 +0300 Subject: [PATCH 62/96] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 48f10f47..a0736751 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ To implement all of the features above you can use the following components: Download via Gradle: ```gradle -compile 'com.github.stfalcon:chatkit:0.3.0' +compile 'com.github.stfalcon:chatkit:0.3.1' ``` or Maven: @@ -51,7 +51,7 @@ or Maven: com.github.stfalcon chatkit - 0.3.0 + 0.3.1 pom ``` From e0ee1eb126857e772ad6df27ee84a17f57df099c Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 16 Aug 2018 17:34:05 +0300 Subject: [PATCH 63/96] fix in proguard rules --- sample/build.gradle | 2 +- sample/proguard-rules.pro | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/sample/build.gradle b/sample/build.gradle index fa1fced7..dbed4d4e 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -12,7 +12,7 @@ android { } buildTypes { release { - minifyEnabled true + minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } diff --git a/sample/proguard-rules.pro b/sample/proguard-rules.pro index 50d21ef8..2995e8d9 100644 --- a/sample/proguard-rules.pro +++ b/sample/proguard-rules.pro @@ -32,8 +32,6 @@ -dontwarn com.squareup.okhttp.** -dontwarn okhttp3.** -dontwarn javax.annotation.** --dontwarn com.android.volley.toolbox.** --dontwarn com.facebook.infer.** -keep public class * extends android.app.Activity -keep public class * extends android.app.Application @@ -44,9 +42,6 @@ -keep public class * extends android.preference.Preference -keep public class * extends android.support.v4.app.Fragment -keep public class * extends android.support.v4.app.DialogFragment --keep public class * extends com.actionbarsherlock.app.SherlockListFragment --keep public class * extends com.actionbarsherlock.app.SherlockFragment --keep public class * extends com.actionbarsherlock.app.SherlockFragmentActivity -keep public class * extends android.app.Fragment -keep public class com.android.vending.licensing.ILicensingService From 5b58ff4671a5e32bb24ec5259df2659934cee542 Mon Sep 17 00:00:00 2001 From: Matthew Weathers Date: Mon, 20 Aug 2018 10:39:36 -0500 Subject: [PATCH 64/96] Enable payloads for custom content types --- .../chatkit/messages/MessageHolders.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) 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 4fce59d3..71b99839 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java @@ -483,6 +483,37 @@ MessageHolders registerContentType( return this; } + /** + * Registers custom content type (e.g. multimedia, events etc.) + * + * @param type unique id for content type + * @param incomingHolder holder class for incoming message + * @param outcomingHolder holder class for outcoming message + * @param incomingPayload payload for incoming message + * @param outcomingPayload payload for outcoming message + * @param incomingLayout layout resource for incoming message + * @param outcomingLayout layout resource for outcoming message + * @param contentChecker {@link MessageHolders.ContentChecker} for registered type + * @return {@link MessageHolders} for subsequent configuration. + */ + public + MessageHolders registerContentType( + byte type, + @NonNull Class> incomingHolder, Object incomingPayload, @LayoutRes int incomingLayout, + @NonNull Class> outcomingHolder, Object outcomingPayload, @LayoutRes int outcomingLayout, + @NonNull MessageHolders.ContentChecker contentChecker) { + + if (type == 0) + throw new IllegalArgumentException("content type must be greater or less than '0'!"); + + customContentTypes.add( + new MessageHolders.ContentTypeConfig<>(type, + new MessageHolders.HolderConfig<>(incomingHolder, incomingLayout, incomingPayload), + new MessageHolders.HolderConfig<>(outcomingHolder, outcomingLayout, outcomingPayload))); + this.contentChecker = contentChecker; + return this; + } + /* * INTERFACES * */ From b22214a045a10bbe651b14eafa7c35e3aa991e6b Mon Sep 17 00:00:00 2001 From: Mathieu Rul Date: Tue, 28 Aug 2018 10:12:54 +0200 Subject: [PATCH 65/96] Clear last message if null in dialog list (Fix issue #189) --- .../com/stfalcon/chatkit/dialogs/DialogsListAdapter.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 eaa8b47f..721813e5 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -631,6 +631,8 @@ public void onBind(final DIALOG dialog) { tvDate.setText(formattedDate == null ? getDateString(lastMessageDate) : formattedDate); + } else { + tvDate.setText(null); } //Set Dialog avatar @@ -643,11 +645,14 @@ public void onBind(final DIALOG dialog) { imageLoader.loadImage(ivLastMessageUser, dialog.getLastMessage().getUser().getAvatar()); } ivLastMessageUser.setVisibility(dialogStyle.isDialogMessageAvatarEnabled() - && dialog.getUsers().size() > 1 ? VISIBLE : GONE); + && dialog.getUsers().size() > 1 + && dialog.getLastMessage() != null ? VISIBLE : GONE); //Set Last message text if (dialog.getLastMessage() != null) { tvLastMessage.setText(dialog.getLastMessage().getText()); + } else { + tvLastMessage.setText(null); } //Set Unread message count bubble From 22545932c710e06e089e01fe8a9d526c4abbfd36 Mon Sep 17 00:00:00 2001 From: Mathieu Rul Date: Tue, 28 Aug 2018 10:18:40 +0200 Subject: [PATCH 66/96] Add upsert method to dialogs list --- .../chatkit/dialogs/DialogsListAdapter.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 eaa8b47f..2ebdbfa7 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -257,6 +257,26 @@ public void updateItemById(DIALOG item) { } } + /** + * Upsert dialog in dialogs list or add it to then end of dialogs list + * + * @param item dialog item + */ + public void upsertItem(DIALOG item) { + boolean updated = false; + for (int i = 0; i < items.size(); i++) { + if (items.get(i).getId().equals(item.getId())) { + items.set(i, item); + notifyItemChanged(i); + updated = true; + break; + } + } + if (!updated) { + addItem(item); + } + } + /** * Find an item by its id * From b4a84be7228a09780ae9f8ec8dd1ddff8f8b31c9 Mon Sep 17 00:00:00 2001 From: Anton Date: Tue, 25 Sep 2018 14:28:05 +0300 Subject: [PATCH 67/96] ver 0.3.2 --- chatkit/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chatkit/build.gradle b/chatkit/build.gradle index f970a58f..9889ae13 100644 --- a/chatkit/build.gradle +++ b/chatkit/build.gradle @@ -8,7 +8,7 @@ android { defaultConfig { minSdkVersion 14 versionCode 1 - versionName "0.3.1" + versionName "0.3.2" consumerProguardFiles 'proguard.txt' } @@ -22,7 +22,7 @@ android { publish { groupId = 'com.github.stfalcon' artifactId = 'chatkit' - publishVersion = '0.3.1' + publishVersion = '0.3.2' 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' From dcd0eb091bbc5d407f4c3f48e33dadcd7f2b082d Mon Sep 17 00:00:00 2001 From: Anton Date: Tue, 25 Sep 2018 14:29:20 +0300 Subject: [PATCH 68/96] fix addItem method in DialogListAdapter --- .../java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 eaa8b47f..dc6eac52 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -200,7 +200,7 @@ public void addItems(List newItems) { */ public void addItem(DIALOG dialog) { items.add(dialog); - notifyItemInserted(0); + notifyItemInserted(items.size() - 1); } /** @@ -421,7 +421,7 @@ public void setDatesFormatter(DateFormatter.Formatter datesFormatter) { void setStyle(DialogListStyle dialogStyle) { this.dialogStyle = dialogStyle; } - + /** * @return the position of a dialog in the dialogs list. */ From 719b67a97b641ef48058791e66bf5355e52f0a74 Mon Sep 17 00:00:00 2001 From: Anton Date: Tue, 25 Sep 2018 14:42:16 +0300 Subject: [PATCH 69/96] make protected items field in MessagesListAdapter and DialogsListAdapter --- .../java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java | 2 +- .../java/com/stfalcon/chatkit/messages/MessagesListAdapter.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 31dcea53..871156cc 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -52,7 +52,7 @@ public class DialogsListAdapter extends RecyclerView.Adapter { - private List items = new ArrayList<>(); + protected List items = new ArrayList<>(); private int itemLayoutId; private Class holderClass; private ImageLoader imageLoader; 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 cbc403d2..caef45b8 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -51,9 +51,9 @@ public class MessagesListAdapter protected static boolean isSelectionModeEnabled; + protected List items; private MessageHolders holders; private String senderId; - private List items; private int selectedItemsCount; private SelectionListener selectionListener; From 3a754d7c3d16976e2c43d806538356f49109cf6e Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 26 Sep 2018 11:50:10 +0300 Subject: [PATCH 70/96] fix delete and deleteByIds methods in MessagesListAdapter --- .../chatkit/messages/MessagesListAdapter.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) 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 caef45b8..acc105f9 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -239,12 +239,18 @@ public void delete(MESSAGE message) { * @param messages messages list to delete. */ public void delete(List messages) { + boolean result = false; for (MESSAGE message : messages) { int index = getMessagePositionById(message.getId()); - items.remove(index); - notifyItemRemoved(index); + if (index >= 0) { + items.remove(index); + notifyItemRemoved(index); + result = true; + } + } + if (result) { + recountDateHeaders(); } - recountDateHeaders(); } /** @@ -267,12 +273,18 @@ public void deleteById(String id) { * @param ids array of identifiers of messages to delete. */ public void deleteByIds(String[] ids) { + boolean result = false; for (String id : ids) { int index = getMessagePositionById(id); - items.remove(index); - notifyItemRemoved(index); + if (index >= 0) { + items.remove(index); + notifyItemRemoved(index); + result = true; + } + } + if (result) { + recountDateHeaders(); } - recountDateHeaders(); } /** From 3a10017c089ae5ebe14c7225ac98f0eb9dfcc599 Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 28 Sep 2018 16:56:00 +0300 Subject: [PATCH 71/96] ability to pass custom data in ImageLoader --- .../stfalcon/chatkit/commons/ImageLoader.java | 3 ++- .../chatkit/dialogs/DialogsListAdapter.java | 4 ++-- .../chatkit/messages/MessageHolders.java | 24 ++++++++++++++----- .../features/demo/DemoDialogsActivity.java | 2 +- .../features/demo/DemoMessagesActivity.java | 2 +- ...CustomOutcomingImageMessageViewHolder.java | 6 +++++ .../demo/def/DefaultDialogsActivity.java | 4 ---- 7 files changed, 30 insertions(+), 15 deletions(-) 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 4d795854..a0f7f44f 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/commons/ImageLoader.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/commons/ImageLoader.java @@ -16,6 +16,7 @@ package com.stfalcon.chatkit.commons; +import android.support.annotation.Nullable; import android.widget.ImageView; /** @@ -23,6 +24,6 @@ */ public interface ImageLoader { - void loadImage(ImageView imageView, String url); + void loadImage(ImageView imageView, @Nullable String url, @Nullable Object payload); } 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 871156cc..dc48e7f0 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -657,12 +657,12 @@ public void onBind(final DIALOG dialog) { //Set Dialog avatar if (imageLoader != null) { - imageLoader.loadImage(ivAvatar, dialog.getDialogPhoto()); + imageLoader.loadImage(ivAvatar, dialog.getDialogPhoto(), null); } //Set Last message user avatar with check if there is last message if (imageLoader != null && dialog.getLastMessage() != null) { - imageLoader.loadImage(ivLastMessageUser, dialog.getLastMessage().getUser().getAvatar()); + imageLoader.loadImage(ivLastMessageUser, dialog.getLastMessage().getUser().getAvatar(), null); } ivLastMessageUser.setVisibility(dialogStyle.isDialogMessageAvatarEnabled() && dialog.getUsers().size() > 1 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 4fce59d3..cce15838 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java @@ -706,7 +706,6 @@ public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event } }); } - } /** @@ -851,7 +850,7 @@ public IncomingImageMessageViewHolder(View itemView, Object payload) { public void onBind(MESSAGE message) { super.onBind(message); if (image != null && imageLoader != null) { - imageLoader.loadImage(image, message.getImageUrl()); + loadImage(message); } if (imageOverlay != null) { @@ -873,11 +872,15 @@ public final void applyStyle(MessagesListStyle style) { } } + protected void loadImage(MESSAGE message) { + imageLoader.loadImage(image, message.getImageUrl(), null); + } + private void init(View itemView) { image = (ImageView) itemView.findViewById(R.id.image); imageOverlay = itemView.findViewById(R.id.imageOverlay); - if (image != null && image instanceof RoundedImageView) { + if (image instanceof RoundedImageView) { ((RoundedImageView) image).setCorners( R.dimen.message_bubble_corners_radius, R.dimen.message_bubble_corners_radius, @@ -912,7 +915,7 @@ public OutcomingImageMessageViewHolder(View itemView, Object payload) { public void onBind(MESSAGE message) { super.onBind(message); if (image != null && imageLoader != null) { - imageLoader.loadImage(image, message.getImageUrl()); + loadImage(message); } if (imageOverlay != null) { @@ -934,11 +937,20 @@ public final void applyStyle(MessagesListStyle style) { } } + /** + * Calls Imageloader for loading image. + * Override this method to have ability to pass custom data in ImageLoader. + * @param message Message with image + */ + protected void loadImage(MESSAGE message) { + imageLoader.loadImage(image, message.getImageUrl(), null); + } + private void init(View itemView) { image = (ImageView) itemView.findViewById(R.id.image); imageOverlay = itemView.findViewById(R.id.imageOverlay); - if (image != null && image instanceof RoundedImageView) { + if (image instanceof RoundedImageView) { ((RoundedImageView) image).setCorners( R.dimen.message_bubble_corners_radius, R.dimen.message_bubble_corners_radius, @@ -1020,7 +1032,7 @@ public void onBind(MESSAGE message) { userAvatar.setVisibility(isAvatarExists ? View.VISIBLE : View.GONE); if (isAvatarExists) { - imageLoader.loadImage(userAvatar, message.getUser().getAvatar()); + imageLoader.loadImage(userAvatar, message.getUser().getAvatar(), null); } } } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoDialogsActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoDialogsActivity.java index f2848ba8..770db5e5 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoDialogsActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoDialogsActivity.java @@ -27,7 +27,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { imageLoader = new ImageLoader() { @Override - public void loadImage(ImageView imageView, String url) { + public void loadImage(ImageView imageView, String url, Object payload) { Picasso.with(DemoDialogsActivity.this).load(url).into(imageView); } }; diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoMessagesActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoMessagesActivity.java index 310f9444..b58867cb 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoMessagesActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoMessagesActivity.java @@ -45,7 +45,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { imageLoader = new ImageLoader() { @Override - public void loadImage(ImageView imageView, String url) { + public void loadImage(ImageView imageView, String url, Object payload) { Picasso.with(DemoMessagesActivity.this).load(url).into(imageView); } }; diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomOutcomingImageMessageViewHolder.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomOutcomingImageMessageViewHolder.java index 9b520b85..b8f00b16 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomOutcomingImageMessageViewHolder.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomOutcomingImageMessageViewHolder.java @@ -21,4 +21,10 @@ public void onBind(Message message) { time.setText(message.getStatus() + " " + time.getText()); } + + //Override this method to pass custom data in ImageLoader. + @Override + protected void loadImage(Message message) { + imageLoader.loadImage(image, message.getImageUrl(), null); + } } \ No newline at end of file diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultDialogsActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultDialogsActivity.java index b9cf7444..59c9cb4c 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultDialogsActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultDialogsActivity.java @@ -12,12 +12,8 @@ import com.stfalcon.chatkit.sample.common.data.model.Message; import com.stfalcon.chatkit.sample.features.demo.DemoDialogsActivity; -import java.util.ArrayList; - public class DefaultDialogsActivity extends DemoDialogsActivity { - private ArrayList dialogs; - public static void open(Context context) { context.startActivity(new Intent(context, DefaultDialogsActivity.class)); } From 6b3ad7667bad0f94de64f6d3fc826c36fe53595f Mon Sep 17 00:00:00 2001 From: Mathieu Rul Date: Sun, 30 Sep 2018 22:11:15 +0200 Subject: [PATCH 72/96] Update documentation to add upsertItem method --- docs/COMPONENT_DIALOGS_LIST.MD | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/COMPONENT_DIALOGS_LIST.MD b/docs/COMPONENT_DIALOGS_LIST.MD index 61bea52d..e219fc1a 100644 --- a/docs/COMPONENT_DIALOGS_LIST.MD +++ b/docs/COMPONENT_DIALOGS_LIST.MD @@ -115,6 +115,7 @@ When your models are ready to be used by adapter, you can simply add them to the * adapter.addItems(List items) - adds a new dialog list to the end of the list; * adapter.addItem(DIALOG dialog) - adds one dialog to the end of the list * adapter.addItem(int position, DIALOG dialog) - adds a new dialog to the specified position. +* adapter.upsertItem(DIALOG dialog) - adds one dialog to the end of the list if not exists, otherwise updates the existing dialog. #### Updating dialogs If dialog has changed, you can update it by position in list by calling `adapter.updateItem(int position, DIALOG item)` or update it by dialog id by calling `adapter.updateItemById(DIALOG item)` From 356104252989ae967da6c4d8e96c0daf40dac550 Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 1 Oct 2018 16:22:47 +0300 Subject: [PATCH 73/96] ability to pass custom data in ImageLoader --- .../chatkit/messages/MessageHolders.java | 35 +++++++++++-------- ...CustomOutcomingImageMessageViewHolder.java | 8 +++-- 2 files changed, 25 insertions(+), 18 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 09f644c5..c089cbdf 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java @@ -486,14 +486,14 @@ MessageHolders registerContentType( /** * Registers custom content type (e.g. multimedia, events etc.) * - * @param type unique id for content type - * @param incomingHolder holder class for incoming message - * @param outcomingHolder holder class for outcoming message - * @param incomingPayload payload for incoming message + * @param type unique id for content type + * @param incomingHolder holder class for incoming message + * @param outcomingHolder holder class for outcoming message + * @param incomingPayload payload for incoming message * @param outcomingPayload payload for outcoming message - * @param incomingLayout layout resource for incoming message - * @param outcomingLayout layout resource for outcoming message - * @param contentChecker {@link MessageHolders.ContentChecker} for registered type + * @param incomingLayout layout resource for incoming message + * @param outcomingLayout layout resource for outcoming message + * @param contentChecker {@link MessageHolders.ContentChecker} for registered type * @return {@link MessageHolders} for subsequent configuration. */ public @@ -881,7 +881,7 @@ public IncomingImageMessageViewHolder(View itemView, Object payload) { public void onBind(MESSAGE message) { super.onBind(message); if (image != null && imageLoader != null) { - loadImage(message); + imageLoader.loadImage(image, message.getImageUrl(), getPayloadForImageLoader(message)); } if (imageOverlay != null) { @@ -903,8 +903,13 @@ public final void applyStyle(MessagesListStyle style) { } } - protected void loadImage(MESSAGE message) { - imageLoader.loadImage(image, message.getImageUrl(), null); + /** + * Override this method to have ability to pass custom data in ImageLoader for loading image(not avatar). + * + * @param message Message with image + */ + protected Object getPayloadForImageLoader(MESSAGE message) { + return null; } private void init(View itemView) { @@ -946,7 +951,7 @@ public OutcomingImageMessageViewHolder(View itemView, Object payload) { public void onBind(MESSAGE message) { super.onBind(message); if (image != null && imageLoader != null) { - loadImage(message); + imageLoader.loadImage(image, message.getImageUrl(), getPayloadForImageLoader(message)); } if (imageOverlay != null) { @@ -969,12 +974,12 @@ public final void applyStyle(MessagesListStyle style) { } /** - * Calls Imageloader for loading image. - * Override this method to have ability to pass custom data in ImageLoader. + * Override this method to have ability to pass custom data in ImageLoader for loading image(not avatar). + * * @param message Message with image */ - protected void loadImage(MESSAGE message) { - imageLoader.loadImage(image, message.getImageUrl(), null); + protected Object getPayloadForImageLoader(MESSAGE message) { + return null; } private void init(View itemView) { diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomOutcomingImageMessageViewHolder.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomOutcomingImageMessageViewHolder.java index b8f00b16..484ce026 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomOutcomingImageMessageViewHolder.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/messages/CustomOutcomingImageMessageViewHolder.java @@ -1,5 +1,6 @@ package com.stfalcon.chatkit.sample.features.demo.custom.holder.holders.messages; +import android.util.Pair; import android.view.View; import com.stfalcon.chatkit.messages.MessageHolders; @@ -22,9 +23,10 @@ public void onBind(Message message) { time.setText(message.getStatus() + " " + time.getText()); } - //Override this method to pass custom data in ImageLoader. + //Override this method to have ability to pass custom data in ImageLoader for loading image(not avatar). @Override - protected void loadImage(Message message) { - imageLoader.loadImage(image, message.getImageUrl(), null); + protected Object getPayloadForImageLoader(Message message) { + //For example you can pass size of placeholder before loading + return new Pair<>(100, 100); } } \ No newline at end of file From bc4a21879607e468500e6b448b7c88792a7fb072 Mon Sep 17 00:00:00 2001 From: Primoz Date: Thu, 4 Oct 2018 11:29:23 +1000 Subject: [PATCH 74/96] Added upsert method to move a specific item to the start. --- .../chatkit/messages/MessagesListAdapter.java | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) 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 acc105f9..80f0a304 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -51,7 +51,7 @@ public class MessagesListAdapter protected static boolean isSelectionModeEnabled; - protected List items; + public List items; private MessageHolders holders; private String senderId; @@ -213,6 +213,22 @@ public boolean update(String oldId, MESSAGE newMessage) { } } + /** + * Moves the elements position from current to start + * + * @param newMessage new message object. + */ + public void updateAndMoveToStart(MESSAGE newMessage) { + int position = getMessagePositionById(newMessage.getId()); + if (position >= 0) { + Wrapper element = new Wrapper<>(newMessage); + items.remove(position); + items.add(0, element); + notifyItemMoved(position, 0); + notifyItemChanged(0); + } + } + /** * Updates message by its id if it exists, add to start if not * @@ -224,6 +240,24 @@ public void upsert(MESSAGE message) { } } + /** + * Updates and moves to start if message by its id exists and if specified move to start, if not + * specified the item stays at current position and updated + * + * @param message message object to insert or update. + */ + public void upsert(MESSAGE message, boolean moveToStartIfUpdate) { + if (moveToStartIfUpdate) { + if (getMessagePositionById(message.getId()) > 0) { + updateAndMoveToStart(message); + } else { + upsert(message); + } + } else { + upsert(message); + } + } + /** * Deletes message. * @@ -494,7 +528,7 @@ private void recountDateHeaders() { } } - private void generateDateHeaders(List messages) { + public void generateDateHeaders(List messages) { for (int i = 0; i < messages.size(); i++) { MESSAGE message = messages.get(i); this.items.add(new Wrapper<>(message)); @@ -653,9 +687,9 @@ void setStyle(MessagesListStyle style) { /* * WRAPPER * */ - private class Wrapper { - protected DATA item; - protected boolean isSelected; + public class Wrapper { + public DATA item; + public boolean isSelected; Wrapper(DATA item) { this.item = item; From e1b9332f2b46d328ed7130db38a61ff22df926f2 Mon Sep 17 00:00:00 2001 From: Primoz Date: Fri, 12 Oct 2018 08:35:57 +1100 Subject: [PATCH 75/96] Changed access modifier from public to protected for: - List items - method `generateDateHeaders` --- .../com/stfalcon/chatkit/messages/MessagesListAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 80f0a304..e0fcb8a2 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -51,7 +51,7 @@ public class MessagesListAdapter protected static boolean isSelectionModeEnabled; - public List items; + protected List items; private MessageHolders holders; private String senderId; @@ -528,7 +528,7 @@ private void recountDateHeaders() { } } - public void generateDateHeaders(List messages) { + protected void generateDateHeaders(List messages) { for (int i = 0; i < messages.size(); i++) { MESSAGE message = messages.get(i); this.items.add(new Wrapper<>(message)); From 947adeda2ffb5aa3f59a7fb13600c986138d7928 Mon Sep 17 00:00:00 2001 From: Anton Bevza Date: Fri, 12 Oct 2018 09:45:24 +0300 Subject: [PATCH 76/96] Update CHANGELOG.md --- docs/CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 15c85c0c..6dc81352 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,12 @@ +## Version 0.3.2 (2018/09/28) +* [Passing custom data to ImageLoader](https://github.com/stfalcon-studio/ChatKit/issues/183) +* Fixed [#198](https://github.com/stfalcon-studio/ChatKit/issues/198) +* Protected `items` field in `MessagesListAdapter` and `DialogsListAdapte` [#188](https://github.com/stfalcon-studio/ChatKit/issues/188) +* Fixed `delete` and `deleteByIds` methods in MessagesListAdapter +* Merged: Clear last message if null in dialog list (Fix issue #189) [#190](https://github.com/stfalcon-studio/ChatKit/pull/190) +* Merged: Add upsert method to dialogs list [#191](https://github.com/stfalcon-studio/ChatKit/pull/191) +* Merged: Update documentation to add upsertItem method [#208](https://github.com/stfalcon-studio/ChatKit/pull/208) + ## Version 0.3.1 (2018/08/16) * [Passing custom data to your ViewHolder](https://github.com/stfalcon-studio/ChatKit/blob/master/docs/COMPONENT_MESSAGES_LIST.md#passing-custom-data-to-your-viewholder) [#180](https://github.com/stfalcon-studio/ChatKit/issues/180) * Added Proguard rules to [Readme](https://github.com/stfalcon-studio/ChatKit#proguard) and [sample project](https://github.com/stfalcon-studio/ChatKit/blob/master/sample/proguard-rules.pro). [#122](https://github.com/stfalcon-studio/ChatKit/issues/122) From 5edd8044ff407373cfcf7cbd7898dbee4ee3b65c Mon Sep 17 00:00:00 2001 From: Anton Bevza Date: Fri, 12 Oct 2018 09:48:09 +0300 Subject: [PATCH 77/96] Update CHANGELOG.md --- docs/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 6dc81352..82c7cd8d 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,6 @@ +## Version 0.3.3-SNAPSHOT (2018/10/12) +* Merged: Added upsert method to move a specific item to the start. [#209](https://github.com/stfalcon-studio/ChatKit/pull/209) + ## Version 0.3.2 (2018/09/28) * [Passing custom data to ImageLoader](https://github.com/stfalcon-studio/ChatKit/issues/183) * Fixed [#198](https://github.com/stfalcon-studio/ChatKit/issues/198) From c48ace09d79c9825724062987880eee8b9ca9b3e Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 12 Oct 2018 10:00:59 +0300 Subject: [PATCH 78/96] version 0.3.3-SNAPSHOT --- chatkit/build.gradle | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/chatkit/build.gradle b/chatkit/build.gradle index 9889ae13..32c8c3da 100644 --- a/chatkit/build.gradle +++ b/chatkit/build.gradle @@ -8,8 +8,7 @@ android { defaultConfig { minSdkVersion 14 versionCode 1 - versionName "0.3.2" - + versionName "0.3.3-SNAPSHOT" consumerProguardFiles 'proguard.txt' } android { @@ -22,7 +21,7 @@ android { publish { groupId = 'com.github.stfalcon' artifactId = 'chatkit' - publishVersion = '0.3.2' + publishVersion = '0.3.3-SNAPSHOT' 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' From a660b7ac9ecbb094467c226f9255a32bdc05316f Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 12 Oct 2018 10:13:19 +0300 Subject: [PATCH 79/96] version 0.3.3 --- chatkit/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chatkit/build.gradle b/chatkit/build.gradle index 32c8c3da..f9b50b7f 100644 --- a/chatkit/build.gradle +++ b/chatkit/build.gradle @@ -8,7 +8,7 @@ android { defaultConfig { minSdkVersion 14 versionCode 1 - versionName "0.3.3-SNAPSHOT" + versionName "0.3.3" consumerProguardFiles 'proguard.txt' } android { @@ -21,7 +21,7 @@ android { publish { groupId = 'com.github.stfalcon' artifactId = 'chatkit' - publishVersion = '0.3.3-SNAPSHOT' + 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' From 6b9072b2db6c2674609cb97981522dfc1e5f8951 Mon Sep 17 00:00:00 2001 From: Anton Bevza Date: Fri, 12 Oct 2018 10:19:01 +0300 Subject: [PATCH 80/96] Update CHANGELOG.md --- docs/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 82c7cd8d..32e427f5 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,4 +1,4 @@ -## Version 0.3.3-SNAPSHOT (2018/10/12) +## Version 0.3.3 (2018/10/12) * Merged: Added upsert method to move a specific item to the start. [#209](https://github.com/stfalcon-studio/ChatKit/pull/209) ## Version 0.3.2 (2018/09/28) From 2cfc13868be581aae82a9980dd7dff185a20a5dc Mon Sep 17 00:00:00 2001 From: Anton Bevza Date: Fri, 12 Oct 2018 10:20:52 +0300 Subject: [PATCH 81/96] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a0736751..f98dad80 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ To implement all of the features above you can use the following components: Download via Gradle: ```gradle -compile 'com.github.stfalcon:chatkit:0.3.1' +compile 'com.github.stfalcon:chatkit:0.3.3' ``` or Maven: @@ -51,7 +51,7 @@ or Maven: com.github.stfalcon chatkit - 0.3.1 + 0.3.3 pom ``` From 0c77ce94379d325d21773b75747b169efa0c25ce Mon Sep 17 00:00:00 2001 From: Anton Bevza Date: Wed, 29 May 2019 10:06:34 +0300 Subject: [PATCH 82/96] Update COMPONENT_MESSAGES_LIST.md --- docs/COMPONENT_MESSAGES_LIST.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/COMPONENT_MESSAGES_LIST.md b/docs/COMPONENT_MESSAGES_LIST.md index d424767f..1273fda8 100644 --- a/docs/COMPONENT_MESSAGES_LIST.md +++ b/docs/COMPONENT_MESSAGES_LIST.md @@ -370,7 +370,7 @@ Then in our custom ViewHolder in method `onBind`: } ``` Then create Payload and set it and our ViewHolder class to MessageHolders config. -``` +```java //We can pass any data to ViewHolder with payload CustomIncomingTextMessageViewHolder.Payload payload = new CustomIncomingTextMessageViewHolder.Payload(); //For example click listener From 47c2ca3c8e60a089f3fa600a89905f0805000e08 Mon Sep 17 00:00:00 2001 From: Andrii Zhumela Date: Mon, 8 Jul 2019 11:47:18 +0300 Subject: [PATCH 83/96] Update README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index f98dad80..5b64f95a 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,13 @@ or Maven: ``` +### AndroidX +To use with AndroidX you have to set targetSdkVersion for your project to 28 and add following 2 lines in ```gradle.properties``` file. +``` +android.useAndroidX=true +android.enableJetifier=true +``` + ### Proguard If you are using ProGuard you might need to add rules: ``` From 243e8908de999a9111b2c4192808488f2c946fd0 Mon Sep 17 00:00:00 2001 From: Andrii Zhumela Date: Tue, 9 Jul 2019 09:59:54 +0300 Subject: [PATCH 84/96] Update COMPONENT_MESSAGES_LIST.md --- docs/COMPONENT_MESSAGES_LIST.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/COMPONENT_MESSAGES_LIST.md b/docs/COMPONENT_MESSAGES_LIST.md index 1273fda8..cff2a03e 100644 --- a/docs/COMPONENT_MESSAGES_LIST.md +++ b/docs/COMPONENT_MESSAGES_LIST.md @@ -282,7 +282,7 @@ But what if you need not only to change the appearance of the elements, but also * `@id/messageTime` (TextView) * `@id/messageUserAvatar` (ImageView) -For better understanding see how [custom layout looks like](https://github.com/stfalcon-studio/ChatKit/blob/master/sample/src/main/res/layout/item_custom_incoming_message.xml) +For better understanding see how [custom layout looks like](https://github.com/stfalcon-studio/ChatKit/blob/master/sample/src/main/res/layout/item_custom_incoming_text_message.xml) After a layout was created, you need to put it into `HoldersConfig` object, which has appropriate methods for each layout files: `setIncomingLayout(int layoutRes)`, `setOutcomingLayout(int layoutRes)` `setDateHeaderLayout(int layoutRes)`. To hook up a config object, you need to transfer it to adapter through a constructor: From b3be2b0f840c23683ece92c084a60df78737da73 Mon Sep 17 00:00:00 2001 From: Ilya Gazman Date: Wed, 7 Oct 2020 19:54:44 -0400 Subject: [PATCH 85/96] Migrated to AndroidX and Java 8 --- chatkit/build.gradle | 21 +- chatkit/src/main/AndroidManifest.xml | 3 +- .../stfalcon/chatkit/commons/ImageLoader.java | 3 +- .../com/stfalcon/chatkit/commons/Style.java | 11 +- .../stfalcon/chatkit/commons/ViewHolder.java | 3 +- .../chatkit/commons/models/IUser.java | 6 +- .../commons/models/MessageContentType.java | 3 +- .../stfalcon/chatkit/dialogs/DialogsList.java | 15 +- .../chatkit/dialogs/DialogsListAdapter.java | 87 +++-- .../chatkit/messages/MessageHolders.java | 40 +-- .../chatkit/messages/MessageInput.java | 15 +- .../chatkit/messages/MessageInputStyle.java | 7 +- .../chatkit/messages/MessagesList.java | 11 +- .../chatkit/messages/MessagesListAdapter.java | 52 ++- .../chatkit/messages/MessagesListStyle.java | 7 +- .../messages/RecyclerScrollMoreListener.java | 8 +- .../chatkit/utils/RoundedImageView.java | 14 +- .../chatkit/utils/ShapeImageView.java | 2 +- .../src/main/res/layout/item_date_header.xml | 10 +- chatkit/src/main/res/layout/item_dialog.xml | 20 +- .../layout/item_incoming_image_message.xml | 11 +- .../res/layout/item_incoming_text_message.xml | 9 +- .../layout/item_outcoming_image_message.xml | 9 +- .../layout/item_outcoming_text_message.xml | 7 +- .../main/res/layout/view_message_input.xml | 17 +- chatkit/src/main/res/values/attrs.xml | 316 +++++++++--------- chatkit/src/main/res/values/strings.xml | 2 +- gradle.properties | 4 - gradlew | 198 +++++------ sample/build.gradle | 35 +- .../sample/ExampleInstrumentedTest.java | 7 +- sample/src/main/AndroidManifest.xml | 32 +- .../features/demo/DemoDialogsActivity.java | 13 +- .../features/demo/DemoMessagesActivity.java | 46 +-- .../holder/CustomHolderDialogsActivity.java | 2 +- .../holder/CustomHolderMessagesActivity.java | 13 +- .../CustomIncomingTextMessageViewHolder.java | 9 +- .../layout/CustomLayoutDialogsActivity.java | 2 +- .../layout/CustomLayoutMessagesActivity.java | 4 +- .../media/CustomMediaMessagesActivity.java | 13 +- .../IncomingVoiceMessageViewHolder.java | 4 +- .../OutcomingVoiceMessageViewHolder.java | 4 +- .../demo/def/DefaultDialogsActivity.java | 2 +- .../demo/def/DefaultMessagesActivity.java | 17 +- .../demo/styled/StyledDialogsActivity.java | 2 +- .../demo/styled/StyledMessagesActivity.java | 4 +- .../sample/features/main/MainActivity.java | 9 +- .../main/adapter/DemoCardFragment.java | 15 +- .../adapter/MainActivityPagerAdapter.java | 7 +- .../chatkit/sample/utils/AppUtils.java | 3 +- .../res/drawable/dark_blue_top_gradient.xml | 4 +- .../src/main/res/drawable/ic_play_black.xml | 5 +- .../src/main/res/drawable/ic_play_white.xml | 5 +- .../res/drawable/shape_bubble_offline.xml | 8 +- .../main/res/drawable/shape_bubble_online.xml | 8 +- .../main/res/drawable/shape_custom_cursor.xml | 6 +- .../layout/activity_custom_holder_dialogs.xml | 5 +- .../activity_custom_holder_messages.xml | 9 +- .../layout/activity_custom_layout_dialogs.xml | 5 +- .../activity_custom_layout_messages.xml | 9 +- .../layout/activity_custom_media_messages.xml | 9 +- .../res/layout/activity_default_dialogs.xml | 5 +- .../res/layout/activity_default_messages.xml | 9 +- sample/src/main/res/layout/activity_main.xml | 17 +- .../res/layout/activity_styled_dialogs.xml | 5 +- .../res/layout/activity_styled_messages.xml | 9 +- .../main/res/layout/fragment_demo_card.xml | 11 +- .../main/res/layout/item_custom_dialog.xml | 17 +- .../layout/item_custom_dialog_view_holder.xml | 20 +- .../item_custom_incoming_image_message.xml | 11 +- .../item_custom_incoming_text_message.xml | 11 +- .../item_custom_incoming_voice_message.xml | 11 +- .../item_custom_outcoming_image_message.xml | 7 +- .../item_custom_outcoming_text_message.xml | 7 +- .../item_custom_outcoming_voice_message.xml | 9 +- sample/src/main/res/layout/item_sample.xml | 11 +- .../src/main/res/menu/chat_actions_menu.xml | 6 +- .../chatkit/sample/ExampleUnitTest.java | 2 +- 78 files changed, 658 insertions(+), 737 deletions(-) diff --git a/chatkit/build.gradle b/chatkit/build.gradle index f9b50b7f..14d6746d 100644 --- a/chatkit/build.gradle +++ b/chatkit/build.gradle @@ -2,8 +2,8 @@ apply plugin: 'com.android.library' apply plugin: 'com.novoda.bintray-release' android { - compileSdkVersion 27 - buildToolsVersion "27.0.3" + compileSdkVersion 29 + buildToolsVersion '29.0.2' defaultConfig { minSdkVersion 14 @@ -16,6 +16,11 @@ android { abortOnError false } } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } publish { @@ -28,15 +33,11 @@ publish { website = 'https://github.com/stfalcon-studio/ChatKit.git' } -ext { - supportVersion = '27.1.1' - flexboxVersion = '1.0.0' -} - dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "com.android.support:appcompat-v7:$supportVersion" - implementation "com.android.support:design:$supportVersion" - implementation "com.google.android:flexbox:$flexboxVersion" + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.2.1' + implementation "com.google.android:flexbox:1.0.0" + implementation 'androidx.recyclerview:recyclerview:1.1.0' } diff --git a/chatkit/src/main/AndroidManifest.xml b/chatkit/src/main/AndroidManifest.xml index 1b8f973d..e3238ed8 100644 --- a/chatkit/src/main/AndroidManifest.xml +++ b/chatkit/src/main/AndroidManifest.xml @@ -1,4 +1,3 @@ - + 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..bfcfeb78 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/commons/ImageLoader.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/commons/ImageLoader.java @@ -16,9 +16,10 @@ package com.stfalcon.chatkit.commons; -import android.support.annotation.Nullable; import android.widget.ImageView; +import androidx.annotation.Nullable; + /** * Callback for implementing images loading in message list */ 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..c69511a3 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/commons/Style.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/commons/Style.java @@ -20,14 +20,15 @@ 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 android.util.AttributeSet; import android.util.TypedValue; +import androidx.annotation.AttrRes; +import androidx.annotation.ColorRes; +import androidx.annotation.DimenRes; +import androidx.annotation.DrawableRes; +import androidx.core.content.ContextCompat; + import com.stfalcon.chatkit.R; /** 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..c92d5213 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/commons/ViewHolder.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/commons/ViewHolder.java @@ -16,9 +16,10 @@ package com.stfalcon.chatkit.commons; -import android.support.v7.widget.RecyclerView; import android.view.View; +import androidx.recyclerview.widget.RecyclerView; + /** * Base ViewHolder */ diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IUser.java b/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IUser.java index d51c2081..d4c621a0 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IUser.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IUser.java @@ -25,20 +25,20 @@ public interface IUser { * Returns the user's id * * @return the user's id - * */ + */ String getId(); /** * Returns the user's name * * @return the user's name - * */ + */ String getName(); /** * Returns the user's avatar image url * * @return the user's avatar image url - * */ + */ String getAvatar(); } 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..cb33dd6c 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,8 @@ 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..cf2448cb 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsList.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsList.java @@ -17,13 +17,14 @@ 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 android.util.AttributeSet; +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 com.stfalcon.chatkit.commons.models.IDialog; /** @@ -73,7 +74,7 @@ public void setAdapter(Adapter adapter) { * @param adapter Adapter. Must extend DialogsListAdapter * @param Dialog model class */ - public + public > void setAdapter(DialogsListAdapter adapter) { setAdapter(adapter, false); } @@ -85,7 +86,7 @@ void setAdapter(DialogsListAdapter adapter) { * @param reverseLayout weather to use reverse layout for layout manager. * @param Dialog model class */ - public + public > void setAdapter(DialogsListAdapter adapter, boolean reverseLayout) { SimpleItemAnimator itemAnimator = new DefaultItemAnimator(); itemAnimator.setSupportsChangeAnimations(false); 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..147fda0e 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,6 @@ 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 android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; @@ -28,6 +25,10 @@ import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.LayoutRes; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.RecyclerView; + import com.stfalcon.chatkit.R; import com.stfalcon.chatkit.commons.ImageLoader; import com.stfalcon.chatkit.commons.ViewHolder; @@ -216,8 +217,9 @@ public void addItem(int position, DIALOG dialog) { /** * Move an item + * * @param fromPosition the actual position of the item - * @param toPosition the new position of the item + * @param toPosition the new position of the item */ public void moveItem(int fromPosition, int toPosition) { DIALOG dialog = items.remove(fromPosition); @@ -327,15 +329,12 @@ public boolean updateDialogWithMessage(String dialogId, IMessage message) { * Sort dialog by last message date */ public void sortByLastMessageDate() { - Collections.sort(items, new Comparator() { - @Override - public int compare(DIALOG o1, DIALOG o2) { - if (o1.getLastMessage().getCreatedAt().after(o2.getLastMessage().getCreatedAt())) { - return -1; - } else if (o1.getLastMessage().getCreatedAt().before(o2.getLastMessage().getCreatedAt())) { - return 1; - } else return 0; - } + Collections.sort(items, (o1, o2) -> { + if (o1.getLastMessage().getCreatedAt().after(o2.getLastMessage().getCreatedAt())) { + return -1; + } else if (o1.getLastMessage().getCreatedAt().before(o2.getLastMessage().getCreatedAt())) { + return 1; + } else return 0; }); notifyDataSetChanged(); } @@ -443,15 +442,15 @@ void setStyle(DialogListStyle dialogStyle) { } /** - * @return the position of a dialog in the dialogs list. - */ + * @return the position of a dialog in the dialogs list. + */ public int getDialogPosition(DIALOG dialog) { return this.items.indexOf(dialog); } /* - * LISTENERS - * */ + * LISTENERS + * */ public interface OnDialogClickListener { void onDialogClick(DIALOG dialog); } @@ -469,8 +468,8 @@ public interface OnDialogViewLongClickListener { } /* - * HOLDERS - * */ + * HOLDERS + * */ public abstract static class BaseDialogViewHolder extends ViewHolder { @@ -525,15 +524,15 @@ public static class DialogViewHolder extends BaseDialogV public DialogViewHolder(View itemView) { super(itemView); - root = (ViewGroup) itemView.findViewById(R.id.dialogRootLayout); - container = (ViewGroup) itemView.findViewById(R.id.dialogContainer); - tvName = (TextView) itemView.findViewById(R.id.dialogName); - tvDate = (TextView) itemView.findViewById(R.id.dialogDate); - tvLastMessage = (TextView) itemView.findViewById(R.id.dialogLastMessage); - tvBubble = (TextView) itemView.findViewById(R.id.dialogUnreadBubble); - ivLastMessageUser = (ImageView) itemView.findViewById(R.id.dialogLastMessageUserAvatar); - ivAvatar = (ImageView) itemView.findViewById(R.id.dialogAvatar); - dividerContainer = (ViewGroup) itemView.findViewById(R.id.dialogDividerContainer); + root = itemView.findViewById(R.id.dialogRootLayout); + container = itemView.findViewById(R.id.dialogContainer); + tvName = itemView.findViewById(R.id.dialogName); + tvDate = itemView.findViewById(R.id.dialogDate); + tvLastMessage = itemView.findViewById(R.id.dialogLastMessage); + tvBubble = itemView.findViewById(R.id.dialogUnreadBubble); + ivLastMessageUser = itemView.findViewById(R.id.dialogLastMessageUserAvatar); + ivAvatar = itemView.findViewById(R.id.dialogAvatar); + dividerContainer = itemView.findViewById(R.id.dialogDividerContainer); divider = itemView.findViewById(R.id.dialogDivider); } @@ -680,30 +679,24 @@ public void onBind(final DIALOG dialog) { tvBubble.setVisibility(dialogStyle.isDialogUnreadBubbleEnabled() && dialog.getUnreadCount() > 0 ? VISIBLE : GONE); - container.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (onDialogClickListener != null) { - onDialogClickListener.onDialogClick(dialog); - } - if (onDialogViewClickListener != null) { - onDialogViewClickListener.onDialogViewClick(view, dialog); - } + container.setOnClickListener(view -> { + if (onDialogClickListener != null) { + onDialogClickListener.onDialogClick(dialog); + } + if (onDialogViewClickListener != null) { + onDialogViewClickListener.onDialogViewClick(view, dialog); } }); - container.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - if (onLongItemClickListener != null) { - onLongItemClickListener.onDialogLongClick(dialog); - } - if (onDialogViewLongClickListener != null) { - onDialogViewLongClickListener.onDialogViewLongClick(view, dialog); - } - return onLongItemClickListener != null || onDialogViewLongClickListener != null; + container.setOnLongClickListener(view -> { + if (onLongItemClickListener != null) { + onLongItemClickListener.onDialogLongClick(dialog); + } + if (onDialogViewLongClickListener != null) { + onDialogViewLongClickListener.onDialogViewLongClick(view, dialog); } + return onLongItemClickListener != null || onDialogViewLongClickListener != null; }); } 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..2c09b016 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,5 @@ package com.stfalcon.chatkit.messages; -import android.support.annotation.LayoutRes; -import android.support.annotation.NonNull; -import android.support.v4.view.ViewCompat; import android.text.Spannable; import android.text.method.LinkMovementMethod; import android.util.SparseArray; @@ -14,6 +11,10 @@ import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.LayoutRes; +import androidx.annotation.NonNull; +import androidx.core.view.ViewCompat; + import com.stfalcon.chatkit.R; import com.stfalcon.chatkit.commons.ImageLoader; import com.stfalcon.chatkit.commons.ViewHolder; @@ -508,8 +509,8 @@ MessageHolders registerContentType( customContentTypes.add( new MessageHolders.ContentTypeConfig<>(type, - new MessageHolders.HolderConfig<>(incomingHolder, incomingLayout, incomingPayload), - new MessageHolders.HolderConfig<>(outcomingHolder, outcomingLayout, outcomingPayload))); + new HolderConfig<>(incomingHolder, incomingLayout, incomingPayload), + new HolderConfig<>(outcomingHolder, outcomingLayout, outcomingPayload))); this.contentChecker = contentChecker; return this; } @@ -580,12 +581,7 @@ protected void bind(final ViewHolder holder, final Object item, boolean isSelect final int key = clickListenersArray.keyAt(i); final View view = holder.itemView.findViewById(key); if (view != null) { - view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListenersArray.get(key).onMessageViewClick(view, (IMessage) item); - } - }); + view.setOnClickListener(v -> clickListenersArray.get(key).onMessageViewClick(view, (IMessage) item)); } } } else if (item instanceof Date) { @@ -793,8 +789,8 @@ public void applyStyle(MessagesListStyle style) { } private void init(View itemView) { - bubble = (ViewGroup) itemView.findViewById(R.id.bubble); - text = (TextView) itemView.findViewById(R.id.messageText); + bubble = itemView.findViewById(R.id.bubble); + text = itemView.findViewById(R.id.messageText); } } @@ -852,8 +848,8 @@ public final void applyStyle(MessagesListStyle style) { } private void init(View itemView) { - bubble = (ViewGroup) itemView.findViewById(R.id.bubble); - text = (TextView) itemView.findViewById(R.id.messageText); + bubble = itemView.findViewById(R.id.bubble); + text = itemView.findViewById(R.id.messageText); } } @@ -913,7 +909,7 @@ protected Object getPayloadForImageLoader(MESSAGE message) { } private void init(View itemView) { - image = (ImageView) itemView.findViewById(R.id.image); + image = itemView.findViewById(R.id.image); imageOverlay = itemView.findViewById(R.id.imageOverlay); if (image instanceof RoundedImageView) { @@ -983,7 +979,7 @@ protected Object getPayloadForImageLoader(MESSAGE message) { } private void init(View itemView) { - image = (ImageView) itemView.findViewById(R.id.image); + image = itemView.findViewById(R.id.image); imageOverlay = itemView.findViewById(R.id.imageOverlay); if (image instanceof RoundedImageView) { @@ -1009,7 +1005,7 @@ public static class DefaultDateHeaderViewHolder extends ViewHolder public DefaultDateHeaderViewHolder(View itemView) { super(itemView); - text = (TextView) itemView.findViewById(R.id.messageText); + text = itemView.findViewById(R.id.messageText); } @Override @@ -1089,8 +1085,8 @@ public void applyStyle(MessagesListStyle style) { } private void init(View itemView) { - time = (TextView) itemView.findViewById(R.id.messageTime); - userAvatar = (ImageView) itemView.findViewById(R.id.messageUserAvatar); + time = itemView.findViewById(R.id.messageTime); + userAvatar = itemView.findViewById(R.id.messageUserAvatar); } } @@ -1130,7 +1126,7 @@ public void applyStyle(MessagesListStyle style) { } private void init(View itemView) { - time = (TextView) itemView.findViewById(R.id.messageTime); + time = itemView.findViewById(R.id.messageTime); } } @@ -1189,7 +1185,7 @@ private ContentTypeConfig( } } - private class HolderConfig { + private static class HolderConfig { protected Class> holder; protected int layout; 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..665f0503 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,6 @@ 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 android.text.Editable; import android.text.TextWatcher; import android.util.AttributeSet; @@ -29,8 +27,11 @@ import android.widget.EditText; import android.widget.ImageButton; import android.widget.RelativeLayout; +import android.widget.Space; import android.widget.TextView; +import androidx.core.view.ViewCompat; + import com.stfalcon.chatkit.R; import java.lang.reflect.Field; @@ -226,11 +227,11 @@ && getPaddingBottom() == 0) { private void init(Context context) { inflate(context, R.layout.view_message_input, this); - messageInput = (EditText) findViewById(R.id.messageInput); - messageSendButton = (ImageButton) findViewById(R.id.messageSendButton); - attachmentButton = (ImageButton) findViewById(R.id.attachmentButton); - sendButtonSpace = (Space) findViewById(R.id.sendButtonSpace); - attachmentButtonSpace = (Space) findViewById(R.id.attachmentButtonSpace); + messageInput = findViewById(R.id.messageInput); + messageSendButton = findViewById(R.id.messageSendButton); + attachmentButton = findViewById(R.id.attachmentButton); + sendButtonSpace = findViewById(R.id.sendButtonSpace); + attachmentButtonSpace = findViewById(R.id.attachmentButtonSpace); messageSendButton.setOnClickListener(this); attachmentButton.setOnClickListener(this); 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..ddac1859 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInputStyle.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageInputStyle.java @@ -20,11 +20,12 @@ 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 android.util.AttributeSet; +import androidx.annotation.ColorInt; +import androidx.annotation.DrawableRes; +import androidx.core.graphics.drawable.DrawableCompat; + import com.stfalcon.chatkit.R; import com.stfalcon.chatkit.commons.Style; 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..901b6eeb 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesList.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesList.java @@ -17,13 +17,14 @@ 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 android.util.AttributeSet; +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 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 e0fcb8a2..74ed2760 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -19,8 +19,6 @@ import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; -import android.support.annotation.LayoutRes; -import android.support.v7.widget.RecyclerView; import android.text.Spannable; import android.text.method.LinkMovementMethod; import android.util.SparseArray; @@ -30,6 +28,9 @@ import android.view.ViewGroup; import android.widget.TextView; +import androidx.annotation.LayoutRes; +import androidx.recyclerview.widget.RecyclerView; + import com.stfalcon.chatkit.R; import com.stfalcon.chatkit.commons.ImageLoader; import com.stfalcon.chatkit.commons.ViewHolder; @@ -617,39 +618,32 @@ private void notifyMessageViewLongClicked(View view, MESSAGE message) { } private View.OnClickListener getMessageClickListener(final Wrapper wrapper) { - return new View.OnClickListener() { - @Override - public void onClick(View view) { - if (selectionListener != null && isSelectionModeEnabled) { - wrapper.isSelected = !wrapper.isSelected; + return view -> { + if (selectionListener != null && isSelectionModeEnabled) { + wrapper.isSelected = !wrapper.isSelected; - if (wrapper.isSelected) incrementSelectedItemsCount(); - else decrementSelectedItemsCount(); + if (wrapper.isSelected) incrementSelectedItemsCount(); + else decrementSelectedItemsCount(); - MESSAGE message = (wrapper.item); - notifyItemChanged(getMessagePositionById(message.getId())); - } else { - notifyMessageClicked(wrapper.item); - notifyMessageViewClicked(view, wrapper.item); - } + MESSAGE message = (wrapper.item); + notifyItemChanged(getMessagePositionById(message.getId())); + } else { + notifyMessageClicked(wrapper.item); + notifyMessageViewClicked(view, wrapper.item); } }; } private View.OnLongClickListener getMessageLongClickListener(final Wrapper wrapper) { - return new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - if (selectionListener == null) { - notifyMessageLongClicked(wrapper.item); - notifyMessageViewLongClicked(view, wrapper.item); - return true; - } else { - isSelectionModeEnabled = true; - view.performClick(); - return true; - } + return view -> { + if (selectionListener == null) { + notifyMessageLongClicked(wrapper.item); + notifyMessageViewLongClicked(view, wrapper.item); + } else { + isSelectionModeEnabled = true; + view.performClick(); } + return true; }; } @@ -687,7 +681,7 @@ void setStyle(MessagesListStyle style) { /* * WRAPPER * */ - public class Wrapper { + public static class Wrapper { public DATA item; public boolean isSelected; @@ -948,7 +942,7 @@ public static class DefaultDateHeaderViewHolder extends ViewHolder public DefaultDateHeaderViewHolder(View itemView) { super(itemView); - text = (TextView) itemView.findViewById(R.id.messageText); + text = itemView.findViewById(R.id.messageText); } @Override 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..4ea6ed10 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListStyle.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListStyle.java @@ -22,11 +22,12 @@ 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 android.util.AttributeSet; +import androidx.annotation.ColorInt; +import androidx.annotation.DrawableRes; +import androidx.core.graphics.drawable.DrawableCompat; + import com.stfalcon.chatkit.R; import com.stfalcon.chatkit.commons.Style; 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..d53c6f0d 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,12 @@ 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 android.util.AttributeSet; -import android.widget.ImageView; + +import androidx.annotation.DimenRes; +import androidx.annotation.NonNull; +import androidx.appcompat.widget.AppCompatImageView; +import androidx.core.content.ContextCompat; /** * Thanks to Joonho Kim (https://github.com/pungrue26) for his lightweight SelectableRoundedImageView, @@ -134,8 +134,6 @@ private static class RoundedCornerDrawable extends Drawable { private final Paint mBitmapPaint; - private BitmapShader mBitmapShader; - private float[] mRadii = new float[]{0, 0, 0, 0, 0, 0, 0, 0}; private Path mPath = new Path(); @@ -144,7 +142,7 @@ private static class RoundedCornerDrawable extends Drawable { private RoundedCornerDrawable(Bitmap bitmap, Resources r) { mBitmap = bitmap; - mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); + BitmapShader mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); mBitmapWidth = bitmap.getScaledWidth(r.getDisplayMetrics()); mBitmapHeight = bitmap.getScaledHeight(r.getDisplayMetrics()); 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/item_date_header.xml b/chatkit/src/main/res/layout/item_date_header.xml index 3564394c..356aef27 100644 --- a/chatkit/src/main/res/layout/item_date_header.xml +++ b/chatkit/src/main/res/layout/item_date_header.xml @@ -1,6 +1,6 @@ \ No newline at end of file + android:id="@id/messageText" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center_horizontal" + android:padding="16dp" /> \ No newline at end of file diff --git a/chatkit/src/main/res/layout/item_dialog.xml b/chatkit/src/main/res/layout/item_dialog.xml index 9820dec2..3e3f8b55 100644 --- a/chatkit/src/main/res/layout/item_dialog.xml +++ b/chatkit/src/main/res/layout/item_dialog.xml @@ -1,7 +1,7 @@ + android:id="@id/dialogRootLayout" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + android:layout_margin="16dp" /> + android:maxLines="1" /> + android:maxLines="1" /> + android:layout_marginRight="7dp" /> + android:maxLines="1" /> @@ -88,7 +88,7 @@ android:ellipsize="end" android:fontFamily="@string/font_fontFamily_medium" android:gravity="center" - android:lines="1"/> + android:lines="1" /> + android:background="@color/dialog_divider" /> diff --git a/chatkit/src/main/res/layout/item_incoming_image_message.xml b/chatkit/src/main/res/layout/item_incoming_image_message.xml index 2685e398..73d614d4 100644 --- a/chatkit/src/main/res/layout/item_incoming_image_message.xml +++ b/chatkit/src/main/res/layout/item_incoming_image_message.xml @@ -1,5 +1,4 @@ - + android:layout_marginRight="8dp" /> + android:layout_toRightOf="@id/messageUserAvatar" /> + android:layout_alignTop="@id/image" /> + android:layout_below="@id/image" /> \ No newline at end of file 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..f7ba34b0 100644 --- a/chatkit/src/main/res/layout/item_incoming_text_message.xml +++ b/chatkit/src/main/res/layout/item_incoming_text_message.xml @@ -1,5 +1,4 @@ - + android:layout_marginRight="8dp" /> + android:layout_height="wrap_content" /> + app:layout_alignSelf="center" /> diff --git a/chatkit/src/main/res/layout/item_outcoming_image_message.xml b/chatkit/src/main/res/layout/item_outcoming_image_message.xml index 21712d4f..0149b461 100644 --- a/chatkit/src/main/res/layout/item_outcoming_image_message.xml +++ b/chatkit/src/main/res/layout/item_outcoming_image_message.xml @@ -1,5 +1,4 @@ - + android:layout_marginStart="@dimen/message_outcoming_bubble_margin_left" /> + android:layout_alignTop="@id/image" /> + android:layout_below="@id/image" /> \ No newline at end of file diff --git a/chatkit/src/main/res/layout/item_outcoming_text_message.xml b/chatkit/src/main/res/layout/item_outcoming_text_message.xml index 51e5aeaa..58e58351 100644 --- a/chatkit/src/main/res/layout/item_outcoming_text_message.xml +++ b/chatkit/src/main/res/layout/item_outcoming_text_message.xml @@ -1,5 +1,4 @@ - + android:layout_alignWithParentIfMissing="true" /> + app:layout_order="1" /> diff --git a/chatkit/src/main/res/layout/view_message_input.xml b/chatkit/src/main/res/layout/view_message_input.xml index aaed1f5f..9ab1b4d9 100644 --- a/chatkit/src/main/res/layout/view_message_input.xml +++ b/chatkit/src/main/res/layout/view_message_input.xml @@ -1,5 +1,4 @@ - @@ -8,14 +7,14 @@ android:id="@id/attachmentButton" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_centerVertical="true"/> + android:layout_centerVertical="true" /> - + android:layout_toRightOf="@id/attachmentButton" /> + android:inputType="textAutoCorrect|textAutoComplete|textMultiLine|textCapSentences" /> - + android:layout_toStartOf="@id/messageSendButton" /> + android:layout_centerVertical="true" /> \ No newline at end of file diff --git a/chatkit/src/main/res/values/attrs.xml b/chatkit/src/main/res/values/attrs.xml index 1cd0a317..4e996630 100644 --- a/chatkit/src/main/res/values/attrs.xml +++ b/chatkit/src/main/res/values/attrs.xml @@ -1,227 +1,227 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - + + + + + + - - + + - - + + - - - - + + + + - - - + + + - - - - + + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - - - + + + + - - - + + + - - - - + + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - - - + + + + - - - + + + - + - - + + - - - + + + - + - - - + + + - - + + - - - + + + - + - - - + + + - - + + - - - + + + - + - - - + + + - - - + + + - - - + + + - + - - + + - - - + + + - - - - + + + + - - + + diff --git a/chatkit/src/main/res/values/strings.xml b/chatkit/src/main/res/values/strings.xml index ea100eae..2c5844dd 100644 --- a/chatkit/src/main/res/values/strings.xml +++ b/chatkit/src/main/res/values/strings.xml @@ -1 +1 @@ - + diff --git a/gradle.properties b/gradle.properties index aac7c9b4..743d692c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,16 +1,12 @@ # Project-wide Gradle settings. - # IDE (e.g. Android Studio) users: # Gradle settings configured through the IDE *will override* # any settings specified in this file. - # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html - # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. org.gradle.jvmargs=-Xmx1536m - # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects diff --git a/gradlew b/gradlew index 27309d92..dc2f857e 100755 --- a/gradlew +++ b/gradlew @@ -10,22 +10,22 @@ # Resolve links: $0 may be a link PRG="$0" # Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +while [ -h "$PRG" ]; do + ls=$(ls -ld "$PRG") + link=$(expr "$ls" : '.*-> \(.*\)$') + if expr "$link" : '/.*' >/dev/null; then + PRG="$link" + else + PRG=$(dirname "$PRG")"/$link" + fi done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" +SAVED="$(pwd)" +cd "$(dirname \"$PRG\")/" >/dev/null +APP_HOME="$(pwd -P)" cd "$SAVED" >/dev/null APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=$(basename "$0") # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS="" @@ -33,15 +33,15 @@ DEFAULT_JVM_OPTS="" # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { - echo "$*" +warn() { + echo "$*" } -die ( ) { - echo - echo "$*" - echo - exit 1 +die() { + echo + echo "$*" + echo + exit 1 } # OS specific support (must be 'true' or 'false'). @@ -49,114 +49,114 @@ cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$(uname)" in +CYGWIN*) + cygwin=true + ;; +Darwin*) + darwin=true + ;; +MINGW*) + msys=true + ;; +NONSTOP*) + nonstop=true + ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME +if [ -n "$JAVA_HOME" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ]; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." - fi + fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ]; then + MAX_FD_LIMIT=$(ulimit -H -n) + if [ $? -eq 0 ]; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ]; then + MAX_FD="$MAX_FD_LIMIT" fi + ulimit -n $MAX_FD + if [ $? -ne 0 ]; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi fi # For Darwin, add options to specify how the application appears in the dock if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi # For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" +if $cygwin; then + APP_HOME=$(cygpath --path --mixed "$APP_HOME") + CLASSPATH=$(cygpath --path --mixed "$CLASSPATH") + JAVACMD=$(cygpath --unix "$JAVACMD") + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=$(find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null) + SEP="" + for dir in $ROOTDIRSRAW; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ]; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@"; do + CHECK=$(echo "$arg" | egrep -c "$OURCYGPATTERN" -) + CHECK2=$(echo "$arg" | egrep -c "^-") ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ]; then ### Added a condition + eval $(echo args$i)=$(cygpath --path --ignore --mixed "$arg") + else + eval $(echo args$i)="\"$arg\"" fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac + i=$((i + 1)) + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac fi # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules function splitJvmOpts() { - JVM_OPTS=("$@") + JVM_OPTS=("$@") } eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" diff --git a/sample/build.gradle b/sample/build.gradle index dbed4d4e..15944d1b 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,14 +1,14 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 27 - buildToolsVersion "27.0.3" + compileSdkVersion 29 + buildToolsVersion '29.0.2' defaultConfig { applicationId "com.stfalcon.chatkit.sample" minSdkVersion 14 versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } buildTypes { release { @@ -21,37 +21,34 @@ android { abortOnError false } } -} -ext { - supportVersion = '27.1.1' - picassoVersion = '2.5.2' - circleImageViewVersion = '2.2.0' - shapeImageViewVersion = '0.9.3' - circleindicatorVersion = '1.2.2@aar' + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } dependencies { implementation project(':chatkit') implementation fileTree(dir: 'libs', include: ['*.jar']) - androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { + androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', { exclude group: 'com.android.support', module: 'support-annotations' }) - testImplementation 'junit:junit:4.12' + testImplementation 'junit:junit:4.13' - implementation "com.android.support:appcompat-v7:$supportVersion" - implementation "com.android.support:cardview-v7:$supportVersion" - implementation "com.android.support:design:$supportVersion" + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'androidx.cardview:cardview:1.0.0' + implementation 'com.google.android.material:material:1.2.1' //Picasso - implementation "com.squareup.picasso:picasso:$picassoVersion" + implementation "com.squareup.picasso:picasso:2.5.2" //ImageViews - implementation "de.hdodenhof:circleimageview:$circleImageViewVersion" - implementation "com.github.siyamed:android-shape-imageview:$shapeImageViewVersion" + implementation "de.hdodenhof:circleimageview:2.2.0" + implementation "com.github.siyamed:android-shape-imageview:0.9.3" //Utils - implementation "me.relex:circleindicator:$circleindicatorVersion" + implementation "me.relex:circleindicator:1.2.2@aar" } diff --git a/sample/src/androidTest/java/com/stfalcon/chatkit/sample/ExampleInstrumentedTest.java b/sample/src/androidTest/java/com/stfalcon/chatkit/sample/ExampleInstrumentedTest.java index 9ba761a3..ff85a942 100644 --- a/sample/src/androidTest/java/com/stfalcon/chatkit/sample/ExampleInstrumentedTest.java +++ b/sample/src/androidTest/java/com/stfalcon/chatkit/sample/ExampleInstrumentedTest.java @@ -1,13 +1,14 @@ package com.stfalcon.chatkit.sample; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; + +import androidx.test.InstrumentationRegistry; +import androidx.test.runner.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Instrumentation test, which will execute on an Android device. diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index e95c5cbb..6526cb56 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ + package="com.stfalcon.chatkit.sample"> - + - - + + + android:theme="@style/BlueTheme" /> - - - - - - + android:theme="@style/BlueTheme" /> + + + + + + + android:theme="@style/BlueTheme" /> diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoDialogsActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoDialogsActivity.java index 770db5e5..568379a1 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoDialogsActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoDialogsActivity.java @@ -1,9 +1,9 @@ package com.stfalcon.chatkit.sample.features.demo; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; -import android.widget.ImageView; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; import com.squareup.picasso.Picasso; import com.stfalcon.chatkit.commons.ImageLoader; @@ -25,12 +25,7 @@ public abstract class DemoDialogsActivity extends AppCompatActivity protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - imageLoader = new ImageLoader() { - @Override - public void loadImage(ImageView imageView, String url, Object payload) { - Picasso.with(DemoDialogsActivity.this).load(url).into(imageView); - } - }; + imageLoader = (imageView, url, payload) -> Picasso.with(DemoDialogsActivity.this).load(url).into(imageView); } @Override diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoMessagesActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoMessagesActivity.java index b58867cb..d2eaca59 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoMessagesActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoMessagesActivity.java @@ -2,12 +2,12 @@ import android.os.Bundle; import android.os.Handler; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.Menu; import android.view.MenuItem; -import android.widget.ImageView; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; import com.squareup.picasso.Picasso; import com.stfalcon.chatkit.commons.ImageLoader; @@ -43,12 +43,7 @@ public abstract class DemoMessagesActivity extends AppCompatActivity protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - imageLoader = new ImageLoader() { - @Override - public void loadImage(ImageView imageView, String url, Object payload) { - Picasso.with(DemoMessagesActivity.this).load(url).into(imageView); - } - }; + imageLoader = (imageView, url, payload) -> Picasso.with(DemoMessagesActivity.this).load(url).into(imageView); } @Override @@ -104,29 +99,24 @@ public void onSelectionChanged(int count) { } protected void loadMessages() { - new Handler().postDelayed(new Runnable() { //imitation of internet connection - @Override - public void run() { - ArrayList messages = MessagesFixtures.getMessages(lastLoadedDate); - lastLoadedDate = messages.get(messages.size() - 1).getCreatedAt(); - messagesAdapter.addToEnd(messages, false); - } + //imitation of internet connection + new Handler().postDelayed(() -> { + ArrayList messages = MessagesFixtures.getMessages(lastLoadedDate); + lastLoadedDate = messages.get(messages.size() - 1).getCreatedAt(); + messagesAdapter.addToEnd(messages, false); }, 1000); } private MessagesListAdapter.Formatter getMessageStringFormatter() { - return new MessagesListAdapter.Formatter() { - @Override - public String format(Message message) { - String createdAt = new SimpleDateFormat("MMM d, EEE 'at' h:mm a", Locale.getDefault()) - .format(message.getCreatedAt()); - - String text = message.getText(); - if (text == null) text = "[attachment]"; - - return String.format(Locale.getDefault(), "%s: %s (%s)", - message.getUser().getName(), text, createdAt); - } + return message -> { + String createdAt = new SimpleDateFormat("MMM d, EEE 'at' h:mm a", Locale.getDefault()) + .format(message.getCreatedAt()); + + String text = message.getText(); + if (text == null) text = "[attachment]"; + + return String.format(Locale.getDefault(), "%s: %s (%s)", + message.getUser().getName(), text, createdAt); }; } } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/CustomHolderDialogsActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/CustomHolderDialogsActivity.java index c08df41d..188aa038 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/CustomHolderDialogsActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/CustomHolderDialogsActivity.java @@ -25,7 +25,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_custom_holder_dialogs); - dialogsList = (DialogsList) findViewById(R.id.dialogsList); + dialogsList = findViewById(R.id.dialogsList); initAdapter(); } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/CustomHolderMessagesActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/CustomHolderMessagesActivity.java index 835dcf21..0a59d16f 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/CustomHolderMessagesActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/CustomHolderMessagesActivity.java @@ -35,10 +35,10 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_custom_holder_messages); - messagesList = (MessagesList) findViewById(R.id.messagesList); + messagesList = findViewById(R.id.messagesList); initAdapter(); - MessageInput input = (MessageInput) findViewById(R.id.input); + MessageInput input = findViewById(R.id.input); input.setInputListener(this); input.setAttachmentsListener(this); } @@ -65,13 +65,8 @@ private void initAdapter() { //We can pass any data to ViewHolder with payload CustomIncomingTextMessageViewHolder.Payload payload = new CustomIncomingTextMessageViewHolder.Payload(); //For example click listener - payload.avatarClickListener = new CustomIncomingTextMessageViewHolder.OnAvatarClickListener() { - @Override - public void onAvatarClick() { - Toast.makeText(CustomHolderMessagesActivity.this, - "Text message avatar clicked", Toast.LENGTH_SHORT).show(); - } - }; + payload.avatarClickListener = () -> Toast.makeText(CustomHolderMessagesActivity.this, + "Text message avatar clicked", Toast.LENGTH_SHORT).show(); MessageHolders holdersConfig = new MessageHolders() .setIncomingTextConfig( 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..fee813c1 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 @@ -29,12 +29,9 @@ public void onBind(Message message) { //We can set click listener on view from payload final Payload payload = (Payload) this.payload; - userAvatar.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (payload != null && payload.avatarClickListener != null) { - payload.avatarClickListener.onAvatarClick(); - } + userAvatar.setOnClickListener(view -> { + if (payload != null && payload.avatarClickListener != null) { + payload.avatarClickListener.onAvatarClick(); } }); } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/layout/CustomLayoutDialogsActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/layout/CustomLayoutDialogsActivity.java index b8bddf84..faaea0b3 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/layout/CustomLayoutDialogsActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/layout/CustomLayoutDialogsActivity.java @@ -24,7 +24,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_custom_layout_dialogs); - dialogsList = (DialogsList) findViewById(R.id.dialogsList); + dialogsList = findViewById(R.id.dialogsList); initAdapter(); } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/layout/CustomLayoutMessagesActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/layout/CustomLayoutMessagesActivity.java index d7d7c14f..12e7749b 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/layout/CustomLayoutMessagesActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/layout/CustomLayoutMessagesActivity.java @@ -30,10 +30,10 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_custom_layout_messages); - messagesList = (MessagesList) findViewById(R.id.messagesList); + messagesList = findViewById(R.id.messagesList); initAdapter(); - MessageInput input = (MessageInput) findViewById(R.id.input); + MessageInput input = findViewById(R.id.input); input.setInputListener(this); input.setAttachmentsListener(this); } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/CustomMediaMessagesActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/CustomMediaMessagesActivity.java index 7f3ae57f..caf47d13 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/CustomMediaMessagesActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/CustomMediaMessagesActivity.java @@ -36,10 +36,10 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_custom_media_messages); - this.messagesList = (MessagesList) findViewById(R.id.messagesList); + this.messagesList = findViewById(R.id.messagesList); initAdapter(); - MessageInput input = (MessageInput) findViewById(R.id.input); + MessageInput input = findViewById(R.id.input); input.setInputListener(this); input.setAttachmentsListener(this); } @@ -60,11 +60,10 @@ public void onAddAttachments() { @Override public boolean hasContentFor(Message message, byte type) { - switch (type) { - case CONTENT_TYPE_VOICE: - return message.getVoice() != null - && message.getVoice().getUrl() != null - && !message.getVoice().getUrl().isEmpty(); + if (type == CONTENT_TYPE_VOICE) { + return message.getVoice() != null + && message.getVoice().getUrl() != null + && !message.getVoice().getUrl().isEmpty(); } return false; } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/holders/IncomingVoiceMessageViewHolder.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/holders/IncomingVoiceMessageViewHolder.java index 80c64b5b..bdacb34a 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/holders/IncomingVoiceMessageViewHolder.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/holders/IncomingVoiceMessageViewHolder.java @@ -20,8 +20,8 @@ public class IncomingVoiceMessageViewHolder public IncomingVoiceMessageViewHolder(View itemView, Object payload) { super(itemView, payload); - tvDuration = (TextView) itemView.findViewById(R.id.duration); - tvTime = (TextView) itemView.findViewById(R.id.time); + tvDuration = itemView.findViewById(R.id.duration); + tvTime = itemView.findViewById(R.id.time); } @Override diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/holders/OutcomingVoiceMessageViewHolder.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/holders/OutcomingVoiceMessageViewHolder.java index 6d3dcbf8..b21db7d7 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/holders/OutcomingVoiceMessageViewHolder.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/media/holders/OutcomingVoiceMessageViewHolder.java @@ -20,8 +20,8 @@ public class OutcomingVoiceMessageViewHolder public OutcomingVoiceMessageViewHolder(View itemView, Object payload) { super(itemView, payload); - tvDuration = (TextView) itemView.findViewById(R.id.duration); - tvTime = (TextView) itemView.findViewById(R.id.time); + tvDuration = itemView.findViewById(R.id.duration); + tvTime = itemView.findViewById(R.id.time); } @Override diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultDialogsActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultDialogsActivity.java index 59c9cb4c..c88a3771 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultDialogsActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultDialogsActivity.java @@ -25,7 +25,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_default_dialogs); - dialogsList = (DialogsList) findViewById(R.id.dialogsList); + dialogsList = findViewById(R.id.dialogsList); initAdapter(); } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java index f13b839f..a74bca89 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/def/DefaultMessagesActivity.java @@ -4,14 +4,12 @@ import android.content.Intent; import android.os.Bundle; import android.util.Log; -import android.view.View; import com.stfalcon.chatkit.messages.MessageInput; import com.stfalcon.chatkit.messages.MessagesList; import com.stfalcon.chatkit.messages.MessagesListAdapter; import com.stfalcon.chatkit.sample.R; import com.stfalcon.chatkit.sample.common.data.fixtures.MessagesFixtures; -import com.stfalcon.chatkit.sample.common.data.model.Message; import com.stfalcon.chatkit.sample.features.demo.DemoMessagesActivity; import com.stfalcon.chatkit.sample.utils.AppUtils; @@ -31,10 +29,10 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_default_messages); - this.messagesList = (MessagesList) findViewById(R.id.messagesList); + this.messagesList = findViewById(R.id.messagesList); initAdapter(); - MessageInput input = (MessageInput) findViewById(R.id.input); + MessageInput input = findViewById(R.id.input); input.setInputListener(this); input.setTypingListener(this); input.setAttachmentsListener(this); @@ -58,14 +56,9 @@ private void initAdapter() { super.messagesAdapter.enableSelectionMode(this); super.messagesAdapter.setLoadMoreListener(this); super.messagesAdapter.registerViewClickListener(R.id.messageUserAvatar, - new MessagesListAdapter.OnMessageViewClickListener() { - @Override - public void onMessageViewClick(View view, Message message) { - AppUtils.showToast(DefaultMessagesActivity.this, - message.getUser().getName() + " avatar click", - false); - } - }); + (view, message) -> AppUtils.showToast(DefaultMessagesActivity.this, + message.getUser().getName() + " avatar click", + false)); this.messagesList.setAdapter(super.messagesAdapter); } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/styled/StyledDialogsActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/styled/StyledDialogsActivity.java index 1d8d2865..eb0acc9d 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/styled/StyledDialogsActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/styled/StyledDialogsActivity.java @@ -28,7 +28,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_styled_dialogs); - dialogsList = (DialogsList) findViewById(R.id.dialogsList); + dialogsList = findViewById(R.id.dialogsList); initAdapter(); } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/styled/StyledMessagesActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/styled/StyledMessagesActivity.java index ba01566a..e97ecec0 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/styled/StyledMessagesActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/styled/StyledMessagesActivity.java @@ -30,10 +30,10 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_styled_messages); - messagesList = (MessagesList) findViewById(R.id.messagesList); + messagesList = findViewById(R.id.messagesList); initAdapter(); - MessageInput input = (MessageInput) findViewById(R.id.input); + MessageInput input = findViewById(R.id.input); input.setInputListener(this); input.setAttachmentsListener(this); } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/main/MainActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/main/MainActivity.java index 8a49e160..b05896ce 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/main/MainActivity.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/main/MainActivity.java @@ -1,8 +1,9 @@ package com.stfalcon.chatkit.sample.features.main; import android.os.Bundle; -import android.support.v4.view.ViewPager; -import android.support.v7.app.AppCompatActivity; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.viewpager.widget.ViewPager; import com.stfalcon.chatkit.sample.R; import com.stfalcon.chatkit.sample.features.demo.custom.holder.CustomHolderDialogsActivity; @@ -26,12 +27,12 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - ViewPager pager = (ViewPager) findViewById(R.id.pager); + ViewPager pager = findViewById(R.id.pager); pager.setAdapter(new MainActivityPagerAdapter(this, getSupportFragmentManager())); pager.setPageMargin((int) getResources().getDimension(R.dimen.card_padding) / 4); pager.setOffscreenPageLimit(3); - CircleIndicator indicator = (CircleIndicator) findViewById(R.id.indicator); + CircleIndicator indicator = findViewById(R.id.indicator); indicator.setViewPager(pager); } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/main/adapter/DemoCardFragment.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/main/adapter/DemoCardFragment.java index 8d4054fd..c8779198 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/main/adapter/DemoCardFragment.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/main/adapter/DemoCardFragment.java @@ -2,13 +2,14 @@ import android.content.Context; import android.os.Bundle; -import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; +import androidx.fragment.app.Fragment; + import com.stfalcon.chatkit.sample.R; /* @@ -54,9 +55,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_demo_card, container, false); - TextView tvTitle = (TextView) v.findViewById(R.id.tvTitle); - TextView tvDescription = (TextView) v.findViewById(R.id.tvDescription); - Button button = (Button) v.findViewById(R.id.button); + TextView tvTitle = v.findViewById(R.id.tvTitle); + TextView tvDescription = v.findViewById(R.id.tvDescription); + Button button = v.findViewById(R.id.button); tvTitle.setText(title); tvDescription.setText(description); @@ -67,10 +68,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, @Override public void onClick(View view) { - switch (view.getId()) { - case R.id.button: - onAction(); - break; + if (view.getId() == R.id.button) { + onAction(); } } diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/main/adapter/MainActivityPagerAdapter.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/main/adapter/MainActivityPagerAdapter.java index bfab5867..c1e01097 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/main/adapter/MainActivityPagerAdapter.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/main/adapter/MainActivityPagerAdapter.java @@ -1,9 +1,10 @@ package com.stfalcon.chatkit.sample.features.main.adapter; import android.content.Context; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentStatePagerAdapter; + +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentStatePagerAdapter; import com.stfalcon.chatkit.sample.R; diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/utils/AppUtils.java b/sample/src/main/java/com/stfalcon/chatkit/sample/utils/AppUtils.java index 8c914dfd..ca49edef 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/utils/AppUtils.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/utils/AppUtils.java @@ -1,9 +1,10 @@ package com.stfalcon.chatkit.sample.utils; import android.content.Context; -import android.support.annotation.StringRes; import android.widget.Toast; +import androidx.annotation.StringRes; + /* * Created by troy379 on 04.04.17. */ diff --git a/sample/src/main/res/drawable/dark_blue_top_gradient.xml b/sample/src/main/res/drawable/dark_blue_top_gradient.xml index fbfded4c..06162093 100644 --- a/sample/src/main/res/drawable/dark_blue_top_gradient.xml +++ b/sample/src/main/res/drawable/dark_blue_top_gradient.xml @@ -1,9 +1,9 @@ + android:shape="rectangle"> + android:startColor="@color/cornflower_blue_darkest" /> \ No newline at end of file diff --git a/sample/src/main/res/drawable/ic_play_black.xml b/sample/src/main/res/drawable/ic_play_black.xml index fd5de4d8..1a348327 100644 --- a/sample/src/main/res/drawable/ic_play_black.xml +++ b/sample/src/main/res/drawable/ic_play_black.xml @@ -1,5 +1,4 @@ - + android:pathData="M3,1.5v14l11,-7z" /> diff --git a/sample/src/main/res/drawable/ic_play_white.xml b/sample/src/main/res/drawable/ic_play_white.xml index cf96f070..4196f11a 100644 --- a/sample/src/main/res/drawable/ic_play_white.xml +++ b/sample/src/main/res/drawable/ic_play_white.xml @@ -1,5 +1,4 @@ - + android:pathData="M3,1.5v14l11,-7z" /> diff --git a/sample/src/main/res/drawable/shape_bubble_offline.xml b/sample/src/main/res/drawable/shape_bubble_offline.xml index d1cc3c34..219d82d1 100644 --- a/sample/src/main/res/drawable/shape_bubble_offline.xml +++ b/sample/src/main/res/drawable/shape_bubble_offline.xml @@ -1,13 +1,13 @@ + android:shape="oval"> - + + android:color="@color/white" /> + android:height="20dp" /> \ No newline at end of file diff --git a/sample/src/main/res/drawable/shape_bubble_online.xml b/sample/src/main/res/drawable/shape_bubble_online.xml index 9b1bbe94..2b5f2386 100644 --- a/sample/src/main/res/drawable/shape_bubble_online.xml +++ b/sample/src/main/res/drawable/shape_bubble_online.xml @@ -1,13 +1,13 @@ + android:shape="oval"> - + + android:color="@color/white" /> + android:height="20dp" /> \ No newline at end of file diff --git a/sample/src/main/res/drawable/shape_custom_cursor.xml b/sample/src/main/res/drawable/shape_custom_cursor.xml index c60888f9..ece0b260 100644 --- a/sample/src/main/res/drawable/shape_custom_cursor.xml +++ b/sample/src/main/res/drawable/shape_custom_cursor.xml @@ -1,8 +1,8 @@ + android:shape="rectangle"> - + - + \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_custom_holder_dialogs.xml b/sample/src/main/res/layout/activity_custom_holder_dialogs.xml index 81eb8ecd..0359eb85 100644 --- a/sample/src/main/res/layout/activity_custom_holder_dialogs.xml +++ b/sample/src/main/res/layout/activity_custom_holder_dialogs.xml @@ -1,5 +1,4 @@ - + app:dialogUnreadTitleTextStyle="bold" /> diff --git a/sample/src/main/res/layout/activity_custom_holder_messages.xml b/sample/src/main/res/layout/activity_custom_holder_messages.xml index 88c6d1cc..723bca6c 100644 --- a/sample/src/main/res/layout/activity_custom_holder_messages.xml +++ b/sample/src/main/res/layout/activity_custom_holder_messages.xml @@ -1,5 +1,4 @@ - + app:outcomingTimeTextColor="@color/gray_dark_transparent" /> + android:background="@color/gray_light" /> + app:showAttachmentButton="true" /> \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_custom_layout_dialogs.xml b/sample/src/main/res/layout/activity_custom_layout_dialogs.xml index 81eb8ecd..0359eb85 100644 --- a/sample/src/main/res/layout/activity_custom_layout_dialogs.xml +++ b/sample/src/main/res/layout/activity_custom_layout_dialogs.xml @@ -1,5 +1,4 @@ - + app:dialogUnreadTitleTextStyle="bold" /> diff --git a/sample/src/main/res/layout/activity_custom_layout_messages.xml b/sample/src/main/res/layout/activity_custom_layout_messages.xml index 88c6d1cc..723bca6c 100644 --- a/sample/src/main/res/layout/activity_custom_layout_messages.xml +++ b/sample/src/main/res/layout/activity_custom_layout_messages.xml @@ -1,5 +1,4 @@ - + app:outcomingTimeTextColor="@color/gray_dark_transparent" /> + android:background="@color/gray_light" /> + app:showAttachmentButton="true" /> \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_custom_media_messages.xml b/sample/src/main/res/layout/activity_custom_media_messages.xml index 9ce4da57..85e7db97 100644 --- a/sample/src/main/res/layout/activity_custom_media_messages.xml +++ b/sample/src/main/res/layout/activity_custom_media_messages.xml @@ -1,5 +1,4 @@ - + android:layout_above="@+id/input" /> + android:background="@color/gray_light" /> + app:showAttachmentButton="true" /> \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_default_dialogs.xml b/sample/src/main/res/layout/activity_default_dialogs.xml index bb5e9436..a14ac43c 100644 --- a/sample/src/main/res/layout/activity_default_dialogs.xml +++ b/sample/src/main/res/layout/activity_default_dialogs.xml @@ -1,5 +1,4 @@ - @@ -7,6 +6,6 @@ + android:layout_height="match_parent" /> diff --git a/sample/src/main/res/layout/activity_default_messages.xml b/sample/src/main/res/layout/activity_default_messages.xml index 9ce4da57..85e7db97 100644 --- a/sample/src/main/res/layout/activity_default_messages.xml +++ b/sample/src/main/res/layout/activity_default_messages.xml @@ -1,5 +1,4 @@ - + android:layout_above="@+id/input" /> + android:background="@color/gray_light" /> + app:showAttachmentButton="true" /> \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index a831f0b8..a84a40bf 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -1,5 +1,4 @@ - @@ -8,7 +7,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/dark_blue_top_gradient" - android:fitsSystemWindows="true"/> + android:fitsSystemWindows="true" /> + android:textSize="28sp" /> - + android:paddingRight="@dimen/card_padding" + android:paddingBottom="20dp" /> + android:layout_alignParentBottom="true" /> - \ No newline at end of file + \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_styled_dialogs.xml b/sample/src/main/res/layout/activity_styled_dialogs.xml index 81eb8ecd..0359eb85 100644 --- a/sample/src/main/res/layout/activity_styled_dialogs.xml +++ b/sample/src/main/res/layout/activity_styled_dialogs.xml @@ -1,5 +1,4 @@ - + app:dialogUnreadTitleTextStyle="bold" /> diff --git a/sample/src/main/res/layout/activity_styled_messages.xml b/sample/src/main/res/layout/activity_styled_messages.xml index 62e217d3..9e2111d2 100644 --- a/sample/src/main/res/layout/activity_styled_messages.xml +++ b/sample/src/main/res/layout/activity_styled_messages.xml @@ -1,5 +1,4 @@ - + app:textAutoLink="all" /> + android:background="@color/gray_light" /> + app:showAttachmentButton="true" /> \ 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..11841c1a 100644 --- a/sample/src/main/res/layout/fragment_demo_card.xml +++ b/sample/src/main/res/layout/fragment_demo_card.xml @@ -1,5 +1,4 @@ - + android:textSize="22sp" /> + android:textSize="15sp" />