|
1 | 1 | package com.simplemobiletools.launcher.adapters |
2 | 2 |
|
| 3 | +import android.graphics.drawable.Drawable |
3 | 4 | import android.view.LayoutInflater |
4 | 5 | import android.view.View |
5 | 6 | import android.view.ViewGroup |
6 | 7 | import androidx.recyclerview.widget.RecyclerView |
7 | 8 | import com.bumptech.glide.Glide |
8 | 9 | import com.bumptech.glide.load.engine.DiskCacheStrategy |
9 | 10 | import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions |
| 11 | +import com.bumptech.glide.request.target.DrawableImageViewTarget |
10 | 12 | import com.bumptech.glide.request.transition.DrawableCrossFadeFactory |
| 13 | +import com.bumptech.glide.request.transition.Transition |
11 | 14 | import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller |
12 | 15 | import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor |
13 | 16 | import com.simplemobiletools.commons.extensions.getProperTextColor |
@@ -109,15 +112,26 @@ class LaunchersAdapter( |
109 | 112 | binding.launcherLabel.setTextColor(textColor) |
110 | 113 | binding.launcherIcon.setPadding(iconPadding, iconPadding, iconPadding, 0) |
111 | 114 |
|
112 | | - val factory = DrawableCrossFadeFactory.Builder(150).setCrossFadeEnabled(true).build() |
113 | | - val placeholderDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.placeholder_drawable, launcher.thumbnailColor) |
114 | | - |
115 | | - Glide.with(activity) |
116 | | - .load(launcher.drawable) |
117 | | - .placeholder(placeholderDrawable) |
118 | | - .diskCacheStrategy(DiskCacheStrategy.RESOURCE) |
119 | | - .transition(DrawableTransitionOptions.withCrossFade(factory)) |
120 | | - .into(binding.launcherIcon) |
| 115 | + // Once all images are loaded and crossfades are done, directly set drawables |
| 116 | + if (launcher.drawable != null && binding.launcherIcon.tag == true) { |
| 117 | + binding.launcherIcon.setImageDrawable(launcher.drawable) |
| 118 | + } else { |
| 119 | + val factory = DrawableCrossFadeFactory.Builder(150).setCrossFadeEnabled(true).build() |
| 120 | + val placeholderDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.placeholder_drawable, launcher.thumbnailColor) |
| 121 | + |
| 122 | + Glide.with(activity) |
| 123 | + .load(launcher.drawable) |
| 124 | + .placeholder(placeholderDrawable) |
| 125 | + .diskCacheStrategy(DiskCacheStrategy.RESOURCE) |
| 126 | + .transition(DrawableTransitionOptions.withCrossFade(factory)) |
| 127 | + .into(object : DrawableImageViewTarget(binding.launcherIcon) { |
| 128 | + override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) { |
| 129 | + super.onResourceReady(resource, transition) |
| 130 | + // Set tag to true to mark that crossfade was already done on this view |
| 131 | + view.tag = true |
| 132 | + } |
| 133 | + }) |
| 134 | + } |
121 | 135 |
|
122 | 136 | setOnClickListener { itemClick(launcher) } |
123 | 137 | setOnLongClickListener { view -> |
|
0 commit comments