@@ -46,6 +46,9 @@ import androidx.recyclerview.widget.DividerItemDecoration
46
46
import androidx.recyclerview.widget.GridLayoutManager
47
47
import androidx.recyclerview.widget.LinearLayoutManager
48
48
import com.bumptech.glide.Glide
49
+ import com.bumptech.glide.load.engine.GlideException
50
+ import com.bumptech.glide.request.RequestListener
51
+ import com.bumptech.glide.request.target.Target
49
52
import com.google.android.material.bottomsheet.BottomSheetBehavior
50
53
import com.google.android.material.bottomsheet.BottomSheetBehavior.BottomSheetCallback
51
54
import com.google.android.material.snackbar.Snackbar
@@ -134,6 +137,7 @@ import java.util.UUID
134
137
import java.util.concurrent.TimeUnit
135
138
import javax.inject.Inject
136
139
import javax.inject.Named
140
+ import javax.sql.DataSource
137
141
import kotlin.concurrent.Volatile
138
142
139
143
@@ -2353,12 +2357,50 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
2353
2357
selectedPlace?.pic?.substringAfterLast(" /" )?.takeIf { it.isNotEmpty() }?.let { imageName ->
2354
2358
Glide .with (binding!! .bottomSheetDetails.icon.context)
2355
2359
.clear(binding!! .bottomSheetDetails.icon)
2360
+
2361
+ val loadingDrawable = ContextCompat .getDrawable(
2362
+ binding!! .bottomSheetDetails.icon.context,
2363
+ R .drawable.loading_icon
2364
+ )
2365
+ val animation = AnimationUtils .loadAnimation(
2366
+ binding!! .bottomSheetDetails.icon.context,
2367
+ R .anim.rotate
2368
+ )
2369
+
2356
2370
Glide .with (binding!! .bottomSheetDetails.icon.context)
2357
2371
.load(" https://commons.wikimedia.org/wiki/Special:Redirect/file/$imageName ?width=25" )
2358
- .placeholder(fr.free.nrw.commons. R .drawable.ic_refresh_24dp_nearby )
2372
+ .placeholder(loadingDrawable )
2359
2373
.error(selectedPlace!! .label.icon)
2374
+ .listener(object : RequestListener <Drawable > {
2375
+ override fun onLoadFailed (
2376
+ e : GlideException ? ,
2377
+ model : Any? ,
2378
+ target : Target <Drawable >,
2379
+ isFirstResource : Boolean
2380
+ ): Boolean {
2381
+ binding!! .bottomSheetDetails.icon.clearAnimation()
2382
+ return false
2383
+ }
2384
+
2385
+ override fun onResourceReady (
2386
+ resource : Drawable ,
2387
+ model : Any ,
2388
+ target : Target <Drawable >? ,
2389
+ dataSource : com.bumptech.glide.load.DataSource ,
2390
+ isFirstResource : Boolean
2391
+ ): Boolean {
2392
+ binding!! .bottomSheetDetails.icon.clearAnimation()
2393
+ return false
2394
+ }
2395
+ })
2360
2396
.into(binding!! .bottomSheetDetails.icon)
2361
2397
2398
+ if (binding!! .bottomSheetDetails.icon.drawable != null && binding!! .bottomSheetDetails.icon.drawable.constantState == loadingDrawable?.constantState) {
2399
+ binding!! .bottomSheetDetails.icon.startAnimation(animation)
2400
+ } else {
2401
+ binding!! .bottomSheetDetails.icon.clearAnimation()
2402
+ }
2403
+
2362
2404
binding!! .bottomSheetDetails.icon.setOnClickListener {
2363
2405
handleMediaClick(imageName)
2364
2406
}
0 commit comments