@@ -9,13 +9,9 @@ package com.owncloud.android.ui.adapter
99
1010import android.content.Context
1111import android.content.res.Configuration
12- import android.graphics.Color
13- import android.graphics.drawable.BitmapDrawable
1412import android.view.View
1513import android.widget.ImageView
1614import androidx.core.content.ContextCompat
17- import androidx.core.content.res.ResourcesCompat
18- import androidx.core.graphics.drawable.toDrawable
1915import com.elyeproj.loaderviewlibrary.LoaderImageView
2016import com.nextcloud.android.common.ui.theme.utils.ColorRole
2117import com.nextcloud.client.account.User
@@ -39,10 +35,8 @@ import com.owncloud.android.ui.activity.FolderPickerActivity
3935import com.owncloud.android.ui.fragment.GalleryFragment
4036import com.owncloud.android.ui.fragment.SearchType
4137import com.owncloud.android.ui.interfaces.OCFileListFragmentInterface
42- import com.owncloud.android.utils.BitmapUtils
4338import com.owncloud.android.utils.DisplayUtils
4439import com.owncloud.android.utils.EncryptionUtils
45- import com.owncloud.android.utils.MimeTypeUtil
4640import com.owncloud.android.utils.theme.ViewThemeUtils
4741import kotlinx.coroutines.CoroutineScope
4842import kotlinx.coroutines.Dispatchers
@@ -72,6 +66,7 @@ class OCFileListDelegate(
7266 var isMultiSelect = false
7367 private val asyncTasks: MutableList <ThumbnailsCacheManager .ThumbnailGenerationTask > = ArrayList ()
7468 private val ioScope = CoroutineScope (Dispatchers .IO )
69+ private val galleryImageGenerationJob = GalleryImageGenerationJob (user, storageManager)
7570
7671 fun setHighlightedItem (highlightedItem : OCFile ? ) {
7772 this .highlightedItem = highlightedItem
@@ -104,7 +99,7 @@ class OCFileListDelegate(
10499 checkedFiles.clear()
105100 }
106101
107- fun bindGalleryRowThumbnail (
102+ fun bindGalleryRow (
108103 shimmer : LoaderImageView ? ,
109104 imageView : ImageView ,
110105 file : OCFile ,
@@ -113,13 +108,31 @@ class OCFileListDelegate(
113108 ) {
114109 imageView.tag = file.fileId
115110
116- setGalleryImage(
117- file,
118- imageView,
119- shimmer,
120- galleryRowHolder,
121- width
122- )
111+ ioScope.launch {
112+ galleryImageGenerationJob.run (
113+ file,
114+ imageView,
115+ width,
116+ viewThemeUtils,
117+ object : GalleryImageGenerationListener {
118+ override fun onSuccess () {
119+ galleryRowHolder.binding.rowLayout.invalidate()
120+ Log_OC .d(tag, " setGalleryImage.onSuccess()" )
121+ DisplayUtils .stopShimmer(shimmer, imageView)
122+ }
123+
124+ override fun onNewGalleryImage () {
125+ Log_OC .d(tag, " setGalleryImage.updateRowVisuals()" )
126+ galleryRowHolder.updateRowVisuals()
127+ }
128+
129+ override fun onError () {
130+ Log_OC .d(tag, " setGalleryImage.onError()" )
131+ DisplayUtils .stopShimmer(shimmer, imageView)
132+ }
133+ }
134+ )
135+ }
123136
124137 imageView.setOnClickListener {
125138 ocFileListFragmentInterface.onItemClicked(file)
@@ -138,72 +151,6 @@ class OCFileListDelegate(
138151 }
139152 }
140153
141- private fun getGalleryDrawable (
142- file : OCFile ,
143- width : Int
144- ): BitmapDrawable {
145- val placeholder = MimeTypeUtil .getFileTypeIcon(
146- file.mimeType,
147- file.fileName,
148- context,
149- viewThemeUtils
150- )
151- ? : ResourcesCompat .getDrawable(context.resources, R .drawable.file_image, null )
152- ? : Color .GRAY .toDrawable()
153-
154- val bitmap = BitmapUtils .drawableToBitmap(
155- placeholder,
156- width / 2 ,
157- width / 2
158- )
159-
160- return BitmapDrawable (context.resources, bitmap)
161- }
162-
163- private val scope = CoroutineScope (Dispatchers .IO )
164- private val galleryImageGenerationJob = GalleryImageGenerationJob (user, storageManager)
165-
166- @Suppress(" ComplexMethod" )
167- private fun setGalleryImage (
168- file : OCFile ,
169- thumbnailView : ImageView ,
170- shimmerThumbnail : LoaderImageView ? ,
171- galleryRowHolder : GalleryRowHolder ,
172- width : Int
173- ) {
174- scope.launch {
175- // add placeholder first
176- withContext(Dispatchers .Main ) {
177- val asyncDrawable = getGalleryDrawable(file, width)
178-
179- if (shimmerThumbnail != null ) {
180- Log_OC .d(tag, " setGalleryImage.startShimmer()" )
181- DisplayUtils .startShimmer(shimmerThumbnail, thumbnailView)
182- }
183-
184- thumbnailView.setImageDrawable(asyncDrawable)
185- }
186-
187- galleryImageGenerationJob.run (file, thumbnailView, object : GalleryImageGenerationListener {
188- override fun onSuccess () {
189- galleryRowHolder.binding.rowLayout.invalidate()
190- Log_OC .d(tag, " setGalleryImage.onSuccess()" )
191- DisplayUtils .stopShimmer(shimmerThumbnail, thumbnailView)
192- }
193-
194- override fun onNewGalleryImage () {
195- Log_OC .d(tag, " updateRowVisuals" )
196- galleryRowHolder.updateRowVisuals()
197- }
198-
199- override fun onError () {
200- Log_OC .d(tag, " setGalleryImage.onError()" )
201- DisplayUtils .stopShimmer(shimmerThumbnail, thumbnailView)
202- }
203- })
204- }
205- }
206-
207154 fun setThumbnail (thumbnail : ImageView , shimmerThumbnail : LoaderImageView ? , file : OCFile ) {
208155 DisplayUtils .setThumbnail(
209156 file,
0 commit comments