bumptech / bumptech/glide

doesn't display images after loading.

Open
#4,711 1 comment 0 reactions 0 assignees View on GitHub
stale
Dominant language
Java
Stars
35k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
8

Description

**Glide Version**: 4.4.0

**Device/Android Version**: pixel 4 XL / Android 12 API 31

I am trying to display multiple images on the chat screen using the recycleView.
10 images are displayed at a time, and when I scroll to the top, the additional 10 images are displayed.

The problem occurs when the additional 10 images are loaded.
When I load the additional 10, I get a problem: The 10 loaded files may or may not have images. (Of the 10, those loaded first are most likely to have images displayed.)
Images that were originally displayed may no longer be displayed at the time of loading.

thanks.

listAdapter
```kotlin
class ScheduleImageListAdapter(private val chatData: ChatData, private val viewModel: ChatViewModel): RecyclerView.Adapter() {

class ViewHolder (val binding: ViewChatScheduleCellItemBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(file: ScheduleFile, viewModel: ChatViewModel) {
binding.run {
this.scheduleFile = file
appCompatImageView.setOnClickListener {
viewModel.onClickScheduleFile(file)
}

executePendingBindings()
}
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
return ViewHolder(
ViewChatScheduleCellItemBinding.inflate(
layoutInflater,
parent,
false
)
)
}

override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
val file = chatData.schedule?.files?.get(position)
viewHolder.bind(file!!, viewModel)
}

override fun getItemCount(): Int {
val count = chatData.schedule?.files?.size ?: 0
return when(chatData.showMoreType) {
2 -> count
else -> kotlin.math.min(count, 5)
}
}

override fun getItemId(position: Int): Long {
return position.toLong()
}

override fun getItemViewType(position: Int): Int {
return position
}
}
```

CustomBindingAdapter.kt
```kotlin
@JvmStatic
@BindingAdapter("android:imageUrl")
fun AppCompatImageView.imageUrl(url: String?) {
// Timber.d("test url ${url}")
url?.let {
val requestOptions = RequestOptions().apply {placeholder(R.drawable.image_loading)
.error(android.R.color.holo_red_light)
.fallback(android.R.color.holo_orange_light)}
// Glide.with(this).load(url).apply(requestOptions).into(this)
Glide.with(this).load(url).apply(requestOptions).listener(object : RequestListener {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target?,
isFirstResource: Boolean
): Boolean {
// Timber.d("test e ${e}")
// Timber.d("test model ${model}")
// Timber.d("test target ${target}")
// Timber.d("test isFirstResource ${isFirstResource}")
return true
}

override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: Target?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
// Timber.d("test resource ${resource}")
// Timber.d("test model ${model}")
// Timber.d("test target ${target}")
// Timber.d("test isFirstResource ${isFirstResource}")
return false
}
}).into(this)
} ?: run {
setImageBitmap(null)
}
}
```

**Layout XML**:
view_chat_schedule_cell_item.xml
```xml





```

Contributor guide

Open the contributing guide

Research direction

Review the RecyclerView adapter, CustomBindingAdapter.kt, and view_chat_schedule_cell_item.xml together, then reproduce the loading behavior on Pixel 4 XL with Android 12 and Glide 4.4.0. Done means isolating a reproducible cause for images disappearing or failing to display when additional items load, with the relevant binding or loading path identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.