feat: add download preview containing file size

This commit is contained in:
0x330a
2022-11-11 16:38:15 +11:00
parent 12ba4d727b
commit 0de0d613a3
5 changed files with 58 additions and 17 deletions

View File

@@ -4,7 +4,6 @@ import android.content.Context
import android.util.AttributeSet
import android.widget.LinearLayout
import androidx.annotation.ColorInt
import androidx.core.content.ContextCompat
import dagger.hilt.android.AndroidEntryPoint
import network.loki.messenger.R
import network.loki.messenger.databinding.ViewPendingAttachmentBinding
@@ -15,6 +14,7 @@ import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.conversation.v2.dialogs.AutoDownloadDialog
import org.thoughtcrime.securesms.util.ActivityDispatcher
import org.thoughtcrime.securesms.util.createAndStartAttachmentDownload
import org.thoughtcrime.securesms.util.displaySize
import java.util.Locale
import javax.inject.Inject
@@ -24,7 +24,8 @@ class PendingAttachmentView: LinearLayout {
enum class AttachmentType {
AUDIO,
DOCUMENT,
MEDIA
IMAGE,
VIDEO,
}
// region Lifecycle
@@ -37,17 +38,18 @@ class PendingAttachmentView: LinearLayout {
// region Updating
fun bind(attachmentType: AttachmentType, @ColorInt textColor: Int, attachment: DatabaseAttachment) {
val (iconRes, stringRes) = when (attachmentType) {
AttachmentType.AUDIO -> R.drawable.ic_microphone to R.string.Slide_audio
AttachmentType.DOCUMENT -> R.drawable.ic_document_large_light to R.string.document
AttachmentType.MEDIA -> R.drawable.ic_image_white_24dp to R.string.media
val stringRes = when (attachmentType) {
AttachmentType.AUDIO -> R.string.Slide_audio
AttachmentType.DOCUMENT -> R.string.document
AttachmentType.IMAGE -> R.string.image
AttachmentType.VIDEO -> R.string.video
}
val iconDrawable = ContextCompat.getDrawable(context,iconRes)!!
iconDrawable.mutate().setTint(textColor)
val text = context.getString(R.string.UntrustedAttachmentView_download_attachment, context.getString(stringRes).toLowerCase(Locale.ROOT))
binding.untrustedAttachmentIcon.setImageDrawable(iconDrawable)
binding.untrustedAttachmentTitle.text = text
val text = context.getString(R.string.UntrustedAttachmentView_download_attachment, context.getString(stringRes).lowercase(Locale.ROOT))
binding.pendingDownloadIcon.setColorFilter(textColor)
binding.pendingDownloadSize.text = attachment.displaySize()
binding.pendingDownloadTitle.text = text
}
// endregion

View File

@@ -192,7 +192,7 @@ class VisibleMessageContentView : LinearLayout {
val firstAttachment = message.slideDeck.asAttachments().first() as? DatabaseAttachment
firstAttachment?.let { attachment ->
binding.pendingAttachmentView.root.bind(
PendingAttachmentView.AttachmentType.MEDIA,
PendingAttachmentView.AttachmentType.IMAGE,
getTextColor(context,message),
attachment
)

View File

@@ -0,0 +1,18 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="57dp"
android:height="44dp"
android:viewportWidth="57"
android:viewportHeight="44">
<path
android:pathData="M10.066,2.663L51.25,6.085A4,4 62.853,0 1,54.905 10.402L52.546,38.797A4,4 72.977,0 1,48.229 42.452L7.044,39.031A4,4 77.145,0 1,3.389 34.713L5.748,6.318A4,4 50.655,0 1,10.066 2.663z"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#000000"/>
<path
android:pathData="M5.182,1.414L45.74,1.414A4,4 0,0 1,49.74 5.414L49.74,33.907A4,4 0,0 1,45.74 37.907L5.182,37.907A4,4 0,0 1,1.182 33.907L1.182,5.414A4,4 0,0 1,5.182 1.414z"
android:strokeWidth="2"
android:strokeColor="#000000"/>
<path
android:pathData="M14.528,20.623L1.708,32.896C1.034,33.542 0.896,34.569 1.376,35.37L1.855,36.168C1.957,36.338 2.083,36.494 2.237,36.619C2.866,37.13 4.009,37.879 4.918,37.879H46.554C46.917,37.879 47.263,37.781 47.574,37.594L48.552,37.007C49.154,36.646 49.523,35.995 49.523,35.292V24.57C49.523,23.99 49.272,23.439 48.834,23.059L38.721,14.277C37.899,13.563 36.656,13.638 35.926,14.446L26.337,25.058C25.646,25.822 24.489,25.937 23.662,25.324L17.102,20.461C16.319,19.88 15.231,19.949 14.528,20.623Z"
android:fillColor="#000000"/>
</vector>

View File

@@ -6,22 +6,41 @@
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:padding="@dimen/medium_spacing"
android:paddingHorizontal="12dp"
android:paddingVertical="@dimen/small_spacing"
android:gravity="center">
<ImageView
android:id="@+id/untrustedAttachmentIcon"
android:id="@+id/pendingDownloadIcon"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_document_large_light"
android:src="@drawable/ic_media"
app:tint="?android:textColorPrimary" />
<TextView
android:id="@+id/untrustedAttachmentTitle"
android:id="@+id/pendingDownloadSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:textSize="@dimen/small_font_size"
android:textSize="@dimen/very_small_font_size"
android:textColor="?android:textColorPrimary"
android:maxLines="1"
tools:text="1.23MB"
/>
<ImageView
android:layout_width="2dp"
android:layout_height="2dp"
android:src="@drawable/circle_tintable"
android:layout_gravity="center"
android:layout_marginHorizontal="6dp"
app:tint="?android:textColorPrimary" />
<TextView
android:id="@+id/pendingDownloadTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/very_small_font_size"
android:textColor="?android:textColorPrimary"
tools:text="I'm a very long document title. Did you know that?"
android:maxLines="2"

View File

@@ -880,4 +880,6 @@
<string name="conversation_settings_leave_group">Leave Group</string>
<string name="conversation_settings_group_members">Group Members</string>
<string name="conversation_settings_delete_group">Delete Group</string>
<string name="image">image</string>
<string name="video">video</string>
</resources>