mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-21 09:28:27 +00:00
Add document view
This commit is contained in:
parent
6ddde26496
commit
f79bb5e0d4
@ -1,36 +1,34 @@
|
|||||||
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.ColorStateList
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
|
import androidx.annotation.ColorInt
|
||||||
import kotlinx.android.synthetic.main.view_document.view.*
|
import kotlinx.android.synthetic.main.view_document.view.*
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||||
|
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
|
||||||
|
|
||||||
class DocumentView : LinearLayout {
|
class DocumentView : LinearLayout {
|
||||||
|
|
||||||
// region Lifecycle
|
// region Lifecycle
|
||||||
constructor(context: Context) : super(context) {
|
constructor(context: Context) : super(context) { initialize() }
|
||||||
setUpViewHierarchy()
|
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) {
|
private fun initialize() {
|
||||||
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)
|
LayoutInflater.from(context).inflate(R.layout.view_document, this)
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Updating
|
// region Updating
|
||||||
fun bind(message: MessageRecord) {
|
fun bind(message: MmsMessageRecord, @ColorInt textColor: Int) {
|
||||||
textView.text = "I'm a document"
|
val document = message.slideDeck.documentSlide!!
|
||||||
|
documentTitleTextView.text = document.fileName.or("Untitled File")
|
||||||
|
documentTitleTextView.setTextColor(textColor)
|
||||||
|
documentViewIconImageView.imageTintList = ColorStateList.valueOf(textColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun recycle() {
|
fun recycle() {
|
||||||
|
@ -8,6 +8,7 @@ import android.view.LayoutInflater
|
|||||||
import android.view.ViewOutlineProvider
|
import android.view.ViewOutlineProvider
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.annotation.ColorInt
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.core.graphics.BlendModeColorFilterCompat
|
import androidx.core.graphics.BlendModeColorFilterCompat
|
||||||
@ -67,7 +68,7 @@ class VisibleMessageContentView : LinearLayout {
|
|||||||
mainContainer.addView(voiceMessageView)
|
mainContainer.addView(voiceMessageView)
|
||||||
} else if (message is MmsMessageRecord && message.slideDeck.documentSlide != null) {
|
} else if (message is MmsMessageRecord && message.slideDeck.documentSlide != null) {
|
||||||
val documentView = DocumentView(context)
|
val documentView = DocumentView(context)
|
||||||
documentView.bind(message)
|
documentView.bind(message, getTextColor(message))
|
||||||
mainContainer.addView(documentView)
|
mainContainer.addView(documentView)
|
||||||
} else if (message is MmsMessageRecord && message.slideDeck.asAttachments().isNotEmpty()) {
|
} else if (message is MmsMessageRecord && message.slideDeck.asAttachments().isNotEmpty()) {
|
||||||
throw IllegalStateException("Not yet implemented; we may want to use Signal's album view here.")
|
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.setPadding(hPadding, vPadding, hPadding, vPadding)
|
||||||
result.text = message.body
|
result.text = message.body
|
||||||
result.setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.small_font_size))
|
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 uiMode = UiModeUtilities.getUserSelectedUiMode(context)
|
||||||
val colorID = if (message.isOutgoing) {
|
val colorID = if (message.isOutgoing) {
|
||||||
if (uiMode == UiMode.NIGHT) R.color.black else R.color.white
|
if (uiMode == UiMode.NIGHT) R.color.black else R.color.white
|
||||||
} else {
|
} else {
|
||||||
if (uiMode == UiMode.NIGHT) R.color.white else R.color.black
|
if (uiMode == UiMode.NIGHT) R.color.white else R.color.black
|
||||||
}
|
}
|
||||||
result.setTextColor(resources.getColorWithID(colorID, context.theme))
|
return resources.getColorWithID(colorID, context.theme)
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
}
|
}
|
@ -1,16 +1,30 @@
|
|||||||
<?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"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
|
android:padding="@dimen/medium_spacing"
|
||||||
android:gravity="center">
|
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
|
<TextView
|
||||||
android:id="@+id/textView"
|
android:id="@+id/documentTitleTextView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textSize="@dimen/medium_font_size"
|
android:layout_marginStart="4dp"
|
||||||
android:textColor="@color/text" />
|
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>
|
</LinearLayout>
|
Loading…
x
Reference in New Issue
Block a user