mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-12 06:43:39 +00:00
Fix quote view sizing
This commit is contained in:
parent
da0ed31f9b
commit
0291171fb8
@ -1,6 +1,7 @@
|
||||
package org.thoughtcrime.securesms.conversation.v2.input_bar
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.text.Editable
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
@ -10,6 +11,7 @@ import android.widget.LinearLayout
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.core.view.isVisible
|
||||
import kotlinx.android.synthetic.main.view_input_bar.view.*
|
||||
import kotlinx.android.synthetic.main.view_quote.view.*
|
||||
import network.loki.messenger.R
|
||||
import org.thoughtcrime.securesms.conversation.v2.messages.QuoteView
|
||||
import org.thoughtcrime.securesms.conversation.v2.messages.QuoteViewDelegate
|
||||
@ -19,8 +21,10 @@ import org.thoughtcrime.securesms.loki.utilities.toDp
|
||||
import org.thoughtcrime.securesms.loki.utilities.toPx
|
||||
import org.thoughtcrime.securesms.mms.SlideDeck
|
||||
import kotlin.math.max
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate {
|
||||
private val screenWidth = Resources.getSystem().displayMetrics.widthPixels
|
||||
private val vMargin by lazy { toDp(4, resources) }
|
||||
var delegate: InputBarDelegate? = null
|
||||
var additionalContentHeight = 0
|
||||
@ -96,8 +100,10 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate {
|
||||
quoteView.delegate = this
|
||||
inputBarAdditionalContentContainer.addView(quoteView)
|
||||
val attachments = (message as? MmsMessageRecord)?.slideDeck
|
||||
quoteView.bind(message.individualRecipient.address.toString(), message.body, attachments, message.recipient, true)
|
||||
val quoteViewIntrinsicHeight = quoteView.getIntrinsicHeight()
|
||||
val maxContentWidth = (screenWidth - 2 * resources.getDimension(R.dimen.medium_spacing) - toPx(16, resources) - toPx(30, resources)).roundToInt()
|
||||
quoteView.bind(message.individualRecipient.address.toString(), message.body, attachments,
|
||||
message.recipient, true, maxContentWidth, message.isOpenGroupInvitation)
|
||||
val quoteViewIntrinsicHeight = quoteView.getIntrinsicHeight(maxContentWidth) + toPx(6, resources)
|
||||
val newHeight = max(inputBarEditText.height + 2 * vMargin, toPx(56, resources)) + quoteViewIntrinsicHeight
|
||||
additionalContentHeight = quoteViewIntrinsicHeight
|
||||
setHeight(newHeight)
|
||||
|
@ -22,6 +22,7 @@ import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||
import org.thoughtcrime.securesms.loki.utilities.UiMode
|
||||
import org.thoughtcrime.securesms.loki.utilities.UiModeUtilities
|
||||
import org.thoughtcrime.securesms.loki.utilities.toDp
|
||||
import org.thoughtcrime.securesms.loki.utilities.toPx
|
||||
import org.thoughtcrime.securesms.mms.SlideDeck
|
||||
import kotlin.math.max
|
||||
@ -43,13 +44,12 @@ class QuoteView : LinearLayout {
|
||||
constructor(context: Context, mode: Mode) : super(context) {
|
||||
this.mode = mode
|
||||
LayoutInflater.from(context).inflate(R.layout.view_quote, this)
|
||||
setPadding(0, toPx(6, resources), 0, 0)
|
||||
when (mode) {
|
||||
Mode.Draft -> quoteViewCancelButton.setOnClickListener { delegate?.cancelQuoteDraft() }
|
||||
Mode.Regular -> {
|
||||
quoteViewCancelButton.isVisible = false
|
||||
mainQuoteViewContainer.setBackgroundColor(ResourcesCompat.getColor(resources, R.color.transparent, context.theme))
|
||||
val hPadding = resources.getDimension(R.dimen.medium_spacing).roundToInt()
|
||||
mainQuoteViewContainer.setPadding(hPadding, toPx(12, resources), hPadding, toPx(0, resources))
|
||||
val quoteViewMainContentContainerLayoutParams = quoteViewMainContentContainer.layoutParams as RelativeLayout.LayoutParams
|
||||
quoteViewMainContentContainerLayoutParams.marginEnd = resources.getDimension(R.dimen.medium_spacing).roundToInt()
|
||||
quoteViewMainContentContainer.layoutParams = quoteViewMainContentContainerLayoutParams
|
||||
@ -59,9 +59,8 @@ class QuoteView : LinearLayout {
|
||||
// endregion
|
||||
|
||||
// region General
|
||||
fun getIntrinsicContentHeight(): Int {
|
||||
fun getIntrinsicContentHeight(maxContentWidth: Int): Int {
|
||||
if (quoteViewAttachmentPreviewContainer.isVisible) { return toPx(40, resources) }
|
||||
val maxContentWidth = quoteViewMainContentContainer.width
|
||||
var result = 0
|
||||
var authorTextViewIntrinsicHeight = 0
|
||||
if (quoteViewAuthorTextView.isVisible) {
|
||||
@ -73,19 +72,22 @@ class QuoteView : LinearLayout {
|
||||
val bodyTextViewIntrinsicHeight = TextUtilities.getIntrinsicHeight(body, quoteViewBodyTextView.paint, maxContentWidth)
|
||||
result += bodyTextViewIntrinsicHeight
|
||||
if (!quoteViewAuthorTextView.isVisible) {
|
||||
return min(max(result, toPx(32, resources)), toPx(54, resources))
|
||||
return min(max(result, toPx(32, resources)), toPx(60, resources))
|
||||
} else {
|
||||
return min(result, toPx(54, resources) + authorTextViewIntrinsicHeight)
|
||||
return min(result, toPx(60, resources) + authorTextViewIntrinsicHeight)
|
||||
}
|
||||
}
|
||||
|
||||
fun getIntrinsicHeight(): Int {
|
||||
return getIntrinsicContentHeight() + 2 * vPadding
|
||||
fun getIntrinsicHeight(maxContentWidth: Int): Int {
|
||||
var result = getIntrinsicContentHeight(maxContentWidth)
|
||||
result += 2 * vPadding
|
||||
return result
|
||||
}
|
||||
// endregion
|
||||
|
||||
// region Updating
|
||||
fun bind(authorPublicKey: String, body: String?, attachments: SlideDeck?, thread: Recipient, isOutgoingMessage: Boolean) {
|
||||
fun bind(authorPublicKey: String, body: String?, attachments: SlideDeck?, thread: Recipient,
|
||||
isOutgoingMessage: Boolean, maxContentWidth: Int, isOpenGroupInvitation: Boolean) {
|
||||
val contactDB = DatabaseFactory.getSessionContactDatabase(context)
|
||||
// Author
|
||||
if (thread.isGroupRecipient) {
|
||||
@ -96,7 +98,6 @@ class QuoteView : LinearLayout {
|
||||
}
|
||||
quoteViewAuthorTextView.isVisible = thread.isGroupRecipient
|
||||
// Body
|
||||
val isOpenGroupInvitation = (body?.let { UpdateMessageData.fromJSON(it) } != null)
|
||||
quoteViewBodyTextView.text = if (isOpenGroupInvitation) resources.getString(R.string.open_group_invitation_view__open_group_invitation) else body
|
||||
quoteViewBodyTextView.setTextColor(getTextColor(isOutgoingMessage))
|
||||
// Accent line / attachment preview
|
||||
@ -105,7 +106,7 @@ class QuoteView : LinearLayout {
|
||||
quoteViewAttachmentPreviewContainer.isVisible = hasAttachments
|
||||
if (!hasAttachments) {
|
||||
val accentLineLayoutParams = quoteViewAccentLine.layoutParams as RelativeLayout.LayoutParams
|
||||
accentLineLayoutParams.height = getIntrinsicContentHeight()
|
||||
accentLineLayoutParams.height = getIntrinsicContentHeight(maxContentWidth)
|
||||
quoteViewAccentLine.layoutParams = accentLineLayoutParams
|
||||
quoteViewAccentLine.setBackgroundColor(getLineColor(isOutgoingMessage))
|
||||
} else {
|
||||
@ -124,6 +125,7 @@ class QuoteView : LinearLayout {
|
||||
// TODO: Link previews
|
||||
// TODO: Images/video
|
||||
}
|
||||
mainQuoteViewContainer.layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, getIntrinsicHeight(maxContentWidth))
|
||||
val quoteViewMainContentContainerLayoutParams = quoteViewMainContentContainer.layoutParams as RelativeLayout.LayoutParams
|
||||
quoteViewMainContentContainerLayoutParams.marginStart = if (!hasAttachments) toPx(16, resources) else toPx(48, resources)
|
||||
quoteViewMainContentContainer.layoutParams = quoteViewMainContentContainerLayoutParams
|
||||
|
@ -25,6 +25,7 @@ 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 kotlin.math.roundToInt
|
||||
|
||||
class VisibleMessageContentView : LinearLayout {
|
||||
var onContentClick: (() -> Unit)? = null
|
||||
@ -42,7 +43,7 @@ class VisibleMessageContentView : LinearLayout {
|
||||
// endregion
|
||||
|
||||
// region Updating
|
||||
fun bind(message: MessageRecord, isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean, glide: GlideRequests) {
|
||||
fun bind(message: MessageRecord, isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean, glide: GlideRequests, maxWidth: Int) {
|
||||
// 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
|
||||
@ -61,7 +62,9 @@ class VisibleMessageContentView : LinearLayout {
|
||||
} else if (message is MmsMessageRecord && message.quote != null) {
|
||||
val quote = message.quote!!
|
||||
val quoteView = QuoteView(context, QuoteView.Mode.Regular)
|
||||
quoteView.bind(quote.author.toString(), quote.text, quote.attachment, message.recipient, message.isOutgoing)
|
||||
val maxContentWidth = (maxWidth - 2 * resources.getDimension(R.dimen.medium_spacing) - toPx(16, resources)).roundToInt()
|
||||
quoteView.bind(quote.author.toString(), quote.text, quote.attachment, message.recipient,
|
||||
message.isOutgoing, maxContentWidth, message.isOpenGroupInvitation)
|
||||
mainContainer.addView(quoteView)
|
||||
val bodyTextView = VisibleMessageContentView.getBodyTextView(context, message)
|
||||
ViewUtil.setPaddingTop(bodyTextView, 0)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.thoughtcrime.securesms.conversation.v2.messages
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Rect
|
||||
import android.graphics.Region
|
||||
@ -39,6 +40,7 @@ import kotlin.math.roundToInt
|
||||
import kotlin.math.sqrt
|
||||
|
||||
class VisibleMessageView : LinearLayout {
|
||||
private val screenWidth = Resources.getSystem().displayMetrics.widthPixels
|
||||
private val swipeToReplyIcon = ContextCompat.getDrawable(context, R.drawable.ic_baseline_reply_24)!!.mutate()
|
||||
private val swipeToReplyIconRect = Rect()
|
||||
private var dx = 0.0f
|
||||
@ -138,7 +140,11 @@ class VisibleMessageView : LinearLayout {
|
||||
messageStatusImageView.isVisible = false
|
||||
}
|
||||
// Populate content view
|
||||
messageContentView.bind(message, isStartOfMessageCluster, isEndOfMessageCluster, glide)
|
||||
var maxWidth = screenWidth - messageContentContainerLayoutParams.leftMargin - messageContentContainerLayoutParams.rightMargin
|
||||
if (profilePictureContainer.visibility != View.GONE) {
|
||||
maxWidth -= profilePictureContainer.width
|
||||
}
|
||||
messageContentView.bind(message, isStartOfMessageCluster, isEndOfMessageCluster, glide, maxWidth)
|
||||
}
|
||||
|
||||
private fun setMessageSpacing(isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean) {
|
||||
|
@ -6,9 +6,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:background="@color/input_bar_background"
|
||||
android:paddingHorizontal="@dimen/medium_spacing"
|
||||
android:paddingVertical="6dp"
|
||||
android:gravity="center_vertical">
|
||||
android:paddingHorizontal="@dimen/medium_spacing">
|
||||
|
||||
<View
|
||||
android:id="@+id/quoteViewAccentLine"
|
||||
|
Loading…
x
Reference in New Issue
Block a user