Fix various layout issues in chat

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2020-04-07 10:54:01 +02:00
parent 16102774f5
commit a4363f01ec
No known key found for this signature in database
GPG Key ID: CDE0BBD2738C4CC0
7 changed files with 120 additions and 102 deletions

View File

@ -46,6 +46,7 @@ open class ChatPresenter<T : Any>(context: Context, private val onElementClickPa
override fun onBind(page: Page, holder: Holder, element: Element<T>, payloads: List<Any>) { override fun onBind(page: Page, holder: Holder, element: Element<T>, payloads: List<Any>) {
super.onBind(page, holder, element, payloads) super.onBind(page, holder, element, payloads)
holder.itemView.setOnLongClickListener { holder.itemView.setOnLongClickListener {
onElementLongClick?.invoke(page, holder, element, mapOf()) onElementLongClick?.invoke(page, holder, element, mapOf())
true true
@ -64,10 +65,24 @@ open class ChatPresenter<T : Any>(context: Context, private val onElementClickPa
val elementType = chatElement!!.elementType val elementType = chatElement!!.elementType
chatMessage.let { chatMessage.let {
if (elementType == ChatElementTypes.CHAT_MESSAGE) { if (elementType == ChatElementTypes.CHAT_MESSAGE) {
holder.itemView.authorName?.text = it.actorDisplayName var shouldShowNameAndAvatar = true
val previousElement = getAdapter().elementAt(holder.adapterPosition - 1)
if (previousElement != null && previousElement.element.data != null && previousElement.element.data is ChatElement) {
val previousChatElement = previousElement.element.data as ChatElement
if (previousChatElement.elementType == ChatElementTypes.CHAT_MESSAGE) {
val previousChatMessage = previousChatElement.data as ChatMessage
if (previousChatMessage.actorId == it.actorId) {
shouldShowNameAndAvatar = false
}
}
}
holder.itemView.messageTime?.text = DateFormatter.format(it.createdAt, DateFormatter.Template.TIME) holder.itemView.messageTime?.text = DateFormatter.format(it.createdAt, DateFormatter.Template.TIME)
holder.itemView.chatMessage.text = it.text holder.itemView.chatMessage.text = it.text
if (shouldShowNameAndAvatar) {
holder.itemView.authorLayout.isVisible = true
holder.itemView.authorName?.text = it.actorDisplayName
if (it.actorType == "bots" && it.actorId == "changelog") { if (it.actorType == "bots" && it.actorId == "changelog") {
val layers = arrayOfNulls<Drawable>(2) val layers = arrayOfNulls<Drawable>(2)
layers[0] = context.getDrawable(R.drawable.ic_launcher_background) layers[0] = context.getDrawable(R.drawable.ic_launcher_background)
@ -89,6 +104,9 @@ open class ChatPresenter<T : Any>(context: Context, private val onElementClickPa
} else { } else {
imageLoader.loadImage(holder.itemView.authorAvatar, it.user.avatar) imageLoader.loadImage(holder.itemView.authorAvatar, it.user.avatar)
} }
} else {
holder.itemView.authorLayout.isVisible = false
}
it.parentMessage?.let { parentMessage -> it.parentMessage?.let { parentMessage ->
holder.itemView.quotedMessageLayout.isVisible = true holder.itemView.quotedMessageLayout.isVisible = true
@ -173,5 +191,5 @@ open class ChatPresenter<T : Any>(context: Context, private val onElementClickPa
holder.itemView.noticeText.text = (element.data as HeaderSource.Data<*, *>).header.toString() holder.itemView.noticeText.text = (element.data as HeaderSource.Data<*, *>).header.toString()
} }
} }
} }
} }

View File

@ -31,6 +31,7 @@ import androidx.lifecycle.viewModelScope
import coil.Coil import coil.Coil
import coil.api.get import coil.api.get
import coil.transform.CircleCropTransformation import coil.transform.CircleCropTransformation
import com.nextcloud.talk.R
import com.nextcloud.talk.models.json.conversations.Conversation import com.nextcloud.talk.models.json.conversations.Conversation
import com.nextcloud.talk.models.json.generic.GenericOverall import com.nextcloud.talk.models.json.generic.GenericOverall
import com.nextcloud.talk.newarch.conversationsList.mvp.BaseViewModel import com.nextcloud.talk.newarch.conversationsList.mvp.BaseViewModel
@ -178,7 +179,7 @@ class ConversationsListViewModel (
operationUser?.let { operationUser?.let {
viewModelScope.launch { viewModelScope.launch {
val url = ApiUtils.getUrlForAvatarWithNameAndPixels(it.baseUrl, it.userId, 256) val url = ApiUtils.getUrlForAvatarWithName(it.baseUrl, it.userId, R.dimen.avatar_size)
try { try {
val drawable = Coil.get((url)) { val drawable = Coil.get((url)) {
addHeader("Authorization", it.getCredentials()) addHeader("Authorization", it.getCredentials())

View File

@ -85,7 +85,6 @@ class NetworkComponents(
okHttpClientBuilder.dispatcher(dispatcher) okHttpClientBuilder.dispatcher(dispatcher)
return okHttpClientBuilder.build() return okHttpClientBuilder.build()
} }

View File

@ -36,7 +36,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_toEndOf="@id/quotedUserAvatar" android:layout_toEndOf="@id/quotedUserAvatar"
android:textSize="12sp" android:textSize="14sp"
android:id="@+id/quotedAuthor" android:id="@+id/quotedAuthor"
android:layout_alignBaseline="@id/quotedUserAvatar" android:layout_alignBaseline="@id/quotedUserAvatar"
tools:text="Another user"/> tools:text="Another user"/>
@ -63,6 +63,7 @@
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_toStartOf="@id/cancelReplyButton" android:layout_toStartOf="@id/cancelReplyButton"
android:id="@+id/quotedChatText" android:id="@+id/quotedChatText"
android:textSize="12sp"
android:layout_below="@id/quotedPreviewImage" android:layout_below="@id/quotedPreviewImage"
tools:text="Just another chat message"/> tools:text="Just another chat message"/>
@ -71,7 +72,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_below="@id/quotedChatText" android:layout_below="@id/quotedChatText"
android:textSize="12sp" android:textSize="10sp"
android:textAlignment="textEnd"
android:id="@+id/quotedMessageTime" android:id="@+id/quotedMessageTime"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
tools:text="12:30"/> tools:text="12:30"/>

View File

@ -3,8 +3,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto">
android:layout_marginTop="4dp">
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -26,7 +25,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_toEndOf="@id/authorAvatar" android:layout_toEndOf="@id/authorAvatar"
android:textSize="12sp" android:textSize="14sp"
android:id="@+id/authorName" android:id="@+id/authorName"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:gravity="center_vertical" android:gravity="center_vertical"
@ -36,7 +35,6 @@
<include layout="@layout/item_message_quote" <include layout="@layout/item_message_quote"
android:layout_below="@id/authorLayout" android:layout_below="@id/authorLayout"
android:layout_marginTop="4dp"
android:layout_marginStart="40dp" android:layout_marginStart="40dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -47,7 +45,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:layout_marginTop="4dp"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:layout_below="@id/quotedMessageLayout" android:layout_below="@id/quotedMessageLayout"
@ -60,6 +57,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="40dp" android:layout_marginStart="40dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:textSize="12sp"
android:id="@+id/chatMessage" android:id="@+id/chatMessage"
android:layout_below="@id/previewImage" android:layout_below="@id/previewImage"
tools:text="Just another chat message"/> tools:text="Just another chat message"/>
@ -69,7 +67,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_below="@id/chatMessage" android:layout_below="@id/chatMessage"
android:textSize="12sp" android:textSize="10sp"
android:id="@+id/messageTime" android:id="@+id/messageTime"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
tools:text="12:30"/> tools:text="12:30"/>

View File

@ -58,10 +58,10 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="@color/warm_grey_four" android:textColor="@color/warm_grey_four"
android:textSize="12sp" android:textSize="10sp"
tools:text="17:30" tools:text="17:30"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
app:layout_alignSelf="center" app:layout_alignSelf="flex_end"
app:layout_flexGrow="1" app:layout_flexGrow="1"
app:layout_wrapBefore="false"/> app:layout_wrapBefore="false"/>
</com.google.android.flexbox.FlexboxLayout> </com.google.android.flexbox.FlexboxLayout>

View File

@ -30,7 +30,7 @@
<!-- Custom transition dimensions --> <!-- Custom transition dimensions -->
<dimen name="margin_between_elements">8dp</dimen> <dimen name="margin_between_elements">8dp</dimen>
<dimen name="double_margin_between_elements">16dp</dimen> <dimen name="double_margin_between_elements">16dp</dimen>
<dimen name="avatar_size">40dp</dimen> <dimen name="avatar_size">48dp</dimen>
<dimen name="avatar_size_big">96dp</dimen> <dimen name="avatar_size_big">96dp</dimen>
<dimen name="avatar_size_very_big">@dimen/avatar_fetching_size_very_big</dimen> <dimen name="avatar_size_very_big">@dimen/avatar_fetching_size_very_big</dimen>
<dimen name="avatar_fetching_size_very_big">180dp</dimen> <dimen name="avatar_fetching_size_very_big">180dp</dimen>