Show icon for common mime types

This commit is contained in:
Naveen 2022-11-05 00:20:04 +05:30
parent 0e3f651687
commit 61a57aa2b5
7 changed files with 49 additions and 2 deletions

View File

@ -90,6 +90,7 @@ class AttachmentsAdapter(
view.setupDocumentPreview( view.setupDocumentPreview(
uri = attachment.uri, uri = attachment.uri,
title = attachment.filename, title = attachment.filename,
mimeType = attachment.mimetype,
attachment = true, attachment = true,
onClick = { activity.launchViewIntent(attachment.uri, attachment.mimetype, attachment.filename) }, onClick = { activity.launchViewIntent(attachment.uri, attachment.mimetype, attachment.filename) },
onRemoveButtonClicked = { removeAttachment(attachment) } onRemoveButtonClicked = { removeAttachment(attachment) }

View File

@ -427,6 +427,7 @@ class ThreadAdapter(
setupDocumentPreview( setupDocumentPreview(
uri = uri, uri = uri,
title = attachment.filename, title = attachment.filename,
mimeType = attachment.mimetype,
onClick = { onClick = {
if (actModeCallback.isSelectable) { if (actModeCallback.isSelectable) {
holder.viewClicked(message) holder.viewClicked(message)

View File

@ -23,3 +23,19 @@ fun String.isVCardMimeType(): Boolean {
val lowercase = lowercase() val lowercase = lowercase()
return lowercase.endsWith("x-vcard") || lowercase.endsWith("vcard") return lowercase.endsWith("x-vcard") || lowercase.endsWith("vcard")
} }
fun String.isAudioMimeType(): Boolean {
return lowercase().startsWith("audio")
}
fun String.isCalendarMimeType(): Boolean {
return lowercase().endsWith("calendar")
}
fun String.isPdfMimeType(): Boolean {
return lowercase().endsWith("pdf")
}
fun String.isZipMimeType(): Boolean {
return lowercase().endsWith("zip")
}

View File

@ -6,7 +6,7 @@ import android.view.View
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.SimpleContactsHelper import com.simplemobiletools.commons.helpers.SimpleContactsHelper
import com.simplemobiletools.smsmessenger.R import com.simplemobiletools.smsmessenger.R
import com.simplemobiletools.smsmessenger.extensions.getFileSizeFromUri import com.simplemobiletools.smsmessenger.extensions.*
import kotlinx.android.synthetic.main.item_attachment_document.view.* import kotlinx.android.synthetic.main.item_attachment_document.view.*
import kotlinx.android.synthetic.main.item_attachment_vcard.view.* import kotlinx.android.synthetic.main.item_attachment_vcard.view.*
import kotlinx.android.synthetic.main.item_attachment_vcard_preview.view.* import kotlinx.android.synthetic.main.item_attachment_vcard_preview.view.*
@ -15,6 +15,7 @@ import kotlinx.android.synthetic.main.item_remove_attachment_button.view.*
fun View.setupDocumentPreview( fun View.setupDocumentPreview(
uri: Uri, uri: Uri,
title: String, title: String,
mimeType: String,
attachment: Boolean = false, attachment: Boolean = false,
onClick: (() -> Unit)? = null, onClick: (() -> Unit)? = null,
onLongClick: (() -> Unit)? = null, onLongClick: (() -> Unit)? = null,
@ -38,7 +39,8 @@ fun View.setupDocumentPreview(
document_attachment_holder.background.applyColorFilter(textColor) document_attachment_holder.background.applyColorFilter(textColor)
filename.setTextColor(textColor) filename.setTextColor(textColor)
file_size.setTextColor(textColor) file_size.setTextColor(textColor)
// todo: set icon drawable based on mime type
icon.setImageResource(getIconResourceForMimeType(mimeType))
icon.background.setTint(primaryColor) icon.background.setTint(primaryColor)
document_attachment_holder.background.applyColorFilter(primaryColor.darkenColor()) document_attachment_holder.background.applyColorFilter(primaryColor.darkenColor())
@ -140,3 +142,11 @@ fun View.setupVCardPreview(
} }
} }
} }
private fun getIconResourceForMimeType(mimeType: String) = when {
mimeType.isAudioMimeType() -> R.drawable.ic_vector_audio_file
mimeType.isCalendarMimeType() -> R.drawable.ic_calendar_month_vector
mimeType.isPdfMimeType() -> R.drawable.ic_vector_pdf
mimeType.isZipMimeType() -> R.drawable.ic_vector_folder_zip
else -> R.drawable.ic_document_vector
}

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M14,2H6C4.9,2 4.01,2.9 4.01,4L4,20c0,1.1 0.89,2 1.99,2H18c1.1,0 2,-0.9 2,-2V8L14,2zM16,13h-3v3.75c0,1.24 -1.01,2.25 -2.25,2.25S8.5,17.99 8.5,16.75c0,-1.24 1.01,-2.25 2.25,-2.25c0.46,0 0.89,0.14 1.25,0.38V11h4V13zM13,9V3.5L18.5,9H13z"/>
</vector>

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M20,6h-8l-2,-2H4C2.9,4 2.01,4.9 2.01,6L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8C22,6.9 21.1,6 20,6zM18,12h-2v2h2v2h-2v2h-2v-2h2v-2h-2v-2h2v-2h-2V8h2v2h2V12z"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="1024dp"
android:height="1024dp"
android:viewportWidth="1024"
android:viewportHeight="1024">
<path
android:pathData="M597.3,384h234.7L597.3,149.3V384M298.7,85.3h341.3l256,256v512a85.3,85.3 0,0 1,-85.3 85.3H298.7a85.3,85.3 0,0 1,-85.3 -85.3V170.7a85.3,85.3 0,0 1,85.3 -85.3m210.3,445.4c17.5,38.4 39.7,70 65.3,91.7l17.5,13.7c-37.1,6.8 -88.3,18.8 -142.5,39.7l-4.7,1.7 21.3,-44.4c19.2,-37.1 33.3,-70.8 43.1,-102.4m276.5,162.6c7.7,-7.7 11.5,-17.5 11.9,-28.2 1.3,-8.5 -0.9,-16.6 -5.1,-23.5 -12.4,-20.1 -44.4,-29.4 -97.3,-29.4l-55,3 -37.1,-24.7c-26.9,-22.2 -51.2,-61 -68.3,-109.2l1.7,-6c14.1,-56.7 27.3,-125.4 -0.9,-153.6a36.4,36.4 0,0 0,-26 -10.2h-10.2c-15.8,0 -29.9,16.6 -33.7,32.9 -15.8,56.7 -6.4,87.9 9.4,139.5v0.4c-10.7,37.5 -24.3,81.1 -46.1,125l-41,76.8 -38,20.9c-51.2,32 -75.5,67.8 -80.2,90.5 -1.7,8.1 -0.9,15.4 2.1,23l1.3,2.1 20.5,13.2 18.8,4.7c34.6,0 73.8,-40.5 126.7,-131l7.7,-3c43.9,-14.1 98.6,-23.9 171.9,-32 43.9,21.8 95.6,31.6 128,31.6 18.8,0 31.6,-4.7 38.8,-12.8m-17.5,-30.3l3.8,4.7c-0.4,4.3 -1.7,4.7 -3.8,5.5h-1.7l-8.1,0.9c-19.6,0 -49.9,-8.1 -81.1,-21.8 3.8,-4.3 5.5,-4.3 9.8,-4.3 59.7,0 76.8,10.7 81.1,14.9M376.7,725.3c-27.7,50.8 -52.9,78.9 -72.1,85.3 2.1,-16.2 21.3,-44.4 51.6,-72.1l20.5,-13.2m128.9,-294.8c-9.8,-38.4 -10.2,-69.5 -3,-87.5l3,-5.1 6.4,2.1c7.3,10.2 8.1,23.9 3.8,46.9l-1.3,6.8 -6.8,35 -2.1,1.7z"
android:fillColor="@android:color/white"/>
</vector>