From f927cfe2d8ceada0d66b0557a0c76dfe7658365d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey=20Vilas?= Date: Mon, 18 Oct 2021 16:49:47 +0200 Subject: [PATCH] Unified search: Round thumbnails when requested by server MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Brey Vilas --- .../ui/adapter/UnifiedSearchItemViewHolder.kt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main/java/com/owncloud/android/ui/adapter/UnifiedSearchItemViewHolder.kt b/src/main/java/com/owncloud/android/ui/adapter/UnifiedSearchItemViewHolder.kt index 62a8cfbd2b..d80b8df6ab 100644 --- a/src/main/java/com/owncloud/android/ui/adapter/UnifiedSearchItemViewHolder.kt +++ b/src/main/java/com/owncloud/android/ui/adapter/UnifiedSearchItemViewHolder.kt @@ -22,10 +22,13 @@ package com.owncloud.android.ui.adapter import android.content.Context +import android.graphics.Bitmap import android.view.View import androidx.core.content.res.ResourcesCompat import com.afollestad.sectionedrecyclerview.SectionedViewHolder import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestListener +import com.bumptech.glide.request.target.Target import com.nextcloud.client.account.User import com.nextcloud.client.network.ClientFactory import com.owncloud.android.R @@ -33,6 +36,7 @@ import com.owncloud.android.databinding.UnifiedSearchItemBinding import com.owncloud.android.datamodel.FileDataStorageManager import com.owncloud.android.lib.common.SearchResultEntry import com.owncloud.android.ui.interfaces.UnifiedSearchListInterface +import com.owncloud.android.utils.BitmapUtils import com.owncloud.android.utils.MimeTypeUtil import com.owncloud.android.utils.glide.CustomGlideStreamLoader @@ -69,11 +73,38 @@ class UnifiedSearchItemViewHolder( Glide.with(context).using(CustomGlideStreamLoader(user, clientFactory)) .load(entry.thumbnailUrl) + .asBitmap() .placeholder(placeholder) .error(placeholder) .animate(android.R.anim.fade_in) + .listener(RoundIfNeededListener(entry)) .into(binding.thumbnail) binding.unifiedSearchItemLayout.setOnClickListener { listInterface.onSearchResultClicked(entry) } } + + private inner class RoundIfNeededListener(private val entry: SearchResultEntry) : + RequestListener { + override fun onException( + e: Exception?, + model: String?, + target: Target?, + isFirstResource: Boolean + ): Boolean = false + + override fun onResourceReady( + resource: Bitmap?, + model: String?, + target: Target?, + isFromMemoryCache: Boolean, + isFirstResource: Boolean + ): Boolean { + if (entry.rounded) { + val drawable = BitmapUtils.bitmapToCircularBitmapDrawable(context.resources, resource) + binding.thumbnail.setImageDrawable(drawable) + return true + } + return false + } + } }