From 3a1f3242d89671548bb9a23ce25e2e5d9b18d486 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Wed, 27 Apr 2022 17:17:34 +0200 Subject: [PATCH] add fallback images for mimetypes if no preview image was found Signed-off-by: Marcel Hibbe --- .../talk/adapters/SharedItemsAdapter.kt | 50 +++++++++++++------ 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/SharedItemsAdapter.kt b/app/src/main/java/com/nextcloud/talk/adapters/SharedItemsAdapter.kt index 119e41bef..2ef4331e5 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/SharedItemsAdapter.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/SharedItemsAdapter.kt @@ -10,6 +10,7 @@ import com.facebook.drawee.interfaces.DraweeController import com.facebook.drawee.view.SimpleDraweeView import com.facebook.imagepipeline.common.RotationOptions import com.facebook.imagepipeline.request.ImageRequestBuilder +import com.nextcloud.talk.R import com.nextcloud.talk.databinding.AttachmentItemBinding import com.nextcloud.talk.repositories.SharedItem import com.nextcloud.talk.utils.FileViewerUtils @@ -48,23 +49,42 @@ class SharedItemsAdapter : RecyclerView.Adapter() .setImageRequest(imageRequest) .build() holder.binding.image.controller = draweeController - - holder.binding.image.setOnClickListener { - val fileViewerUtils = FileViewerUtils(it.context, currentItem.userEntity) - - fileViewerUtils.openFile( - currentItem.id, - currentItem.name, - currentItem.fileSize, - currentItem.path, - currentItem.link, - currentItem.mimeType, - null, - null, - it as SimpleDraweeView - ) + } else { + when (currentItem.mimeType) { + "video/mp4", + "video/quicktime", + "video/ogg" + -> holder.binding.image.setImageResource(R.drawable.ic_mimetype_video) + "audio/mpeg", + "audio/wav", + "audio/ogg", + -> holder.binding.image.setImageResource(R.drawable.ic_mimetype_audio) + "image/png", + "image/jpeg", + "image/gif" + -> holder.binding.image.setImageResource(R.drawable.ic_mimetype_image) + "text/markdown", + "text/plain" + -> holder.binding.image.setImageResource(R.drawable.ic_mimetype_text) + else + -> holder.binding.image.setImageResource(R.drawable.ic_mimetype_file) } } + holder.binding.image.setOnClickListener { + val fileViewerUtils = FileViewerUtils(it.context, currentItem.userEntity) + + fileViewerUtils.openFile( + currentItem.id, + currentItem.name, + currentItem.fileSize, + currentItem.path, + currentItem.link, + currentItem.mimeType, + null, + null, + it as SimpleDraweeView + ) + } } override fun getItemCount(): Int {