Unified search: Round thumbnails when requested by server

Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey Vilas 2021-10-18 16:49:47 +02:00
parent b6cd8af18a
commit f927cfe2d8
No known key found for this signature in database
GPG key ID: 2585783189A62105

View file

@ -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<String, Bitmap> {
override fun onException(
e: Exception?,
model: String?,
target: Target<Bitmap>?,
isFirstResource: Boolean
): Boolean = false
override fun onResourceReady(
resource: Bitmap?,
model: String?,
target: Target<Bitmap>?,
isFromMemoryCache: Boolean,
isFirstResource: Boolean
): Boolean {
if (entry.rounded) {
val drawable = BitmapUtils.bitmapToCircularBitmapDrawable(context.resources, resource)
binding.thumbnail.setImageDrawable(drawable)
return true
}
return false
}
}
}