Fix loading, long clicks, etc

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2020-04-08 14:32:11 +02:00
parent 25c2260f82
commit a8eefd8b34
No known key found for this signature in database
GPG Key ID: CDE0BBD2738C4CC0
5 changed files with 70 additions and 60 deletions

View File

@ -110,6 +110,12 @@ open class ChatPresenter<T : Any>(context: Context, private val onElementClickPa
it.parentMessage?.let { parentMessage ->
holder.itemView.quotedMessageLayout.isVisible = true
holder.itemView.quotedMessageLayout.setOnClickListener {
onElementLongClick?.invoke(page, holder, element, mapOf("parentMessage" to "yes"))
true
}
holder.itemView.quoteColoredView.setBackgroundResource(R.color.colorPrimary)
holder.itemView.quotedPreviewImage.setOnClickListener {
onElementClickPass?.invoke(page, holder, element, mapOf("parentMessage" to "yes"))
@ -118,10 +124,10 @@ open class ChatPresenter<T : Any>(context: Context, private val onElementClickPa
parentMessage.imageUrl?.let { previewMessageUrl ->
if (previewMessageUrl == "no-preview") {
if (it.selectedIndividualHashMap?.containsKey("mimetype") == true) {
if (parentMessage.selectedIndividualHashMap?.containsKey("mimetype") == true) {
holder.itemView.quotedPreviewImage.visibility = View.VISIBLE
imageLoader.getImageLoader().loadAny(context, getDrawableResourceIdForMimeType(parentMessage.selectedIndividualHashMap!!["mimetype"])) {
target(holder.itemView.previewImage)
target(holder.itemView.quotedPreviewImage)
}
} else {
holder.itemView.quotedPreviewImage.visibility = View.GONE
@ -140,8 +146,7 @@ open class ChatPresenter<T : Any>(context: Context, private val onElementClickPa
}
imageLoader.loadImage(holder.itemView.quotedUserAvatar, parentMessage.user.avatar)
holder.itemView.quotedAuthor.text = parentMessage.actorDisplayName
?: context.getText(R.string.nc_nick_guest)
holder.itemView.quotedAuthor.text = parentMessage.user.name
holder.itemView.quotedChatText.text = parentMessage.text
holder.itemView.quotedMessageTime?.text = DateFormatter.format(it.createdAt, DateFormatter.Template.TIME)
} ?: run {

View File

@ -46,6 +46,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import coil.ImageLoader
import coil.api.load
import coil.api.loadAny
import coil.target.Target
import coil.transform.CircleCropTransformation
import com.bluelinelabs.conductor.RouterTransaction
@ -92,6 +93,7 @@ import com.vanniktech.emoji.EmojiPopup
import kotlinx.android.synthetic.main.controller_chat.view.*
import kotlinx.android.synthetic.main.item_message_quote.view.*
import kotlinx.android.synthetic.main.lobby_view.view.*
import kotlinx.android.synthetic.main.rv_chat_item.view.*
import kotlinx.android.synthetic.main.view_message_input.view.*
import org.koin.android.ext.android.inject
import org.parceler.Parcels
@ -391,11 +393,23 @@ class ChatView(private val bundle: Bundle) : BaseView(), ImageLoaderInterface {
loadImage(quotedUserAvatar, chatMessage.user.avatar)
chatMessage.imageUrl?.let { previewImageUrl ->
if (previewImageUrl == "no-preview") {
if (chatMessage.selectedIndividualHashMap?.containsKey("mimetype") == true) {
quotedPreviewImage.isVisible = true
networkComponents.getImageLoader(viewModel.user).loadAny(context, DrawableUtils.getDrawableResourceIdForMimeType(chatMessage.selectedIndividualHashMap!!["mimetype"])) {
target(quotedPreviewImage) }
} else {
quotedPreviewImage.isVisible = false
}
} else {
quotedPreviewImage.isVisible = true
val mutableMap = mutableMapOf<String, String>()
if (chatMessage.selectedIndividualHashMap?.containsKey("mimetype") == true) {
mutableMap["mimetype"] = chatMessage.selectedIndividualHashMap!!["mimetype"]!!
}
val px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 96f, resources?.displayMetrics)
quotedPreviewImage.maxHeight = px.toInt()
loadImage(quotedPreviewImage, previewImageUrl)
loadImage(quotedPreviewImage, previewImageUrl, mutableMap)
}
} ?: run {
quotedPreviewImage.isVisible = false
}

View File

@ -1,35 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/quotedMessageLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_marginBottom="4dp">
<View
android:id="@+id/quoteColoredView"
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_alignTop="@id/quotedTextLayout"
android:layout_alignParentStart="true"
android:layout_alignBottom="@id/quotedTextLayout"
android:layout_alignParentStart="true"
android:layout_marginEnd="4dp"
android:background="@color/colorPrimary"
/>
android:background="@color/colorPrimary" />
<RelativeLayout
android:id="@+id/quotedTextLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/quotedTextLayout"
android:layout_toStartOf="@id/cancelReplyButton"
android:layout_marginEnd="8dp"
android:layout_toEndOf="@id/quoteColoredView">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:id="@+id/quotedAuthorLayout">
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/quotedUserAvatar"
@ -41,60 +35,58 @@
tools:srcCompat="@tools:sample/avatars" />
<TextView
android:id="@+id/quotedAuthor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="@id/quotedUserAvatar"
android:layout_toEndOf="@id/quotedUserAvatar"
android:textSize="14sp"
android:id="@+id/quotedAuthor"
android:layout_alignBaseline="@id/quotedUserAvatar"
tools:text="Another user" />
</RelativeLayout>
<ImageView
android:id="@+id/quotedPreviewImage"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/quotedAuthorLayout"
android:layout_below="@id/quotedAuthor"
android:layout_alignStart="@id/quotedAuthor"
android:adjustViewBounds="true"
android:layout_alignParentStart="true"
android:scaleType="fitCenter"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:maxHeight="96dp"
android:scaleType="fitStart"
tools:src="@tools:sample/backgrounds/scenic" />
<androidx.emoji.widget.EmojiTextView
android:id="@+id/quotedChatText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:autoLink="all"
android:id="@+id/quotedChatText"
android:textSize="12sp"
android:layout_alignStart="@id/quotedAuthor"
android:layout_below="@id/quotedPreviewImage"
android:autoLink="all"
android:textSize="12sp"
tools:text="Just another chat message" />
<TextView
android:id="@+id/quotedMessageTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="@id/quotedChatText"
android:textSize="10sp"
android:layout_alignParentEnd="true"
android:textAlignment="textEnd"
android:id="@+id/quotedMessageTime"
android:textSize="10sp"
tools:text="12:30" />
</RelativeLayout>
<ImageButton
android:id="@+id/cancelReplyButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_centerVertical="true"
android:layout_marginHorizontal="8dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginStart="8dp"
android:background="@drawable/ic_cancel_black_24dp"
android:backgroundTint="@color/grey_600"
android:id="@+id/cancelReplyButton"/>
android:visibility="gone" />
</RelativeLayout>

View File

@ -42,11 +42,11 @@
<ImageView
android:id="@+id/previewImage"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_alignParentStart="true"
android:scaleType="fitCenter"
android:scaleType="fitStart"
android:layout_below="@id/quotedMessageLayout"
android:layout_marginStart="40dp"
android:layout_marginEnd="8dp"

View File

@ -26,7 +26,6 @@
<include layout="@layout/item_message_quote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:visibility="gone"
/>