From 958cd54b753fcada79beb85935cdf6cc32b01fc3 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Tue, 1 Jun 2021 14:56:58 +1000 Subject: [PATCH] Stub views for different message types --- .../conversation/v2/messages/DocumentView.kt | 40 +++++++++++++++++++ .../v2/messages/LinkPreviewView.kt | 40 +++++++++++++++++++ .../conversation/v2/messages/QuoteView.kt | 40 +++++++++++++++++++ .../v2/messages/VisibleMessageContentView.kt | 34 ++++++++++++++-- .../v2/messages/VisibleMessageView.kt | 1 + .../v2/messages/VoiceMessageView.kt | 40 +++++++++++++++++++ app/src/main/res/layout/view_document.xml | 16 ++++++++ app/src/main/res/layout/view_link_preview.xml | 16 ++++++++ app/src/main/res/layout/view_quote.xml | 16 ++++++++ .../layout/view_visible_message_content.xml | 12 +----- .../main/res/layout/view_voice_message.xml | 16 ++++++++ 11 files changed, 257 insertions(+), 14 deletions(-) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/DocumentView.kt create mode 100644 app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt create mode 100644 app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt create mode 100644 app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VoiceMessageView.kt create mode 100644 app/src/main/res/layout/view_document.xml create mode 100644 app/src/main/res/layout/view_link_preview.xml create mode 100644 app/src/main/res/layout/view_quote.xml create mode 100644 app/src/main/res/layout/view_voice_message.xml diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/DocumentView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/DocumentView.kt new file mode 100644 index 0000000000..240c2c64bd --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/DocumentView.kt @@ -0,0 +1,40 @@ +package org.thoughtcrime.securesms.conversation.v2.messages + +import android.content.Context +import android.util.AttributeSet +import android.view.LayoutInflater +import android.widget.LinearLayout +import kotlinx.android.synthetic.main.view_document.view.* +import network.loki.messenger.R +import org.thoughtcrime.securesms.database.model.MessageRecord + +class DocumentView : 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_document, this) + } + // endregion + + // region Updating + fun bind(message: MessageRecord) { + textView.text = "I'm a document" + } + + fun recycle() { + // TODO: Implement + } + // endregion +} \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt new file mode 100644 index 0000000000..e9f951593b --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt @@ -0,0 +1,40 @@ +package org.thoughtcrime.securesms.conversation.v2.messages + +import android.content.Context +import android.util.AttributeSet +import android.view.LayoutInflater +import android.widget.LinearLayout +import kotlinx.android.synthetic.main.view_link_preview.view.* +import network.loki.messenger.R +import org.thoughtcrime.securesms.database.model.MessageRecord + +class LinkPreviewView : 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_link_preview, this) + } + // endregion + + // region Updating + fun bind(message: MessageRecord) { + textView.text = "I'm a link preview" + } + + fun recycle() { + // TODO: Implement + } + // endregion +} \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt new file mode 100644 index 0000000000..36508c94b7 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt @@ -0,0 +1,40 @@ +package org.thoughtcrime.securesms.conversation.v2.messages + +import android.content.Context +import android.util.AttributeSet +import android.view.LayoutInflater +import android.widget.LinearLayout +import kotlinx.android.synthetic.main.view_quote.view.* +import network.loki.messenger.R +import org.thoughtcrime.securesms.database.model.MessageRecord + +class QuoteView : 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_link_preview, this) + } + // endregion + + // region Updating + fun bind(message: MessageRecord) { + textView.text = "I'm a quote" + } + + fun recycle() { + // TODO: Implement + } + // endregion +} \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt index 227cebbbb4..9710082d80 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt @@ -2,9 +2,9 @@ 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 android.widget.TextView import androidx.core.content.res.ResourcesCompat import androidx.core.graphics.BlendModeColorFilterCompat import androidx.core.graphics.BlendModeCompat @@ -12,6 +12,8 @@ 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 +import org.thoughtcrime.securesms.database.model.MmsMessageRecord +import java.lang.IllegalStateException class VisibleMessageContentView : LinearLayout { @@ -44,9 +46,33 @@ class VisibleMessageContentView : LinearLayout { 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. + if (message is MmsMessageRecord && message.linkPreviews.isNotEmpty()) { + val linkPreviewView = LinkPreviewView(context) + mainContainer.addView(linkPreviewView) + } else if (message is MmsMessageRecord && message.quote != null) { + val quoteView = QuoteView(context) + mainContainer.addView(quoteView) + } else if (message is MmsMessageRecord && message.slideDeck.audioSlide != null) { + val voiceMessageView = VoiceMessageView(context) + mainContainer.addView(voiceMessageView) + } else if (message is MmsMessageRecord && message.slideDeck.documentSlide != null) { + val documentView = DocumentView(context) + mainContainer.addView(documentView) + } else if (message is MmsMessageRecord && message.slideDeck.asAttachments().isNotEmpty()) { + throw IllegalStateException("Not yet implemented; we may want to use Signal's album view here.") + } else { + val bodyTextView = getBodyTextView(message.body) + mainContainer.addView(bodyTextView) + } + } + // endregion + + // region Convenience + private fun getBodyTextView(body: String): TextView { + val result = TextView(context) + result.text = body + // TODO: Styling + return result } // endregion } \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt index 98aa02d06b..7fa23a0836 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt @@ -59,6 +59,7 @@ class VisibleMessageView : LinearLayout { } // Date break dateBreakTextView.text = "The Ancient Past" + dateBreakTextView.visibility = View.GONE // TODO: Set this correctly // Margins val messageContentViewLayoutParams = messageContentView.layoutParams as LinearLayout.LayoutParams messageContentViewLayoutParams.leftMargin = if (message.isOutgoing) resources.getDimension(R.dimen.very_large_spacing).toInt() else 0 diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VoiceMessageView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VoiceMessageView.kt new file mode 100644 index 0000000000..a04c429ac9 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VoiceMessageView.kt @@ -0,0 +1,40 @@ +package org.thoughtcrime.securesms.conversation.v2.messages + +import android.content.Context +import android.util.AttributeSet +import android.view.LayoutInflater +import android.widget.LinearLayout +import kotlinx.android.synthetic.main.view_voice_message.view.* +import network.loki.messenger.R +import org.thoughtcrime.securesms.database.model.MessageRecord + +class VoiceMessageView : 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_document, this) + } + // endregion + + // region Updating + fun bind(message: MessageRecord) { + textView.text = "I'm a voice message" + } + + fun recycle() { + // TODO: Implement + } + // endregion +} \ No newline at end of file diff --git a/app/src/main/res/layout/view_document.xml b/app/src/main/res/layout/view_document.xml new file mode 100644 index 0000000000..e54f8e930c --- /dev/null +++ b/app/src/main/res/layout/view_document.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_link_preview.xml b/app/src/main/res/layout/view_link_preview.xml new file mode 100644 index 0000000000..e54f8e930c --- /dev/null +++ b/app/src/main/res/layout/view_link_preview.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_quote.xml b/app/src/main/res/layout/view_quote.xml new file mode 100644 index 0000000000..e54f8e930c --- /dev/null +++ b/app/src/main/res/layout/view_quote.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_visible_message_content.xml b/app/src/main/res/layout/view_visible_message_content.xml index 45faa14465..9e1ea861d8 100644 --- a/app/src/main/res/layout/view_visible_message_content.xml +++ b/app/src/main/res/layout/view_visible_message_content.xml @@ -1,15 +1,7 @@ - - - - \ No newline at end of file + android:orientation="vertical" /> \ No newline at end of file diff --git a/app/src/main/res/layout/view_voice_message.xml b/app/src/main/res/layout/view_voice_message.xml new file mode 100644 index 0000000000..e54f8e930c --- /dev/null +++ b/app/src/main/res/layout/view_voice_message.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file