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,114 +65,131 @@ 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
holder.itemView.messageTime?.text = DateFormatter.format(it.createdAt, DateFormatter.Template.TIME) val previousElement = getAdapter().elementAt(holder.adapterPosition - 1)
holder.itemView.chatMessage.text = it.text if (previousElement != null && previousElement.element.data != null && previousElement.element.data is ChatElement) {
val previousChatElement = previousElement.element.data as ChatElement
if (it.actorType == "bots" && it.actorId == "changelog") { if (previousChatElement.elementType == ChatElementTypes.CHAT_MESSAGE) {
val layers = arrayOfNulls<Drawable>(2) val previousChatMessage = previousChatElement.data as ChatMessage
layers[0] = context.getDrawable(R.drawable.ic_launcher_background) if (previousChatMessage.actorId == it.actorId) {
layers[1] = context.getDrawable(R.drawable.ic_launcher_foreground) shouldShowNameAndAvatar = false
val layerDrawable = LayerDrawable(layers) }
val loadBuilder = imageLoader.getImageLoader().newLoadBuilder(context).target(holder.itemView.authorAvatar).data(DisplayUtils.getRoundedDrawable(layerDrawable)) }
imageLoader.getImageLoader().load(loadBuilder.build())
} else if (it.actorType == "bots") {
val drawable = TextDrawable.builder()
.beginConfig()
.bold()
.endConfig()
.buildRound(
">",
context.resources.getColor(R.color.black)
)
val loadBuilder = imageLoader.getImageLoader().newLoadBuilder(context).target(holder.itemView.authorAvatar).data(DisplayUtils.getRoundedDrawable(drawable))
imageLoader.getImageLoader().load(loadBuilder.build())
} else {
imageLoader.loadImage(holder.itemView.authorAvatar, it.user.avatar)
}
it.parentMessage?.let { parentMessage ->
holder.itemView.quotedMessageLayout.isVisible = true
holder.itemView.quoteColoredView.setBackgroundResource(R.color.colorPrimary)
holder.itemView.quotedPreviewImage.setOnClickListener {
onElementClickPass?.invoke(page, holder, element, mapOf("parentMessage" to "yes"))
true
} }
parentMessage.imageUrl?.let { previewMessageUrl -> holder.itemView.messageTime?.text = DateFormatter.format(it.createdAt, DateFormatter.Template.TIME)
if (previewMessageUrl == "no-preview") { holder.itemView.chatMessage.text = it.text
if (it.selectedIndividualHashMap?.containsKey("mimetype") == true) { if (shouldShowNameAndAvatar) {
holder.itemView.authorLayout.isVisible = true
holder.itemView.authorName?.text = it.actorDisplayName
if (it.actorType == "bots" && it.actorId == "changelog") {
val layers = arrayOfNulls<Drawable>(2)
layers[0] = context.getDrawable(R.drawable.ic_launcher_background)
layers[1] = context.getDrawable(R.drawable.ic_launcher_foreground)
val layerDrawable = LayerDrawable(layers)
val loadBuilder = imageLoader.getImageLoader().newLoadBuilder(context).target(holder.itemView.authorAvatar).data(DisplayUtils.getRoundedDrawable(layerDrawable))
imageLoader.getImageLoader().load(loadBuilder.build())
} else if (it.actorType == "bots") {
val drawable = TextDrawable.builder()
.beginConfig()
.bold()
.endConfig()
.buildRound(
">",
context.resources.getColor(R.color.black)
)
val loadBuilder = imageLoader.getImageLoader().newLoadBuilder(context).target(holder.itemView.authorAvatar).data(DisplayUtils.getRoundedDrawable(drawable))
imageLoader.getImageLoader().load(loadBuilder.build())
} else {
imageLoader.loadImage(holder.itemView.authorAvatar, it.user.avatar)
}
} else {
holder.itemView.authorLayout.isVisible = false
}
it.parentMessage?.let { parentMessage ->
holder.itemView.quotedMessageLayout.isVisible = true
holder.itemView.quoteColoredView.setBackgroundResource(R.color.colorPrimary)
holder.itemView.quotedPreviewImage.setOnClickListener {
onElementClickPass?.invoke(page, holder, element, mapOf("parentMessage" to "yes"))
true
}
parentMessage.imageUrl?.let { previewMessageUrl ->
if (previewMessageUrl == "no-preview") {
if (it.selectedIndividualHashMap?.containsKey("mimetype") == true) {
holder.itemView.quotedPreviewImage.visibility = View.VISIBLE
imageLoader.getImageLoader().loadAny(context, getDrawableResourceIdForMimeType(parentMessage.selectedIndividualHashMap!!["mimetype"])) {
target(holder.itemView.previewImage)
}
} else {
holder.itemView.quotedPreviewImage.visibility = View.GONE
}
} else {
holder.itemView.quotedPreviewImage.visibility = View.VISIBLE holder.itemView.quotedPreviewImage.visibility = View.VISIBLE
imageLoader.getImageLoader().loadAny(context, getDrawableResourceIdForMimeType(parentMessage.selectedIndividualHashMap!!["mimetype"])) { val mutableMap = mutableMapOf<String, String>()
if (parentMessage.selectedIndividualHashMap?.containsKey("mimetype") == true) {
mutableMap["mimetype"] = it.selectedIndividualHashMap!!["mimetype"]!!
}
imageLoader.loadImage(holder.itemView.previewImage, previewMessageUrl, mutableMap)
}
} ?: run {
holder.itemView.quotedPreviewImage.visibility = View.GONE
}
imageLoader.loadImage(holder.itemView.quotedUserAvatar, parentMessage.user.avatar)
holder.itemView.quotedAuthor.text = parentMessage.actorDisplayName
?: context.getText(R.string.nc_nick_guest)
holder.itemView.quotedChatText.text = parentMessage.text
holder.itemView.messageTime?.text = DateFormatter.format(it.createdAt, DateFormatter.Template.TIME)
} ?: run {
holder.itemView.quotedMessageLayout.isVisible = false
}
it.imageUrl?.let { imageUrl ->
holder.itemView.previewImage.setOnClickListener {
onElementClickPass?.invoke(page, holder, element, emptyMap())
true
}
if (imageUrl == "no-preview") {
if (it.selectedIndividualHashMap?.containsKey("mimetype") == true) {
holder.itemView.previewImage.visibility = View.VISIBLE
imageLoader.getImageLoader().loadAny(context, getDrawableResourceIdForMimeType(it.selectedIndividualHashMap!!["mimetype"])) {
target(holder.itemView.previewImage) target(holder.itemView.previewImage)
} }
} else { } else {
holder.itemView.quotedPreviewImage.visibility = View.GONE holder.itemView.previewImage.visibility = View.GONE
} }
} else { } else {
holder.itemView.quotedPreviewImage.visibility = View.VISIBLE holder.itemView.previewImage.visibility = View.VISIBLE
val mutableMap = mutableMapOf<String, String>() val mutableMap = mutableMapOf<String, String>()
if (parentMessage.selectedIndividualHashMap?.containsKey("mimetype") == true) { if (it.selectedIndividualHashMap?.containsKey("mimetype") == true) {
mutableMap["mimetype"] = it.selectedIndividualHashMap!!["mimetype"]!! mutableMap["mimetype"] = it.selectedIndividualHashMap!!["mimetype"]!!
} }
imageLoader.loadImage(holder.itemView.previewImage, previewMessageUrl, mutableMap) imageLoader.loadImage(holder.itemView.previewImage, imageUrl, mutableMap)
} }
} ?: run { } ?: run {
holder.itemView.quotedPreviewImage.visibility = View.GONE holder.itemView.previewImage.visibility = View.GONE
} }
imageLoader.loadImage(holder.itemView.quotedUserAvatar, parentMessage.user.avatar) } else {
holder.itemView.quotedAuthor.text = parentMessage.actorDisplayName holder.itemView.systemMessageText.text = it.text
?: context.getText(R.string.nc_nick_guest) holder.itemView.systemItemTime.text = DateFormatter.format(it.createdAt, DateFormatter.Template.TIME)
holder.itemView.quotedChatText.text = parentMessage.text
holder.itemView.messageTime?.text = DateFormatter.format(it.createdAt, DateFormatter.Template.TIME)
} ?: run {
holder.itemView.quotedMessageLayout.isVisible = false
} }
it.imageUrl?.let { imageUrl ->
holder.itemView.previewImage.setOnClickListener {
onElementClickPass?.invoke(page, holder, element, emptyMap())
true
}
if (imageUrl == "no-preview") {
if (it.selectedIndividualHashMap?.containsKey("mimetype") == true) {
holder.itemView.previewImage.visibility = View.VISIBLE
imageLoader.getImageLoader().loadAny(context, getDrawableResourceIdForMimeType(it.selectedIndividualHashMap!!["mimetype"])) {
target(holder.itemView.previewImage)
}
} else {
holder.itemView.previewImage.visibility = View.GONE
}
} else {
holder.itemView.previewImage.visibility = View.VISIBLE
val mutableMap = mutableMapOf<String, String>()
if (it.selectedIndividualHashMap?.containsKey("mimetype") == true) {
mutableMap["mimetype"] = it.selectedIndividualHashMap!!["mimetype"]!!
}
imageLoader.loadImage(holder.itemView.previewImage, imageUrl, mutableMap)
}
} ?: run {
holder.itemView.previewImage.visibility = View.GONE
}
} else {
holder.itemView.systemMessageText.text = it.text
holder.itemView.systemItemTime.text = DateFormatter.format(it.createdAt, DateFormatter.Template.TIME)
} }
} }
} element.type == ChatElementTypes.UNREAD_MESSAGE_NOTICE.ordinal -> {
element.type == ChatElementTypes.UNREAD_MESSAGE_NOTICE.ordinal -> { holder.itemView.noticeText.text = context.resources.getString(R.string.nc_new_messages)
holder.itemView.noticeText.text = context.resources.getString(R.string.nc_new_messages) }
} else -> {
else -> { // Date header
// Date header 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

@ -84,8 +84,7 @@ 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>