mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 17:27:45 +00:00
Basic quote view attachment handling
This commit is contained in:
parent
517539a837
commit
48df733773
@ -13,8 +13,10 @@ import network.loki.messenger.R
|
||||
import org.thoughtcrime.securesms.conversation.v2.messages.QuoteView
|
||||
import org.thoughtcrime.securesms.conversation.v2.messages.QuoteViewDelegate
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
|
||||
import org.thoughtcrime.securesms.loki.utilities.toDp
|
||||
import org.thoughtcrime.securesms.loki.utilities.toPx
|
||||
import org.thoughtcrime.securesms.mms.SlideDeck
|
||||
import kotlin.math.max
|
||||
|
||||
class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate {
|
||||
@ -88,7 +90,8 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate {
|
||||
val quoteView = QuoteView(context, QuoteView.Mode.Draft)
|
||||
quoteView.delegate = this
|
||||
inputBarAdditionalContentContainer.addView(quoteView)
|
||||
quoteView.bind(message.individualRecipient.address.toString(), message.body, null, message.recipient, true)
|
||||
val attachments = (message as? MmsMessageRecord)?.slideDeck
|
||||
quoteView.bind(message.individualRecipient.address.toString(), message.body, attachments, message.recipient, true)
|
||||
val quoteViewIntrinsicHeight = quoteView.getIntrinsicHeight()
|
||||
val newHeight = max(inputBarEditText.height + 2 * vMargin, toPx(56, resources)) + quoteViewIntrinsicHeight
|
||||
additionalContentHeight = quoteViewIntrinsicHeight
|
||||
|
@ -11,19 +11,11 @@ import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||
class LinkPreviewView : LinearLayout {
|
||||
|
||||
// region Lifecycle
|
||||
constructor(context: Context) : super(context) {
|
||||
setUpViewHierarchy()
|
||||
}
|
||||
constructor(context: Context) : super(context) { initialize() }
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { initialize() }
|
||||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { initialize() }
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
|
||||
setUpViewHierarchy()
|
||||
}
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
|
||||
setUpViewHierarchy()
|
||||
}
|
||||
|
||||
private fun setUpViewHierarchy() {
|
||||
private fun initialize() {
|
||||
LayoutInflater.from(context).inflate(R.layout.view_link_preview, this)
|
||||
}
|
||||
// endregion
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.thoughtcrime.securesms.conversation.v2.messages
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.content.res.Resources
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
@ -10,6 +11,7 @@ import android.widget.RelativeLayout
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.marginStart
|
||||
import kotlinx.android.synthetic.main.view_quote.view.*
|
||||
import network.loki.messenger.R
|
||||
import org.session.libsession.messaging.contacts.Contact
|
||||
@ -58,6 +60,7 @@ class QuoteView : LinearLayout {
|
||||
|
||||
// region General
|
||||
fun getIntrinsicContentHeight(): Int {
|
||||
if (quoteViewAttachmentPreviewContainer.isVisible) { return toPx(40, resources) }
|
||||
var result = 0
|
||||
val width = screenWidth
|
||||
var authorTextViewIntrinsicHeight = 0
|
||||
@ -95,11 +98,31 @@ class QuoteView : LinearLayout {
|
||||
// Body
|
||||
quoteViewBodyTextView.text = body
|
||||
quoteViewBodyTextView.setTextColor(getTextColor(isOutgoingMessage))
|
||||
// Accent line
|
||||
// Accent line / attachment preview
|
||||
val hasAttachments = (attachments != null && attachments.asAttachments().isNotEmpty())
|
||||
quoteViewAccentLine.isVisible = !hasAttachments
|
||||
quoteViewAttachmentPreviewContainer.isVisible = hasAttachments
|
||||
if (!hasAttachments) {
|
||||
val accentLineLayoutParams = quoteViewAccentLine.layoutParams as RelativeLayout.LayoutParams
|
||||
accentLineLayoutParams.height = getIntrinsicContentHeight()
|
||||
quoteViewAccentLine.layoutParams = accentLineLayoutParams
|
||||
quoteViewAccentLine.setBackgroundColor(getLineColor(isOutgoingMessage))
|
||||
} else {
|
||||
attachments!!
|
||||
quoteViewAttachmentPreviewImageView.imageTintList = ColorStateList.valueOf(ResourcesCompat.getColor(resources, R.color.white, context.theme))
|
||||
if (attachments.audioSlide != null) {
|
||||
quoteViewAttachmentPreviewImageView.setImageResource(R.drawable.ic_microphone)
|
||||
quoteViewBodyTextView.text = resources.getString(R.string.Slide_audio)
|
||||
} else if (attachments.documentSlide != null) {
|
||||
quoteViewAttachmentPreviewImageView.setImageResource(R.drawable.ic_document_large_light)
|
||||
quoteViewBodyTextView.text = resources.getString(R.string.document)
|
||||
}
|
||||
// TODO: Link previews
|
||||
// TODO: Images/video
|
||||
}
|
||||
val quoteViewMainContentContainerLayoutParams = quoteViewMainContentContainer.layoutParams as RelativeLayout.LayoutParams
|
||||
quoteViewMainContentContainerLayoutParams.marginStart = if (!hasAttachments) toPx(16, resources) else toPx(48, resources)
|
||||
quoteViewMainContentContainer.layoutParams = quoteViewMainContentContainerLayoutParams
|
||||
}
|
||||
// endregion
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<solid android:color="@color/black" />
|
||||
|
||||
<corners android:radius="4dp" />
|
||||
</shape>
|
@ -18,7 +18,23 @@
|
||||
android:layout_centerVertical="true"
|
||||
android:background="@color/text" />
|
||||
|
||||
<!-- The start margin below is the accent line thickness (4 dp) + 12 dp -->
|
||||
<RelativeLayout
|
||||
android:id="@+id/quoteViewAttachmentPreviewContainer"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:background="@drawable/view_quote_attachment_preview_background">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/quoteViewAttachmentPreviewImageView"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/ic_microphone" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/quoteViewMainContentContainer"
|
||||
|
@ -845,4 +845,6 @@
|
||||
<string name="fragment_user_details_bottom_sheet_edit_text_hint">Enter a nickname</string>
|
||||
<string name="invalid_public_key">Invalid public key</string>
|
||||
|
||||
<string name="document">Document</string>
|
||||
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user