From 8f4dce5da177b163ceec2bbb1156f5e9342831dd Mon Sep 17 00:00:00 2001 From: Vitalii Bonar Date: Wed, 21 Feb 2018 19:33:21 +0200 Subject: [PATCH] Change dialog model --- .../stfalcon/chatkit/commons/models/IDialog.java | 4 +--- .../chatkit/dialogs/DialogsListAdapter.java | 2 +- .../common/data/fixtures/DialogsFixtures.java | 4 ++-- .../chatkit/sample/common/data/model/Dialog.java | 14 +++++--------- .../holders/dialogs/CustomDialogViewHolder.java | 4 ++-- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IDialog.java b/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IDialog.java index 661c76e8..9462e6aa 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IDialog.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IDialog.java @@ -16,8 +16,6 @@ package com.stfalcon.chatkit.commons.models; -import java.util.List; - /** * For implementing by real dialog model */ @@ -30,7 +28,7 @@ public interface IDialog { String getDialogName(); - List getUsers(); + int getUsersCount(); MESSAGE getLastMessage(); 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..c683c85c 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -600,7 +600,7 @@ public void onBind(final DIALOG dialog) { imageLoader.loadImage(ivLastMessageUser, dialog.getLastMessage().getUser().getAvatar()); } ivLastMessageUser.setVisibility(dialogStyle.isDialogMessageAvatarEnabled() - && dialog.getUsers().size() > 1 ? VISIBLE : GONE); + && dialog.getUsersCount() > 1 ? VISIBLE : GONE); //Set Last message text tvLastMessage.setText(dialog.getLastMessage().getText()); diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/common/data/fixtures/DialogsFixtures.java b/sample/src/main/java/com/stfalcon/chatkit/sample/common/data/fixtures/DialogsFixtures.java index b7505404..58c646a6 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/common/data/fixtures/DialogsFixtures.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/common/data/fixtures/DialogsFixtures.java @@ -36,9 +36,9 @@ private static Dialog getDialog(int i, Date lastMessageCreatedAt) { getRandomId(), users.size() > 1 ? groupChatTitles.get(users.size() - 2) : users.get(0).getName(), users.size() > 1 ? groupChatImages.get(users.size() - 2) : getRandomAvatar(), - users, getMessage(lastMessageCreatedAt), - i < 3 ? 3 - i : 0); + i < 3 ? 3 - i : 0, + users.size()); } private static ArrayList getUsers() { 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 7f239df6..d303b10b 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 @@ -2,8 +2,6 @@ import com.stfalcon.chatkit.commons.models.IDialog; -import java.util.ArrayList; - /* * Created by troy379 on 04.04.17. */ @@ -12,20 +10,18 @@ public class Dialog implements IDialog { private String id; private String dialogPhoto; private String dialogName; - private ArrayList users; private Message lastMessage; + private int usersCount; private int unreadCount; - public Dialog(String id, String name, String photo, - ArrayList users, Message lastMessage, int unreadCount) { - + public Dialog(String id, String name, String photo, Message lastMessage, int unreadCount, int usersCount) { this.id = id; this.dialogName = name; this.dialogPhoto = photo; - this.users = users; this.lastMessage = lastMessage; this.unreadCount = unreadCount; + this.usersCount = usersCount; } @Override @@ -44,8 +40,8 @@ public String getDialogName() { } @Override - public ArrayList getUsers() { - return users; + public int getUsersCount() { + return usersCount; } @Override diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/dialogs/CustomDialogViewHolder.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/dialogs/CustomDialogViewHolder.java index ba22f69a..a9e9b178 100644 --- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/dialogs/CustomDialogViewHolder.java +++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/custom/holder/holders/dialogs/CustomDialogViewHolder.java @@ -23,10 +23,10 @@ public CustomDialogViewHolder(View itemView) { public void onBind(Dialog dialog) { super.onBind(dialog); - if (dialog.getUsers().size() > 1) { + if (dialog.getUsersCount() > 1) { onlineIndicator.setVisibility(View.GONE); } else { - boolean isOnline = dialog.getUsers().get(0).isOnline(); + boolean isOnline = dialog.getLastMessage().getUser().isOnline(); onlineIndicator.setVisibility(View.VISIBLE); if (isOnline) { onlineIndicator.setBackgroundResource(R.drawable.shape_bubble_online);