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