From a8eefd8b34d0bc446b8cb7cefbfdfc8ba9c8d12f Mon Sep 17 00:00:00 2001 From: Mario Danic <mario@lovelyhq.com> Date: Wed, 8 Apr 2020 14:32:11 +0200 Subject: [PATCH] Fix loading, long clicks, etc Signed-off-by: Mario Danic <mario@lovelyhq.com> --- .../newarch/features/chat/ChatPresenter.kt | 13 ++- .../talk/newarch/features/chat/ChatView.kt | 22 ++++- .../main/res/layout/item_message_quote.xml | 90 +++++++++---------- app/src/main/res/layout/rv_chat_item.xml | 4 +- .../main/res/layout/view_message_input.xml | 1 - 5 files changed, 70 insertions(+), 60 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/newarch/features/chat/ChatPresenter.kt b/app/src/main/java/com/nextcloud/talk/newarch/features/chat/ChatPresenter.kt index cf0f05132..128a728f6 100644 --- a/app/src/main/java/com/nextcloud/talk/newarch/features/chat/ChatPresenter.kt +++ b/app/src/main/java/com/nextcloud/talk/newarch/features/chat/ChatPresenter.kt @@ -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 { diff --git a/app/src/main/java/com/nextcloud/talk/newarch/features/chat/ChatView.kt b/app/src/main/java/com/nextcloud/talk/newarch/features/chat/ChatView.kt index 5359946f1..231690f41 100644 --- a/app/src/main/java/com/nextcloud/talk/newarch/features/chat/ChatView.kt +++ b/app/src/main/java/com/nextcloud/talk/newarch/features/chat/ChatView.kt @@ -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 -> - quotedPreviewImage.isVisible = true + 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 } diff --git a/app/src/main/res/layout/item_message_quote.xml b/app/src/main/res/layout/item_message_quote.xml index a1cc49785..de14f6ad6 100644 --- a/app/src/main/res/layout/item_message_quote.xml +++ b/app/src/main/res/layout/item_message_quote.xml @@ -1,100 +1,92 @@ <?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 + + <com.google.android.material.imageview.ShapeableImageView + android:id="@+id/quotedUserAvatar" + android:layout_width="16dp" + android:layout_height="16dp" + android:layout_alignParentTop="true" + android:layout_marginEnd="8dp" + app:shapeAppearanceOverlay="@style/circleImageView" + tools:srcCompat="@tools:sample/avatars" /> + + <TextView + android:id="@+id/quotedAuthor" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginEnd="8dp" - android:id="@+id/quotedAuthorLayout"> + android:layout_alignBaseline="@id/quotedUserAvatar" + android:layout_toEndOf="@id/quotedUserAvatar" + android:textSize="14sp" + tools:text="Another user" /> - <com.google.android.material.imageview.ShapeableImageView - android:id="@+id/quotedUserAvatar" - android:layout_width="16dp" - android:layout_height="16dp" - android:layout_alignParentTop="true" - android:layout_marginEnd="8dp" - app:shapeAppearanceOverlay="@style/circleImageView" - tools:srcCompat="@tools:sample/avatars" /> - - <TextView - android:layout_width="match_parent" - android:layout_height="wrap_content" - 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" - tools:src="@tools:sample/backgrounds/scenic"/> + 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" - tools:text="Just another chat message"/> + 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" - tools:text="12:30"/> + 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> \ No newline at end of file diff --git a/app/src/main/res/layout/rv_chat_item.xml b/app/src/main/res/layout/rv_chat_item.xml index 9f34323ed..ec632506a 100644 --- a/app/src/main/res/layout/rv_chat_item.xml +++ b/app/src/main/res/layout/rv_chat_item.xml @@ -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" diff --git a/app/src/main/res/layout/view_message_input.xml b/app/src/main/res/layout/view_message_input.xml index 4c759831d..a5be3aba1 100644 --- a/app/src/main/res/layout/view_message_input.xml +++ b/app/src/main/res/layout/view_message_input.xml @@ -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" />