|
@@ -22,8 +22,12 @@
|
|
package com.owncloud.android.ui.adapter
|
|
package com.owncloud.android.ui.adapter
|
|
|
|
|
|
import android.content.Context
|
|
import android.content.Context
|
|
|
|
+import android.graphics.Color
|
|
|
|
+import android.graphics.drawable.ColorDrawable
|
|
|
|
+import android.os.AsyncTask
|
|
import android.view.View
|
|
import android.view.View
|
|
import android.widget.ImageView
|
|
import android.widget.ImageView
|
|
|
|
+import androidx.core.content.res.ResourcesCompat
|
|
import com.elyeproj.loaderviewlibrary.LoaderImageView
|
|
import com.elyeproj.loaderviewlibrary.LoaderImageView
|
|
import com.nextcloud.client.account.User
|
|
import com.nextcloud.client.account.User
|
|
import com.nextcloud.client.preferences.AppPreferences
|
|
import com.nextcloud.client.preferences.AppPreferences
|
|
@@ -31,13 +35,18 @@ import com.owncloud.android.R
|
|
import com.owncloud.android.datamodel.FileDataStorageManager
|
|
import com.owncloud.android.datamodel.FileDataStorageManager
|
|
import com.owncloud.android.datamodel.OCFile
|
|
import com.owncloud.android.datamodel.OCFile
|
|
import com.owncloud.android.datamodel.ThumbnailsCacheManager
|
|
import com.owncloud.android.datamodel.ThumbnailsCacheManager
|
|
|
|
+import com.owncloud.android.datamodel.ThumbnailsCacheManager.AsyncGalleryImageDrawable
|
|
|
|
+import com.owncloud.android.datamodel.ThumbnailsCacheManager.GalleryImageGenerationTask
|
|
|
|
+import com.owncloud.android.datamodel.ThumbnailsCacheManager.GalleryImageGenerationTask.GalleryListener
|
|
import com.owncloud.android.datamodel.ThumbnailsCacheManager.ThumbnailGenerationTask
|
|
import com.owncloud.android.datamodel.ThumbnailsCacheManager.ThumbnailGenerationTask
|
|
import com.owncloud.android.lib.common.utils.Log_OC
|
|
import com.owncloud.android.lib.common.utils.Log_OC
|
|
import com.owncloud.android.ui.activity.ComponentsGetter
|
|
import com.owncloud.android.ui.activity.ComponentsGetter
|
|
import com.owncloud.android.ui.fragment.SearchType
|
|
import com.owncloud.android.ui.fragment.SearchType
|
|
import com.owncloud.android.ui.interfaces.OCFileListFragmentInterface
|
|
import com.owncloud.android.ui.interfaces.OCFileListFragmentInterface
|
|
|
|
+import com.owncloud.android.utils.BitmapUtils
|
|
import com.owncloud.android.utils.DisplayUtils
|
|
import com.owncloud.android.utils.DisplayUtils
|
|
import com.owncloud.android.utils.theme.ViewThemeUtils
|
|
import com.owncloud.android.utils.theme.ViewThemeUtils
|
|
|
|
+import com.owncloud.android.utils.MimeTypeUtil
|
|
|
|
|
|
@Suppress("LongParameterList", "TooManyFunctions")
|
|
@Suppress("LongParameterList", "TooManyFunctions")
|
|
class OCFileListDelegate(
|
|
class OCFileListDelegate(
|
|
@@ -100,16 +109,14 @@ class OCFileListDelegate(
|
|
) {
|
|
) {
|
|
// thumbnail
|
|
// thumbnail
|
|
imageView.tag = file.fileId
|
|
imageView.tag = file.fileId
|
|
- DisplayUtils.setGalleryImage(
|
|
|
|
|
|
+ setGalleryImage(
|
|
file,
|
|
file,
|
|
imageView,
|
|
imageView,
|
|
user,
|
|
user,
|
|
storageManager,
|
|
storageManager,
|
|
asyncGalleryTasks,
|
|
asyncGalleryTasks,
|
|
- gridView,
|
|
|
|
context,
|
|
context,
|
|
shimmer,
|
|
shimmer,
|
|
- preferences,
|
|
|
|
themeColorUtils,
|
|
themeColorUtils,
|
|
themeDrawableUtils,
|
|
themeDrawableUtils,
|
|
galleryRowHolder,
|
|
galleryRowHolder,
|
|
@@ -119,6 +126,92 @@ class OCFileListDelegate(
|
|
imageView.setOnClickListener { ocFileListFragmentInterface.onItemClicked(file) }
|
|
imageView.setOnClickListener { ocFileListFragmentInterface.onItemClicked(file) }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Suppress("ComplexMethod")
|
|
|
|
+ private fun setGalleryImage(
|
|
|
|
+ file: OCFile,
|
|
|
|
+ thumbnailView: ImageView,
|
|
|
|
+ user: User?,
|
|
|
|
+ storageManager: FileDataStorageManager?,
|
|
|
|
+ asyncTasks: MutableList<GalleryImageGenerationTask>,
|
|
|
|
+ context: Context,
|
|
|
|
+ shimmerThumbnail: LoaderImageView?,
|
|
|
|
+ themeColorUtils: ThemeColorUtils?,
|
|
|
|
+ themeDrawableUtils: ThemeDrawableUtils?,
|
|
|
|
+ galleryRowHolder: GalleryRowHolder,
|
|
|
|
+ width: Int
|
|
|
|
+ ) {
|
|
|
|
+ // cancel previous generation, if view is re-used
|
|
|
|
+ if (ThumbnailsCacheManager.cancelPotentialThumbnailWork(file, thumbnailView)) {
|
|
|
|
+ for (task in asyncTasks) {
|
|
|
|
+ if (file.remoteId != null && task.imageKey != null && file.remoteId == task.imageKey) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ val task = GalleryImageGenerationTask(
|
|
|
|
+ thumbnailView,
|
|
|
|
+ user,
|
|
|
|
+ storageManager,
|
|
|
|
+ asyncTasks,
|
|
|
|
+ file.remoteId,
|
|
|
|
+ context.resources.getColor(R.color.bg_default)
|
|
|
|
+ )
|
|
|
|
+ var drawable = MimeTypeUtil.getFileTypeIcon(
|
|
|
|
+ file.mimeType,
|
|
|
|
+ file.fileName,
|
|
|
|
+ user,
|
|
|
|
+ context,
|
|
|
|
+ themeColorUtils,
|
|
|
|
+ themeDrawableUtils
|
|
|
|
+ )
|
|
|
|
+ if (drawable == null) {
|
|
|
|
+ drawable = ResourcesCompat.getDrawable(
|
|
|
|
+ context.resources,
|
|
|
|
+ R.drawable.file_image,
|
|
|
|
+ null
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+ if (drawable == null) {
|
|
|
|
+ drawable = ColorDrawable(Color.GRAY)
|
|
|
|
+ }
|
|
|
|
+ val thumbnail = BitmapUtils.drawableToBitmap(drawable, width / 2, width / 2)
|
|
|
|
+ val asyncDrawable = AsyncGalleryImageDrawable(
|
|
|
|
+ context.resources,
|
|
|
|
+ thumbnail,
|
|
|
|
+ task
|
|
|
|
+ )
|
|
|
|
+ if (shimmerThumbnail != null) {
|
|
|
|
+ Log_OC.d("Shimmer", "start Shimmer")
|
|
|
|
+ DisplayUtils.startShimmer(shimmerThumbnail, thumbnailView)
|
|
|
|
+ }
|
|
|
|
+ task.setListener(object : GalleryListener {
|
|
|
|
+ override fun onSuccess() {
|
|
|
|
+ galleryRowHolder.binding.rowLayout.invalidate()
|
|
|
|
+ Log_OC.d("Shimmer", "stop Shimmer")
|
|
|
|
+ DisplayUtils.stopShimmer(shimmerThumbnail, thumbnailView)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onNewGalleryImage() {
|
|
|
|
+ galleryRowHolder.redraw()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onError() {
|
|
|
|
+ Log_OC.d("Shimmer", "stop Shimmer")
|
|
|
|
+ DisplayUtils.stopShimmer(shimmerThumbnail, thumbnailView)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ thumbnailView.setImageDrawable(asyncDrawable)
|
|
|
|
+ asyncTasks.add(task)
|
|
|
|
+ task.executeOnExecutor(
|
|
|
|
+ AsyncTask.THREAD_POOL_EXECUTOR,
|
|
|
|
+ file
|
|
|
|
+ )
|
|
|
|
+ } catch (e: IllegalArgumentException) {
|
|
|
|
+ Log_OC.d(this, "ThumbnailGenerationTask : " + e.message)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
fun bindGridViewHolder(
|
|
fun bindGridViewHolder(
|
|
gridViewHolder: ListGridImageViewHolder,
|
|
gridViewHolder: ListGridImageViewHolder,
|
|
file: OCFile,
|
|
file: OCFile,
|