diff --git a/app/.attach_pid781771 b/app/.attach_pid781771 deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.kt b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.kt index 8a9fe6e86..500231642 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.kt +++ b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.kt @@ -46,6 +46,9 @@ import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import com.bumptech.glide.Glide +import com.bumptech.glide.load.engine.GlideException +import com.bumptech.glide.request.RequestListener +import com.bumptech.glide.request.target.Target import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior.BottomSheetCallback import com.google.android.material.snackbar.Snackbar @@ -135,6 +138,7 @@ import java.util.UUID import java.util.concurrent.TimeUnit import javax.inject.Inject import javax.inject.Named +import javax.sql.DataSource import kotlin.concurrent.Volatile @@ -2356,12 +2360,50 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), selectedPlace?.pic?.substringAfterLast("/")?.takeIf { it.isNotEmpty() }?.let { imageName -> Glide.with(binding!!.bottomSheetDetails.icon.context) .clear(binding!!.bottomSheetDetails.icon) + + val loadingDrawable = ContextCompat.getDrawable( + binding!!.bottomSheetDetails.icon.context, + R.drawable.loading_icon + ) + val animation = AnimationUtils.loadAnimation( + binding!!.bottomSheetDetails.icon.context, + R.anim.rotate + ) + Glide.with(binding!!.bottomSheetDetails.icon.context) .load("https://commons.wikimedia.org/wiki/Special:Redirect/file/$imageName?width=25") - .placeholder(fr.free.nrw.commons.R.drawable.ic_refresh_24dp_nearby) + .placeholder(loadingDrawable) .error(selectedPlace!!.label.icon) + .listener(object : RequestListener { + override fun onLoadFailed( + e: GlideException?, + model: Any?, + target: Target, + isFirstResource: Boolean + ): Boolean { + binding!!.bottomSheetDetails.icon.clearAnimation() + return false + } + + override fun onResourceReady( + resource: Drawable, + model: Any, + target: Target?, + dataSource: com.bumptech.glide.load.DataSource, + isFirstResource: Boolean + ): Boolean { + binding!!.bottomSheetDetails.icon.clearAnimation() + return false + } + }) .into(binding!!.bottomSheetDetails.icon) + if (binding!!.bottomSheetDetails.icon.drawable != null && binding!!.bottomSheetDetails.icon.drawable.constantState == loadingDrawable?.constantState) { + binding!!.bottomSheetDetails.icon.startAnimation(animation) + } else { + binding!!.bottomSheetDetails.icon.clearAnimation() + } + binding!!.bottomSheetDetails.icon.setOnClickListener { handleMediaClick(imageName) } diff --git a/app/src/main/res/anim/rotate.xml b/app/src/main/res/anim/rotate.xml new file mode 100644 index 000000000..8c42dc3e5 --- /dev/null +++ b/app/src/main/res/anim/rotate.xml @@ -0,0 +1,10 @@ + + \ No newline at end of file diff --git a/app/src/main/res/drawable/loading_icon.xml b/app/src/main/res/drawable/loading_icon.xml new file mode 100644 index 000000000..babc0da6f --- /dev/null +++ b/app/src/main/res/drawable/loading_icon.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file