Skip to content

Commit 817699e

Browse files
committed
fix git conflict
Signed-off-by: alperozturk <[email protected]>
1 parent 2f29d8f commit 817699e

File tree

2 files changed

+29
-87
lines changed

2 files changed

+29
-87
lines changed

app/src/main/java/com/owncloud/android/ui/adapter/GalleryRowHolder.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,8 @@ class GalleryRowHolder(
112112
invalidate()
113113
}
114114

115-
val drawable = ThumbnailsCacheManager.AsyncGalleryImageDrawable(
116-
context.resources,
117-
defaultBitmap,
118-
null
119-
)
120115
val rowCellImageView = ImageView(context).apply {
121-
setImageDrawable(drawable)
116+
setImageBitmap(defaultBitmap)
122117
adjustViewBounds = true
123118
scaleType = ImageView.ScaleType.FIT_XY
124119
}
@@ -180,7 +175,7 @@ class GalleryRowHolder(
180175
adjustRowCell(thumbnail, isChecked)
181176
adjustCheckBox(checkBoxImageView, isChecked)
182177

183-
ocFileListDelegate.bindGalleryRowThumbnail(
178+
ocFileListDelegate.bindGalleryRow(
184179
shimmer,
185180
thumbnail,
186181
file,

app/src/main/java/com/owncloud/android/ui/adapter/OCFileListDelegate.kt

Lines changed: 27 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@ package com.owncloud.android.ui.adapter
99

1010
import android.content.Context
1111
import android.content.res.Configuration
12-
import android.graphics.Color
13-
import android.graphics.drawable.BitmapDrawable
1412
import android.view.View
1513
import android.widget.ImageView
1614
import androidx.core.content.ContextCompat
17-
import androidx.core.content.res.ResourcesCompat
18-
import androidx.core.graphics.drawable.toDrawable
1915
import com.elyeproj.loaderviewlibrary.LoaderImageView
2016
import com.nextcloud.android.common.ui.theme.utils.ColorRole
2117
import com.nextcloud.client.account.User
@@ -39,10 +35,8 @@ import com.owncloud.android.ui.activity.FolderPickerActivity
3935
import com.owncloud.android.ui.fragment.GalleryFragment
4036
import com.owncloud.android.ui.fragment.SearchType
4137
import com.owncloud.android.ui.interfaces.OCFileListFragmentInterface
42-
import com.owncloud.android.utils.BitmapUtils
4338
import com.owncloud.android.utils.DisplayUtils
4439
import com.owncloud.android.utils.EncryptionUtils
45-
import com.owncloud.android.utils.MimeTypeUtil
4640
import com.owncloud.android.utils.theme.ViewThemeUtils
4741
import kotlinx.coroutines.CoroutineScope
4842
import 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

Comments
 (0)