mirror of
https://github.com/nextcloud/android.git
synced 2024-11-22 21:25:35 +03:00
Unified search: Round thumbnails when requested by server
Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
b6cd8af18a
commit
f927cfe2d8
1 changed files with 31 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue