Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ import chat.rocket.android.util.extensions.toList
import chat.rocket.core.model.Message
import chat.rocket.core.model.isSystemMessage
import com.google.android.flexbox.FlexDirection
import com.google.android.flexbox.FlexWrap
import com.google.android.flexbox.FlexboxLayoutManager
import com.google.android.flexbox.JustifyContent

abstract class BaseViewHolder<T : BaseUiModel<*>>(
itemView: View,
private val listener: ActionsListener,
private val listener: ActionsListener? = null,
var reactionListener: EmojiReactionListener? = null
) : RecyclerView.ViewHolder(itemView),
MenuItem.OnMenuItemClickListener {
Expand Down Expand Up @@ -63,7 +62,7 @@ abstract class BaseViewHolder<T : BaseUiModel<*>>(
}

override fun onReactionLongClicked(shortname: String, isCustom: Boolean, url: String?, usernames: List<String>) {
reactionListener?.onReactionLongClicked(shortname, isCustom,url, usernames)
reactionListener?.onReactionLongClicked(shortname, isCustom, url, usernames)
}
}

Expand Down Expand Up @@ -119,7 +118,7 @@ abstract class BaseViewHolder<T : BaseUiModel<*>>(
}

internal fun setupActionMenu(view: View) {
if (listener.isActionsEnabled()) {
if (listener?.isActionsEnabled() == true) {
view.setOnClickListener(onClickListener)
if (view is ViewGroup) {
for (child in view.children) {
Expand All @@ -133,7 +132,7 @@ abstract class BaseViewHolder<T : BaseUiModel<*>>(

override fun onMenuItemClick(item: MenuItem): Boolean {
data?.let {
listener.onActionSelected(item, it.message)
listener?.onActionSelected(item, it.message)
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import chat.rocket.android.chatroom.uimodel.AttachmentUiModel
import chat.rocket.android.chatroom.uimodel.BaseUiModel
import chat.rocket.android.chatroom.uimodel.MessageReplyUiModel
import chat.rocket.android.chatroom.uimodel.MessageUiModel
import chat.rocket.android.chatroom.uimodel.SystemMessageUiModel
import chat.rocket.android.chatroom.uimodel.UrlPreviewUiModel
import chat.rocket.android.chatroom.uimodel.toViewType
import chat.rocket.android.emoji.EmojiReactionListener
Expand All @@ -24,7 +25,6 @@ import chat.rocket.core.model.attachment.actions.Action
import chat.rocket.core.model.attachment.actions.ButtonAction
import chat.rocket.core.model.isSystemMessage
import timber.log.Timber
import java.security.InvalidParameterException

class ChatRoomAdapter(
private val roomId: String? = null,
Expand All @@ -49,6 +49,13 @@ class ChatRoomAdapter(
MessageViewHolder(
view,
actionsListener,
reactionListener
) { userId -> navigator?.toUserDetails(userId) }
}
BaseUiModel.ViewType.SYSTEM_MESSAGE -> {
val view = parent.inflate(R.layout.item_system_message)
SystemMessageViewHolder(
view,
reactionListener,
{ userId -> navigator?.toUserDetails(userId) },
{
Expand Down Expand Up @@ -81,9 +88,6 @@ class ChatRoomAdapter(
actionSelectListener?.openDirectMessage(roomName, permalink)
}
}
else -> {
throw InvalidParameterException("TODO - implement for ${viewType.toViewType()}")
}
}
}

Expand Down Expand Up @@ -112,13 +116,14 @@ class ChatRoomAdapter(
when (holder) {
is MessageViewHolder ->
holder.bind(dataSet[position] as MessageUiModel)
is UrlPreviewViewHolder -> {
is SystemMessageViewHolder ->
holder.bind(dataSet[position] as SystemMessageUiModel)
is UrlPreviewViewHolder ->
holder.bind(dataSet[position] as UrlPreviewUiModel)
}
is MessageReplyViewHolder ->
holder.bind(dataSet[position] as MessageReplyUiModel)
is AttachmentViewHolder ->
holder.bind(dataSet[position] as AttachmentUiModel)
is MessageReplyViewHolder ->
holder.bind(dataSet[position] as MessageReplyUiModel)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.core.view.isVisible
import chat.rocket.android.R
import chat.rocket.android.chatroom.uimodel.MessageUiModel
import chat.rocket.android.emoji.EmojiReactionListener
import chat.rocket.core.model.MessageType
import chat.rocket.core.model.isSystemMessage
import com.bumptech.glide.load.resource.gif.GifDrawable
import kotlinx.android.synthetic.main.avatar.view.*
Expand All @@ -20,8 +19,7 @@ class MessageViewHolder(
itemView: View,
listener: ActionsListener,
reactionListener: EmojiReactionListener? = null,
private val avatarListener: (String) -> Unit,
private val joinVideoCallListener: (View) -> Unit
private val avatarListener: (String) -> Unit
) : BaseViewHolder<MessageUiModel>(itemView, listener, reactionListener), Drawable.Callback {

init {
Expand Down Expand Up @@ -53,9 +51,6 @@ class MessageViewHolder(

text_content.text_content.text = data.content

button_join_video_call.isVisible = data.message.type is MessageType.JitsiCallStarted
button_join_video_call.setOnClickListener { joinVideoCallListener(it) }

image_avatar.setImageURI(data.avatar)
text_content.setTextColor(if (data.isTemporary) Color.GRAY else Color.BLACK)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package chat.rocket.android.chatroom.adapter

import android.graphics.Color
import android.text.method.LinkMovementMethod
import android.view.View
import androidx.core.view.isVisible
import chat.rocket.android.chatroom.uimodel.SystemMessageUiModel
import chat.rocket.android.emoji.EmojiReactionListener
import chat.rocket.core.model.MessageType
import kotlinx.android.synthetic.main.avatar.view.*
import kotlinx.android.synthetic.main.item_system_message.view.*

class SystemMessageViewHolder(
itemView: View,
reactionListener: EmojiReactionListener? = null,
private val avatarListener: (String) -> Unit,
private val joinVideoCallListener: (View) -> Unit
) : BaseViewHolder<SystemMessageUiModel>(itemView, null, reactionListener) {

init {
with(itemView) {
setupActionMenu(message_container)
text_content.movementMethod = LinkMovementMethod()
}
}

override fun bindViews(data: SystemMessageUiModel) {
with(itemView) {
day.text = data.currentDayMarkerText
day_marker_layout.isVisible = data.showDayMarker

new_messages_notif.isVisible = data.isFirstUnread

text_sender.text = data.senderName
text_content.text_content.text = data.content

button_join_video_call.isVisible = data.message.type is MessageType.JitsiCallStarted
button_join_video_call.setOnClickListener { joinVideoCallListener(it) }

image_avatar.setImageURI(data.avatar)
text_content.setTextColor(if (data.isTemporary) Color.GRAY else Color.BLACK)

setOnClickListener {
data.message.sender?.id?.let { userId ->
avatarListener(userId)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ class ChatRoomPresenter @Inject constructor(
)
}


/*FIXME: Get chat role can cause unresponsive problems especially on slower connections
We are updating the room again after the first step so that initial messages
get loaded in and the system appears more responsive. Something should be
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package chat.rocket.android.chatroom.uimodel

import chat.rocket.android.R
import chat.rocket.core.model.Message

data class SystemMessageUiModel(
override val message: Message,
override val rawData: Message,
override val messageId: String,
override val avatar: String,
override val time: CharSequence,
override val senderName: CharSequence,
override val content: CharSequence,
override val isPinned: Boolean,
override var currentDayMarkerText: String,
override var showDayMarker: Boolean,
override var reactions: List<ReactionUiModel>,
override var nextDownStreamMessage: BaseUiModel<*>? = null,
override var preview: Message? = null,
override var unread: Boolean? = null,
var isFirstUnread: Boolean,
override var isTemporary: Boolean = false,
override var menuItemsToHide: MutableList<Int> = mutableListOf(),
override var permalink: String,
val subscriptionId: String
) : BaseMessageUiModel<Message> {
override val viewType: Int
get() = BaseUiModel.ViewType.SYSTEM_MESSAGE.viewType
override val layoutId: Int
get() = R.layout.item_system_message
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,23 @@ class UiModelMapper @Inject constructor(
list.addAll(it)
}

mapMessage(message, chatRoom).let {
if (list.isNotEmpty()) {
it.preview = list.first().preview
if (message.isSystemMessage()) {
mapSystemMessage(message, chatRoom).let {
if (list.isNotEmpty()) {
it.preview = list.first().preview
}
list.add(it)
}
} else {
mapMessage(message, chatRoom).let {
if (list.isNotEmpty()) {
it.preview = list.first().preview
}
list.add(it)
}
list.add(it)
}
}


for (i in list.size - 1 downTo 0) {
val next = if (i - 1 < 0) null else list[i - 1]
list[i].nextDownStreamMessage = next
Expand Down Expand Up @@ -217,11 +225,20 @@ class UiModelMapper @Inject constructor(
val list = ArrayList<BaseUiModel<*>>()

getChatRoomAsync(message.roomId)?.let { chatRoom ->
mapMessage(message, chatRoom).let {
if (list.isNotEmpty()) {
it.preview = list.first().preview
if (message.isSystemMessage()) {
mapSystemMessage(message, chatRoom).let {
if (list.isNotEmpty()) {
it.preview = list.first().preview
}
list.add(it)
}
} else {
mapMessage(message, chatRoom).let {
if (list.isNotEmpty()) {
it.preview = list.first().preview
}
list.add(it)
}
list.add(it)
}

message.attachments?.forEach {
Expand Down Expand Up @@ -268,6 +285,34 @@ class UiModelMapper @Inject constructor(
senderUsername != currentUsername
}

private suspend fun mapSystemMessage(
message: Message,
chatRoom: ChatRoom
): SystemMessageUiModel = withContext(Dispatchers.IO) {
val sender = getSenderName(message)
val time = getTime(message.timestamp)
val avatar = getUserAvatar(message)
val preview = mapMessagePreview(message)
val synced = message.synced
val unread = if (settings.messageReadReceiptEnabled()) {
message.unread ?: false
} else {
null
}

val localDateTime = DateTimeHelper.getLocalDateTime(message.timestamp)
val dayMarkerText = DateTimeHelper.getFormattedDateForMessages(localDateTime, context)
val permalink = messageHelper.createPermalink(message, chatRoom, false)

val content = getContent(stripMessageQuotes(message))
SystemMessageUiModel(message = stripMessageQuotes(message), rawData = message,
messageId = message.id, avatar = avatar!!, time = time, senderName = sender,
content = content, isPinned = message.pinned, currentDayMarkerText = dayMarkerText,
showDayMarker = false, reactions = getReactions(message), isFirstUnread = false,
preview = preview, isTemporary = !synced, unread = unread, permalink = permalink,
subscriptionId = chatRoom.subscriptionId)
}

private fun mapMessageReply(message: Message, chatRoom: ChatRoom): MessageReplyUiModel {
val name = message.sender?.name
val roomName =
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/res/layout/avatar.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="match_parent">

<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/image_avatar"
android:layout_width="40dp"
android:layout_height="40dp"
app:roundedCornerRadius="3dp" />

</LinearLayout>
</FrameLayout>
13 changes: 13 additions & 0 deletions app/src/main/res/layout/avatar_small.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/image_avatar"
android:layout_width="20dp"
android:layout_height="20dp"
app:roundedCornerRadius="1.5dp" />

</FrameLayout>
1 change: 0 additions & 1 deletion app/src/main/res/layout/item_file_attachment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
android:paddingEnd="@dimen/screen_edge_left_and_right_padding"
android:paddingStart="@dimen/screen_edge_left_and_right_padding">


<TextView
android:id="@+id/text_file_name"
android:layout_width="0dp"
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/item_generic_attachment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
android:visibility="gone" />
</LinearLayout>


<TextView
android:id="@+id/text_file_name"
android:layout_width="0dp"
Expand Down
12 changes: 1 addition & 11 deletions app/src/main/res/layout/item_message.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:maxLength="22"
tools:text="User Name with long name" />
tools:text="UserNameWithVeryLongName" />

<TextView
android:id="@+id/text_message_time"
Expand Down Expand Up @@ -158,16 +158,6 @@
app:layout_constraintTop_toBottomOf="@+id/message_header"
tools:text="This is a multiline chat message from Bertie that will take more than just one line of text. I have made sure that everything is amazing!" />

<Button
android:id="@+id/button_join_video_call"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:text="@string/msg_join_video_call"
android:visibility="gone"
app:layout_constraintStart_toStartOf="@+id/text_content"
app:layout_constraintTop_toBottomOf="@+id/text_content" />

<include
layout="@layout/layout_reactions"
android:layout_width="0dp"
Expand Down
Loading