mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 02:25:19 +00:00
Basic link preview view
This commit is contained in:
parent
ae078d8ee9
commit
0eaecf168d
@ -49,6 +49,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
|
||||
// TODO: Selected message background color
|
||||
// TODO: Overflow menu background + text color
|
||||
// TODO: Typing indicators
|
||||
|
||||
private val adapter by lazy {
|
||||
val cursor = DatabaseFactory.getMmsSmsDatabase(this).getConversation(threadID)
|
||||
@ -63,7 +64,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
},
|
||||
onItemLongPress = { message, position ->
|
||||
handleLongPress(message, position)
|
||||
}
|
||||
},
|
||||
glide
|
||||
)
|
||||
adapter
|
||||
}
|
||||
|
@ -14,10 +14,12 @@ import org.thoughtcrime.securesms.database.CursorRecyclerViewAdapter
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||
import org.thoughtcrime.securesms.loki.utilities.getColorWithID
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||
import java.lang.IllegalStateException
|
||||
|
||||
class ConversationAdapter(context: Context, cursor: Cursor, private val onItemPress: (MessageRecord, Int, VisibleMessageView) -> Unit,
|
||||
private val onItemSwipeToReply: (MessageRecord, Int) -> Unit, private val onItemLongPress: (MessageRecord, Int) -> Unit)
|
||||
private val onItemSwipeToReply: (MessageRecord, Int) -> Unit, private val onItemLongPress: (MessageRecord, Int) -> Unit,
|
||||
private val glide: GlideRequests)
|
||||
: CursorRecyclerViewAdapter<ViewHolder>(context, cursor) {
|
||||
private val messageDB = DatabaseFactory.getMmsSmsDatabase(context)
|
||||
var selectedItems = mutableSetOf<MessageRecord>()
|
||||
@ -69,7 +71,7 @@ class ConversationAdapter(context: Context, cursor: Cursor, private val onItemPr
|
||||
view.snIsSelected = isSelected
|
||||
view.messageTimestampTextView.isVisible = isSelected
|
||||
val position = viewHolder.adapterPosition
|
||||
view.bind(message, getMessageBefore(position, cursor), getMessageAfter(position, cursor))
|
||||
view.bind(message, getMessageBefore(position, cursor), getMessageAfter(position, cursor), glide)
|
||||
view.onPress = { onItemPress(message, viewHolder.adapterPosition, view) }
|
||||
view.onSwipeToReply = { onItemSwipeToReply(message, viewHolder.adapterPosition) }
|
||||
view.onLongPress = { onItemLongPress(message, viewHolder.adapterPosition) }
|
||||
|
@ -1,12 +1,20 @@
|
||||
package org.thoughtcrime.securesms.conversation.v2.messages
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewOutlineProvider
|
||||
import android.widget.LinearLayout
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop
|
||||
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
|
||||
import kotlinx.android.synthetic.main.view_link_preview.view.*
|
||||
import network.loki.messenger.R
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
|
||||
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||
import org.thoughtcrime.securesms.mms.ImageSlide
|
||||
|
||||
class LinkPreviewView : LinearLayout {
|
||||
|
||||
@ -21,8 +29,15 @@ class LinkPreviewView : LinearLayout {
|
||||
// endregion
|
||||
|
||||
// region Updating
|
||||
fun bind(message: MessageRecord) {
|
||||
textView.text = "I'm a link preview"
|
||||
fun bind(message: MmsMessageRecord, glide: GlideRequests) {
|
||||
// Thumbnail
|
||||
val linkPreview = message.linkPreviews.first()
|
||||
// TODO: Handle downloading state
|
||||
val uri = linkPreview.thumbnail.get().dataUri!!
|
||||
glide.load(uri).into(thumbnailImageView)
|
||||
// TODO: Properly use glide and the actual thumbnail
|
||||
// Title
|
||||
titleTextView.text = linkPreview.title
|
||||
}
|
||||
|
||||
fun recycle() {
|
||||
|
@ -110,6 +110,9 @@ class QuoteView : LinearLayout {
|
||||
} else {
|
||||
attachments!!
|
||||
quoteViewAttachmentPreviewImageView.imageTintList = ColorStateList.valueOf(ResourcesCompat.getColor(resources, R.color.white, context.theme))
|
||||
val backgroundColorID = if (UiModeUtilities.isDayUiMode(context)) R.color.black else R.color.accent
|
||||
val backgroundColor = ResourcesCompat.getColor(resources, backgroundColorID, context.theme)
|
||||
quoteViewAttachmentPreviewContainer.backgroundTintList = ColorStateList.valueOf(backgroundColor)
|
||||
if (attachments.audioSlide != null) {
|
||||
quoteViewAttachmentPreviewImageView.setImageResource(R.drawable.ic_microphone)
|
||||
quoteViewBodyTextView.text = resources.getString(R.string.Slide_audio)
|
||||
|
@ -23,6 +23,7 @@ import org.thoughtcrime.securesms.loki.utilities.UiMode
|
||||
import org.thoughtcrime.securesms.loki.utilities.UiModeUtilities
|
||||
import org.thoughtcrime.securesms.loki.utilities.getColorWithID
|
||||
import org.thoughtcrime.securesms.loki.utilities.toPx
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||
import java.lang.IllegalStateException
|
||||
|
||||
class VisibleMessageContentView : LinearLayout {
|
||||
@ -41,7 +42,7 @@ class VisibleMessageContentView : LinearLayout {
|
||||
// endregion
|
||||
|
||||
// region Updating
|
||||
fun bind(message: MessageRecord, isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean) {
|
||||
fun bind(message: MessageRecord, isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean, glide: GlideRequests) {
|
||||
// Background
|
||||
val background = getBackground(message.isOutgoing, isStartOfMessageCluster, isEndOfMessageCluster)
|
||||
val colorID = if (message.isOutgoing) R.attr.message_sent_background_color else R.attr.message_received_background_color
|
||||
@ -54,8 +55,10 @@ class VisibleMessageContentView : LinearLayout {
|
||||
onContentClick = null
|
||||
if (message is MmsMessageRecord && message.linkPreviews.isNotEmpty()) {
|
||||
val linkPreviewView = LinkPreviewView(context)
|
||||
linkPreviewView.bind(message)
|
||||
linkPreviewView.bind(message, glide)
|
||||
mainContainer.addView(linkPreviewView)
|
||||
val bodyTextView = getBodyTextView(message)
|
||||
mainContainer.addView(bodyTextView)
|
||||
} else if (message is MmsMessageRecord && message.quote != null) {
|
||||
val quote = message.quote!!
|
||||
val quoteView = QuoteView(context, QuoteView.Mode.Regular)
|
||||
|
@ -25,6 +25,7 @@ import org.thoughtcrime.securesms.loki.utilities.disableClipping
|
||||
import org.thoughtcrime.securesms.loki.utilities.getColorWithID
|
||||
import org.thoughtcrime.securesms.loki.utilities.toDp
|
||||
import org.thoughtcrime.securesms.loki.utilities.toPx
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||
import org.thoughtcrime.securesms.util.DateUtils
|
||||
import java.util.*
|
||||
import kotlin.math.abs
|
||||
@ -66,7 +67,7 @@ class VisibleMessageView : LinearLayout {
|
||||
// endregion
|
||||
|
||||
// region Updating
|
||||
fun bind(message: MessageRecord, previous: MessageRecord?, next: MessageRecord?) {
|
||||
fun bind(message: MessageRecord, previous: MessageRecord?, next: MessageRecord?, glide: GlideRequests) {
|
||||
val sender = message.individualRecipient
|
||||
val senderSessionID = sender.address.serialize()
|
||||
val threadID = message.threadId
|
||||
@ -113,7 +114,7 @@ class VisibleMessageView : LinearLayout {
|
||||
val gravity = if (message.isOutgoing) Gravity.RIGHT else Gravity.LEFT
|
||||
mainContainer.gravity = gravity or Gravity.BOTTOM
|
||||
// Populate content view
|
||||
messageContentView.bind(message, isStartOfMessageCluster, isEndOfMessageCluster)
|
||||
messageContentView.bind(message, isStartOfMessageCluster, isEndOfMessageCluster, glide)
|
||||
}
|
||||
|
||||
private fun setMessageSpacing(isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean) {
|
||||
|
@ -1,16 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
android:id="@+id/mainLinkPreviewContainer"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/thumbnailImageView"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:scaleType="centerCrop" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:id="@+id/titleTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="@dimen/medium_font_size"
|
||||
android:textColor="@color/text" />
|
||||
android:layout_height="match_parent"
|
||||
android:paddingStart="12dp"
|
||||
android:gravity="center_vertical"
|
||||
android:textSize="@dimen/small_font_size"
|
||||
android:textStyle="bold"
|
||||
tools:text="The Day The Dinosaurs Died - Minute by Minute"
|
||||
android:maxLines="3"
|
||||
android:ellipsize="end"
|
||||
android:textColor="@color/text"
|
||||
android:background="@color/link_preview_background" />
|
||||
|
||||
</LinearLayout>
|
@ -28,6 +28,7 @@
|
||||
<color name="input_bar_lock_view_border">#66000000</color>
|
||||
<color name="mention_candidates_view_background">#FCFCFC</color>
|
||||
<color name="mention_candidates_view_background_ripple">#DFDFDF</color>
|
||||
<color name="link_preview_background">#0F000000</color>
|
||||
|
||||
<color name="default_background_start">#ffffff</color>
|
||||
<color name="default_background_end">#fcfcfc</color>
|
||||
|
@ -35,6 +35,7 @@
|
||||
<color name="input_bar_lock_view_border">#66FFFFFF</color>
|
||||
<color name="mention_candidates_view_background">#171717</color>
|
||||
<color name="mention_candidates_view_background_ripple">#0C0C0C</color>
|
||||
<color name="link_preview_background">#000000</color>
|
||||
|
||||
<array name="profile_picture_placeholder_colors">
|
||||
<item>#5ff8b0</item>
|
||||
|
Loading…
Reference in New Issue
Block a user