Add VisibleMessageContentView

This commit is contained in:
nielsandriesse 2021-06-01 13:26:57 +10:00
parent a23cfbc11d
commit 7f3b714401
4 changed files with 72 additions and 6 deletions

View File

@ -0,0 +1,52 @@
package org.thoughtcrime.securesms.conversation.v2.messages
import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.BlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat
import kotlinx.android.synthetic.main.view_visible_message_content.view.*
import network.loki.messenger.R
import org.session.libsession.utilities.ThemeUtil
import org.thoughtcrime.securesms.database.model.MessageRecord
class VisibleMessageContentView : LinearLayout {
// region Lifecycle
constructor(context: Context) : super(context) {
setUpViewHierarchy()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
setUpViewHierarchy()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
setUpViewHierarchy()
}
private fun setUpViewHierarchy() {
LayoutInflater.from(context).inflate(R.layout.view_visible_message_content, this)
}
// endregion
// region Updating
fun bind(message: MessageRecord) {
// Background
// TODO: Set background to one of sent/received + top/middle/bottom + color
val background = ResourcesCompat.getDrawable(resources, R.drawable.message_bubble_background, context.theme)!!
val colorID = if (message.isOutgoing) R.attr.message_sent_background_color else R.attr.message_received_background_color
val color = ThemeUtil.getThemedColor(context, colorID)
val filter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(color, BlendModeCompat.SRC_IN)
background.colorFilter = filter
setBackground(background)
// Body
bodyTextView.text = message.body
// TODO: All the other things that can show up in a visible message, such as link previews,
// attachments (incl. multiple at once), open group invitations, voice messages, etc.
}
// endregion
}

View File

@ -53,7 +53,8 @@ class VisibleMessageView : LinearLayout {
profilePictureContainer.visibility = View.GONE
senderNameTextView.visibility = View.GONE
}
// TODO: Populate content view
// Populate content view
messageContentView.bind(message)
}
fun recycle() {

View File

@ -60,12 +60,10 @@
android:maxLines="1"
android:ellipsize="end" />
<LinearLayout
android:id="@+id/messageContentContainer"
<org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageContentView
android:id="@+id/messageContentView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/message_bubble_background" />
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/bodyTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/text"
android:textSize="@dimen/small_font_size" />
</LinearLayout>