Skip to content

Commit a8e38f4

Browse files
Updated Icon & Added Animation for Nearby (commons-app#6201)
* Applied better animation in nearby * Refactor: Reduce Duration of Rotate Animation Decreased the duration of the rotate animation from 1000ms to 500ms in `rotate.xml`, resulting in a faster rotation speed.
1 parent d32ab15 commit a8e38f4

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed

app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.kt

+43-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ import androidx.recyclerview.widget.DividerItemDecoration
4646
import androidx.recyclerview.widget.GridLayoutManager
4747
import androidx.recyclerview.widget.LinearLayoutManager
4848
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
4952
import com.google.android.material.bottomsheet.BottomSheetBehavior
5053
import com.google.android.material.bottomsheet.BottomSheetBehavior.BottomSheetCallback
5154
import com.google.android.material.snackbar.Snackbar
@@ -134,6 +137,7 @@ import java.util.UUID
134137
import java.util.concurrent.TimeUnit
135138
import javax.inject.Inject
136139
import javax.inject.Named
140+
import javax.sql.DataSource
137141
import kotlin.concurrent.Volatile
138142

139143

@@ -2353,12 +2357,50 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
23532357
selectedPlace?.pic?.substringAfterLast("/")?.takeIf { it.isNotEmpty() }?.let { imageName ->
23542358
Glide.with(binding!!.bottomSheetDetails.icon.context)
23552359
.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+
23562370
Glide.with(binding!!.bottomSheetDetails.icon.context)
23572371
.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)
23592373
.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+
})
23602396
.into(binding!!.bottomSheetDetails.icon)
23612397

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+
23622404
binding!!.bottomSheetDetails.icon.setOnClickListener {
23632405
handleMediaClick(imageName)
23642406
}

app/src/main/res/anim/rotate.xml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<rotate
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:fromDegrees="0"
5+
android:toDegrees="360"
6+
android:pivotX="50%"
7+
android:pivotY="50%"
8+
android:duration="500"
9+
android:repeatCount="infinite"
10+
android:interpolator="@android:anim/linear_interpolator"/>
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item>
4+
<vector
5+
android:width="24dp"
6+
android:height="24dp"
7+
android:viewportWidth="24"
8+
android:viewportHeight="24">
9+
<path
10+
android:pathData="M12,4 A8,8 0 1,1 4,12 A8,8 0 1,5 19.42 ,15"
11+
android:strokeWidth="2"
12+
android:strokeColor="#2196F3"
13+
android:fillColor="#00000000"
14+
android:trimPathStart="0.2"
15+
android:trimPathEnd="1.0"/>
16+
</vector>
17+
</item>
18+
19+
<item>
20+
<vector
21+
android:width="24dp"
22+
android:height="24dp"
23+
android:viewportWidth="24"
24+
android:viewportHeight="24">
25+
<path
26+
android:pathData="M12,4 A8,8 0 1,1 4,12 A8,8 0 1,1 12,4"
27+
android:strokeWidth="2"
28+
android:strokeColor="#FFFFFF"
29+
android:fillColor="#00000000"
30+
android:trimPathStart="0.0"
31+
android:trimPathEnd="0.2"/>
32+
</vector>
33+
</item>
34+
35+
<item android:right="12dp">
36+
<rotate
37+
android:fromDegrees="0"
38+
android:toDegrees="360"
39+
android:pivotX="50%"
40+
android:pivotY="50%">
41+
<shape android:shape="ring">
42+
<size
43+
android:width="12dp"
44+
android:height="2dp"/>
45+
<solid android:color="#2196F3"/>
46+
</shape>
47+
</rotate>
48+
</item>
49+
</layer-list>

0 commit comments

Comments
 (0)