Show icon for common mime types
This commit is contained in:
parent
0e3f651687
commit
61a57aa2b5
7 changed files with 49 additions and 2 deletions
|
|
@ -90,6 +90,7 @@ class AttachmentsAdapter(
|
|||
view.setupDocumentPreview(
|
||||
uri = attachment.uri,
|
||||
title = attachment.filename,
|
||||
mimeType = attachment.mimetype,
|
||||
attachment = true,
|
||||
onClick = { activity.launchViewIntent(attachment.uri, attachment.mimetype, attachment.filename) },
|
||||
onRemoveButtonClicked = { removeAttachment(attachment) }
|
||||
|
|
|
|||
|
|
@ -427,6 +427,7 @@ class ThreadAdapter(
|
|||
setupDocumentPreview(
|
||||
uri = uri,
|
||||
title = attachment.filename,
|
||||
mimeType = attachment.mimetype,
|
||||
onClick = {
|
||||
if (actModeCallback.isSelectable) {
|
||||
holder.viewClicked(message)
|
||||
|
|
|
|||
|
|
@ -23,3 +23,19 @@ fun String.isVCardMimeType(): Boolean {
|
|||
val lowercase = lowercase()
|
||||
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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import android.view.View
|
|||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
|
||||
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_vcard.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(
|
||||
uri: Uri,
|
||||
title: String,
|
||||
mimeType: String,
|
||||
attachment: Boolean = false,
|
||||
onClick: (() -> Unit)? = null,
|
||||
onLongClick: (() -> Unit)? = null,
|
||||
|
|
@ -38,7 +39,8 @@ fun View.setupDocumentPreview(
|
|||
document_attachment_holder.background.applyColorFilter(textColor)
|
||||
filename.setTextColor(textColor)
|
||||
file_size.setTextColor(textColor)
|
||||
// todo: set icon drawable based on mime type
|
||||
|
||||
icon.setImageResource(getIconResourceForMimeType(mimeType))
|
||||
icon.background.setTint(primaryColor)
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue