Stub views for different message types

This commit is contained in:
nielsandriesse 2021-06-01 14:56:58 +10:00
parent 3b18b0985b
commit 958cd54b75
11 changed files with 257 additions and 14 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -2,9 +2,9 @@ package org.thoughtcrime.securesms.conversation.v2.messages
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.BlendModeColorFilterCompat import androidx.core.graphics.BlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat 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 network.loki.messenger.R
import org.session.libsession.utilities.ThemeUtil import org.session.libsession.utilities.ThemeUtil
import org.thoughtcrime.securesms.database.model.MessageRecord import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
import java.lang.IllegalStateException
class VisibleMessageContentView : LinearLayout { class VisibleMessageContentView : LinearLayout {
@ -44,9 +46,33 @@ class VisibleMessageContentView : LinearLayout {
background.colorFilter = filter background.colorFilter = filter
setBackground(background) setBackground(background)
// Body // Body
bodyTextView.text = message.body if (message is MmsMessageRecord && message.linkPreviews.isNotEmpty()) {
// TODO: All the other things that can show up in a visible message, such as link previews, val linkPreviewView = LinkPreviewView(context)
// attachments (incl. multiple at once), open group invitations, voice messages, etc. 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 // endregion
} }

View File

@ -59,6 +59,7 @@ class VisibleMessageView : LinearLayout {
} }
// Date break // Date break
dateBreakTextView.text = "The Ancient Past" dateBreakTextView.text = "The Ancient Past"
dateBreakTextView.visibility = View.GONE // TODO: Set this correctly
// Margins // Margins
val messageContentViewLayoutParams = messageContentView.layoutParams as LinearLayout.LayoutParams val messageContentViewLayoutParams = messageContentView.layoutParams as LinearLayout.LayoutParams
messageContentViewLayoutParams.leftMargin = if (message.isOutgoing) resources.getDimension(R.dimen.very_large_spacing).toInt() else 0 messageContentViewLayoutParams.leftMargin = if (message.isOutgoing) resources.getDimension(R.dimen.very_large_spacing).toInt() else 0

View File

@ -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
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/medium_font_size"
android:textColor="@color/text" />
</LinearLayout>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/medium_font_size"
android:textColor="@color/text" />
</LinearLayout>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/medium_font_size"
android:textColor="@color/text" />
</LinearLayout>

View File

@ -1,15 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical" />
<TextView
android:id="@+id/bodyTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/text"
android:textSize="@dimen/medium_font_size" />
</LinearLayout>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/medium_font_size"
android:textColor="@color/text" />
</LinearLayout>