mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-21 04:29:45 +01:00
Reply layout
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
6b264311e6
commit
25c2260f82
@ -22,6 +22,7 @@
|
||||
|
||||
package com.nextcloud.talk.newarch.features.chat
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
@ -33,10 +34,13 @@ import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.text.Editable
|
||||
import android.text.InputFilter
|
||||
import android.text.TextUtils
|
||||
import android.text.TextWatcher
|
||||
import android.util.Log
|
||||
import android.util.TypedValue
|
||||
import android.view.*
|
||||
import android.widget.ImageView
|
||||
import android.widget.PopupMenu
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.observe
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
@ -82,9 +86,11 @@ import com.otaliastudios.elements.Adapter
|
||||
import com.otaliastudios.elements.Element
|
||||
import com.otaliastudios.elements.Page
|
||||
import com.otaliastudios.elements.Presenter
|
||||
import com.stfalcon.chatkit.utils.DateFormatter
|
||||
import com.uber.autodispose.lifecycle.LifecycleScopeProvider
|
||||
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.view_message_input.view.*
|
||||
import org.koin.android.ext.android.inject
|
||||
@ -194,7 +200,7 @@ class ChatView(private val bundle: Bundle) : BaseView(), ImageLoaderInterface {
|
||||
view.smileyButton.setOnClickListener {
|
||||
emojiPopup?.toggle()
|
||||
}
|
||||
|
||||
|
||||
viewModel.apply {
|
||||
conversation.observe(this@ChatView) { conversation ->
|
||||
setTitle()
|
||||
@ -238,6 +244,7 @@ class ChatView(private val bundle: Bundle) : BaseView(), ImageLoaderInterface {
|
||||
}
|
||||
}
|
||||
|
||||
view.cancelReplyButton.setOnClickListener { hideReplyView() }
|
||||
return view
|
||||
}
|
||||
|
||||
@ -341,8 +348,73 @@ class ChatView(private val bundle: Bundle) : BaseView(), ImageLoaderInterface {
|
||||
}
|
||||
}
|
||||
|
||||
private fun hideReplyView() {
|
||||
view?.messageInputView?.let {
|
||||
with (it) {
|
||||
quotedMessageLayout.isVisible = false
|
||||
attachmentButton.isVisible = true
|
||||
attachmentButtonSpace.isVisible = true
|
||||
}
|
||||
}
|
||||
}
|
||||
private fun onElementLongClick(page: Page, holder: Presenter.Holder, element: Element<ChatElement>, payload: Map<String, String>) {
|
||||
if (element.type == ChatElementTypes.CHAT_MESSAGE.ordinal) {
|
||||
element.data?.let { chatElement ->
|
||||
var chatMessage = chatElement.data as ChatMessage
|
||||
if (payload.containsKey("parentMessage")) {
|
||||
chatMessage = chatMessage.parentMessage!!
|
||||
}
|
||||
|
||||
PopupMenu(this.context, holder.itemView, Gravity.START).apply {
|
||||
setOnMenuItemClickListener { item ->
|
||||
when (item?.itemId) {
|
||||
|
||||
R.id.action_copy_message -> {
|
||||
val clipboardManager =
|
||||
activity?.getSystemService(Context.CLIPBOARD_SERVICE) as android.content.ClipboardManager
|
||||
val clipData = ClipData.newPlainText(resources?.getString(R.string.nc_app_name), chatMessage.text)
|
||||
clipboardManager.setPrimaryClip(clipData)
|
||||
true
|
||||
}
|
||||
R.id.action_reply_to_message -> {
|
||||
view?.let {
|
||||
with(it.messageInputView) {
|
||||
attachmentButton.isVisible = false
|
||||
attachmentButtonSpace.isVisible = false
|
||||
cancelReplyButton.isVisible = true
|
||||
quotedChatText.maxLines = 2
|
||||
quotedChatText.ellipsize = TextUtils.TruncateAt.END
|
||||
quotedChatText.text = chatMessage.text
|
||||
quotedAuthor.text = chatMessage.user.name
|
||||
quotedMessageTime.text = DateFormatter.format(chatMessage.createdAt, DateFormatter.Template.TIME)
|
||||
|
||||
loadImage(quotedUserAvatar, chatMessage.user.avatar)
|
||||
|
||||
chatMessage.imageUrl?.let { previewImageUrl ->
|
||||
quotedPreviewImage.isVisible = true
|
||||
|
||||
val px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 96f, resources?.displayMetrics)
|
||||
quotedPreviewImage.maxHeight = px.toInt()
|
||||
loadImage(quotedPreviewImage, previewImageUrl)
|
||||
} ?: run {
|
||||
quotedPreviewImage.isVisible = false
|
||||
}
|
||||
quotedMessageLayout.tag = chatMessage.jsonMessageId
|
||||
quotedMessageLayout.isVisible = true
|
||||
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
inflate(R.menu.chat_message_menu)
|
||||
menu.findItem(R.id.action_reply_to_message).isVisible = chatMessage.replyable
|
||||
show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttach(view: View) {
|
||||
|
@ -10,9 +10,9 @@
|
||||
android:id="@+id/quoteColoredView"
|
||||
android:layout_width="2dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignTop="@id/quotedAuthorLayout"
|
||||
android:layout_alignTop="@id/quotedTextLayout"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignBottom="@id/quotedMessageTime"
|
||||
android:layout_alignBottom="@id/quotedTextLayout"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:background="@color/colorPrimary"
|
||||
/>
|
||||
@ -20,72 +20,78 @@
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toEndOf="@id/quoteColoredView"
|
||||
android:id="@+id/quotedTextLayout"
|
||||
android:layout_toStartOf="@id/cancelReplyButton"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:id="@+id/quotedAuthorLayout">
|
||||
android:layout_toEndOf="@id/quoteColoredView">
|
||||
|
||||
<com.google.android.material.imageview.ShapeableImageView
|
||||
android:id="@+id/quotedUserAvatar"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_alignParentTop="true"
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
app:shapeAppearanceOverlay="@style/circleImageView"
|
||||
tools:srcCompat="@tools:sample/avatars" />
|
||||
android:id="@+id/quotedAuthorLayout">
|
||||
|
||||
<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_height="wrap_content"
|
||||
android:layout_below="@id/quotedAuthorLayout"
|
||||
android:adjustViewBounds="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:scaleType="fitCenter"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
tools:src="@tools:sample/backgrounds/scenic"/>
|
||||
|
||||
<androidx.emoji.widget.EmojiTextView
|
||||
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_below="@id/quotedPreviewImage"
|
||||
tools:text="Just another chat message"/>
|
||||
|
||||
<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"/>
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_below="@id/quotedChatText"
|
||||
android:textSize="10sp"
|
||||
android:textAlignment="textEnd"
|
||||
android:id="@+id/quotedMessageTime"
|
||||
tools:text="12:30"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/quotedPreviewImage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/quotedAuthorLayout"
|
||||
android:adjustViewBounds="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:scaleType="fitCenter"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_toStartOf="@id/cancelReplyButton"
|
||||
android:layout_marginTop="8dp"
|
||||
tools:src="@tools:sample/backgrounds/scenic"/>
|
||||
|
||||
<androidx.emoji.widget.EmojiTextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:autoLink="all"
|
||||
android:layout_toStartOf="@id/cancelReplyButton"
|
||||
android:id="@+id/quotedChatText"
|
||||
android:textSize="12sp"
|
||||
android:layout_below="@id/quotedPreviewImage"
|
||||
tools:text="Just another chat message"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_below="@id/quotedChatText"
|
||||
android:textSize="10sp"
|
||||
android:textAlignment="textEnd"
|
||||
android:id="@+id/quotedMessageTime"
|
||||
tools:text="12:30"/>
|
||||
|
||||
|
||||
<ImageButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
android:layout_marginHorizontal="8dp"
|
||||
android:visibility="visible"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginHorizontal="8dp"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:background="@drawable/ic_cancel_black_24dp"
|
||||
android:backgroundTint="@color/grey_600"
|
||||
|
@ -27,13 +27,14 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:visibility="gone"/>
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
<androidx.emoji.widget.EmojiEditText
|
||||
android:id="@id/messageInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/quotedChatMessageView"
|
||||
android:layout_below="@+id/quotedMessageLayout"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_toStartOf="@id/sendButtonSpace"
|
||||
android:layout_toEndOf="@id/attachmentButtonSpace"
|
||||
@ -45,14 +46,14 @@
|
||||
android:id="@id/attachmentButton"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_below="@id/quotedChatMessageView"
|
||||
android:layout_below="@id/quotedMessageLayout"
|
||||
android:scaleType="centerInside" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/smileyButton"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_below="@id/quotedChatMessageView"
|
||||
android:layout_below="@id/quotedMessageLayout"
|
||||
android:layout_toStartOf="@id/messageSendButton"
|
||||
android:background="@color/transparent"
|
||||
android:src="@drawable/ic_insert_emoticon_black_24dp"
|
||||
@ -63,7 +64,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_below="@id/quotedChatMessageView"
|
||||
android:layout_below="@id/quotedMessageLayout"
|
||||
android:adjustViewBounds="true"
|
||||
android:padding="4dp"
|
||||
android:scaleType="centerInside" />
|
||||
@ -72,14 +73,14 @@
|
||||
android:id="@id/attachmentButtonSpace"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_below="@id/quotedChatMessageView"
|
||||
android:layout_below="@id/quotedMessageLayout"
|
||||
android:layout_toEndOf="@id/attachmentButton" />
|
||||
|
||||
<Space
|
||||
android:id="@id/sendButtonSpace"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_below="@id/quotedChatMessageView"
|
||||
android:layout_below="@id/quotedMessageLayout"
|
||||
android:layout_toStartOf="@id/smileyButton" />
|
||||
</RelativeLayout>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user