Add document view

This commit is contained in:
Niels Andriesse 2021-06-21 13:58:01 +10:00
parent 6ddde26496
commit f79bb5e0d4
3 changed files with 40 additions and 21 deletions

View file

@ -1,36 +1,34 @@
package org.thoughtcrime.securesms.conversation.v2.messages
import android.content.Context
import android.content.res.ColorStateList
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.annotation.ColorInt
import kotlinx.android.synthetic.main.view_document.view.*
import network.loki.messenger.R
import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
class DocumentView : 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_document, this)
}
// endregion
// region Updating
fun bind(message: MessageRecord) {
textView.text = "I'm a document"
fun bind(message: MmsMessageRecord, @ColorInt textColor: Int) {
val document = message.slideDeck.documentSlide!!
documentTitleTextView.text = document.fileName.or("Untitled File")
documentTitleTextView.setTextColor(textColor)
documentViewIconImageView.imageTintList = ColorStateList.valueOf(textColor)
}
fun recycle() {

View file

@ -8,6 +8,7 @@ import android.view.LayoutInflater
import android.view.ViewOutlineProvider
import android.widget.LinearLayout
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.BlendModeColorFilterCompat
@ -67,7 +68,7 @@ class VisibleMessageContentView : LinearLayout {
mainContainer.addView(voiceMessageView)
} else if (message is MmsMessageRecord && message.slideDeck.documentSlide != null) {
val documentView = DocumentView(context)
documentView.bind(message)
documentView.bind(message, getTextColor(message))
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.")
@ -105,14 +106,20 @@ class VisibleMessageContentView : LinearLayout {
result.setPadding(hPadding, vPadding, hPadding, vPadding)
result.text = message.body
result.setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.small_font_size))
val color = getTextColor(message)
result.setTextColor(color)
return result
}
@ColorInt
private fun getTextColor(message: MessageRecord): Int {
val uiMode = UiModeUtilities.getUserSelectedUiMode(context)
val colorID = if (message.isOutgoing) {
if (uiMode == UiMode.NIGHT) R.color.black else R.color.white
} else {
if (uiMode == UiMode.NIGHT) R.color.white else R.color.black
}
result.setTextColor(resources.getColorWithID(colorID, context.theme))
return result
return resources.getColorWithID(colorID, context.theme)
}
// endregion
}

View file

@ -1,16 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:padding="@dimen/medium_spacing"
android:gravity="center">
<ImageView
android:id="@+id/documentViewIconImageView"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_document_large_light"
app:tint="@color/text" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:id="@+id/documentTitleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/medium_font_size"
android:textColor="@color/text" />
android:layout_marginStart="4dp"
android:textSize="@dimen/small_font_size"
android:textColor="@color/text"
tools:text="I'm a very long document title. Did you know that?"
android:maxLines="2"
android:ellipsize="end" />
</LinearLayout>