Skip to content
This repository was archived by the owner on Dec 16, 2023. It is now read-only.

Commit e568e51

Browse files
committed
Add pull to refresh in products screen
1 parent bf6850c commit e568e51

3 files changed

Lines changed: 317 additions & 70 deletions

File tree

app/src/main/java/com/marknkamau/justjava/ui/main/MainActivity.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class MainActivity : BaseActivity() {
3030

3131
initializeLoadingIndicator()
3232
initializeRecyclerView()
33+
observeSwipeToRefresh()
3334

3435
viewModel.getProducts()
3536
}
@@ -38,6 +39,7 @@ class MainActivity : BaseActivity() {
3839
viewModel.loading.observe(this, Observer { loading ->
3940
TransitionManager.beginDelayedTransition(rootMainActivity)
4041
shimmerLayout.visibility = if (loading) View.VISIBLE else View.GONE
42+
if(loading) layoutFailed.visibility = View.GONE
4143
})
4244
}
4345

@@ -70,9 +72,19 @@ class MainActivity : BaseActivity() {
7072
rvProducts.visibility = View.VISIBLE
7173
adapter.setItems(resource.data)
7274
}
73-
is Resource.Failure -> toast(resource.response.message)
75+
is Resource.Failure -> {
76+
layoutFailed.visibility = View.VISIBLE
77+
toast(resource.response.message)
78+
}
7479
}
7580

7681
})
7782
}
83+
84+
private fun observeSwipeToRefresh(){
85+
swipeRefresh.setOnRefreshListener {
86+
swipeRefresh.isRefreshing = false
87+
viewModel.getProducts()
88+
}
89+
}
7890
}
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="983.06dp"
3+
android:height="697.94dp"
4+
android:viewportWidth="983.06"
5+
android:viewportHeight="697.94">
6+
<path
7+
android:pathData="M292.61,213m-213,0a213,213 0,1 1,426 0a213,213 0,1 1,-426 0"
8+
android:fillColor="#f2f2f2"/>
9+
<path
10+
android:pathData="M0,51.14c0,77.5 48.62,140.21 108.7,140.21"
11+
android:fillColor="#3e2723"/>
12+
<path
13+
android:pathData="M108.7,191.35C108.7,113 163,49.57 230,49.57"
14+
android:fillColor="#f57c00"/>
15+
<path
16+
android:pathData="M39.38,58.17c0,73.61 31,133.18 69.32,133.18"
17+
android:fillColor="#f57c00"/>
18+
<path
19+
android:pathData="M108.7,191.35c0,-100.14 62.71,-181.17 140.21,-181.17"
20+
android:fillColor="#3e2723"/>
21+
<path
22+
android:pathData="M85.83,192.34s15.42,-0.48 20.06,-3.78 23.72,-7.26 24.87,-2 23.17,26.39 5.76,26.53 -40.44,-2.71 -45.07,-5.53S85.83,192.34 85.83,192.34Z"
23+
android:fillColor="#a8a8a8"/>
24+
<path
25+
android:fillColor="#FF000000"
26+
android:pathData="M136.83,211.28c-17.4,0.15 -40.44,-2.71 -45.07,-5.53 -3.53,-2.15 -4.94,-9.87 -5.41,-13.43l-0.52,0s1,12.43 5.62,15.26 27.67,5.67 45.07,5.53c5,0 6.76,-1.83 6.67,-4.47C142.49,210.26 140.57,211.25 136.83,211.28Z"
27+
android:strokeAlpha="0.2"
28+
android:fillAlpha="0.2"/>
29+
<path
30+
android:pathData="M11.61,424.5a187,25.44 0,1 0,374 0a187,25.44 0,1 0,-374 0z"
31+
android:fillColor="#4f332e"/>
32+
<path
33+
android:fillColor="#FF000000"
34+
android:pathData="M41.61,424.5a157,21.36 0,1 0,314 0a157,21.36 0,1 0,-314 0z"
35+
android:strokeAlpha="0.1"
36+
android:fillAlpha="0.1"/>
37+
<path
38+
android:pathData="M140.61,645.5a170,23.13 0,1 0,340 0a170,23.13 0,1 0,-340 0z"
39+
android:fillColor="#4f332e"/>
40+
<path
41+
android:pathData="M462.61,626c90,23 263,-30 282,-90"
42+
android:strokeWidth="2"
43+
android:fillColor="#00000000"
44+
android:strokeColor="#3e2723"/>
45+
<path
46+
android:pathData="M309.61,259s130,-36 138,80 -107,149 -17,172"
47+
android:strokeWidth="2"
48+
android:fillColor="#00000000"
49+
android:strokeColor="#3e2723"/>
50+
<path
51+
android:pathData="M184,537.28s39.07,-10.82 41.48,24.05 -32.16,44.78 -5.11,51.69"
52+
android:strokeWidth="2"
53+
android:fillColor="#00000000"
54+
android:strokeColor="#3e2723"/>
55+
<path
56+
android:pathData="M835.06,223.29m-3.03,0a3.03,3.03 0,1 1,6.06 0a3.03,3.03 0,1 1,-6.06 0"
57+
android:fillColor="#f2f2f2"/>
58+
<path
59+
android:pathData="M108.61,159h208v242h-208z"
60+
android:fillColor="#3e2723"/>
61+
<path
62+
android:pathData="M87.61,135h250v86h-250z"
63+
android:fillColor="#4f332e"/>
64+
<path
65+
android:pathData="M87.61,237h250v86h-250z"
66+
android:fillColor="#4f332e"/>
67+
<path
68+
android:pathData="M87.61,339h250v86h-250z"
69+
android:fillColor="#4f332e"/>
70+
<path
71+
android:pathData="M271.61,150h16v16h-16z"
72+
android:strokeAlpha="0.4"
73+
android:fillColor="#f57c00"
74+
android:fillAlpha="0.4"/>
75+
<path
76+
android:pathData="M294.61,150h16v16h-16z"
77+
android:strokeAlpha="0.8"
78+
android:fillColor="#f57c00"
79+
android:fillAlpha="0.8"/>
80+
<path
81+
android:pathData="M317.61,150h16v16h-16z"
82+
android:fillColor="#f57c00"/>
83+
<path
84+
android:pathData="M271.61,251h16v16h-16z"
85+
android:strokeAlpha="0.4"
86+
android:fillColor="#f57c00"
87+
android:fillAlpha="0.4"/>
88+
<path
89+
android:pathData="M294.61,251h16v16h-16z"
90+
android:strokeAlpha="0.8"
91+
android:fillColor="#f57c00"
92+
android:fillAlpha="0.8"/>
93+
<path
94+
android:pathData="M317.61,251h16v16h-16z"
95+
android:fillColor="#f57c00"/>
96+
<path
97+
android:pathData="M271.61,352h16v16h-16z"
98+
android:strokeAlpha="0.4"
99+
android:fillColor="#f57c00"
100+
android:fillAlpha="0.4"/>
101+
<path
102+
android:pathData="M294.61,352h16v16h-16z"
103+
android:strokeAlpha="0.8"
104+
android:fillColor="#f57c00"
105+
android:fillAlpha="0.8"/>
106+
<path
107+
android:pathData="M317.61,352h16v16h-16z"
108+
android:fillColor="#f57c00"/>
109+
<path
110+
android:pathData="M316.61,538m-79,0a79,79 0,1 1,158 0a79,79 0,1 1,-158 0"
111+
android:fillColor="#3e2723"/>
112+
<path
113+
android:pathData="M280.61,600h24v43h-24z"
114+
android:fillColor="#3e2723"/>
115+
<path
116+
android:pathData="M328.61,600h24v43h-24z"
117+
android:fillColor="#3e2723"/>
118+
<path
119+
android:pathData="M280.61,643.5a20,7.5 0,1 0,40 0a20,7.5 0,1 0,-40 0z"
120+
android:fillColor="#3e2723"/>
121+
<path
122+
android:pathData="M328.61,642.5a20,7.5 0,1 0,40 0a20,7.5 0,1 0,-40 0z"
123+
android:fillColor="#3e2723"/>
124+
<path
125+
android:pathData="M318.61,518m-27,0a27,27 0,1 1,54 0a27,27 0,1 1,-54 0"
126+
android:fillColor="#fff"/>
127+
<path
128+
android:pathData="M318.61,518m-9,0a9,9 0,1 1,18 0a9,9 0,1 1,-18 0"
129+
android:fillColor="#4f332e"/>
130+
<path
131+
android:pathData="M240,464.53c-6.38,-28.57 14,-57.43 45.54,-64.47s62.27,10.41 68.64,39 -14.51,39.1 -46.05,46.14S246.36,493.1 240,464.53Z"
132+
android:fillColor="#f57c00"/>
133+
<path
134+
android:pathData="M349.502,526.393a12.4,39.5 66.83,1 0,72.628 -31.083a12.4,39.5 66.83,1 0,-72.628 31.083z"
135+
android:fillColor="#3e2723"/>
136+
<path
137+
android:pathData="M201.493,579.39a12.4,39.5 66.83,1 0,72.628 -31.083a12.4,39.5 66.83,1 0,-72.628 31.083z"
138+
android:fillColor="#3e2723"/>
139+
<path
140+
android:pathData="M362.61,561c0,7.73 -19.91,23 -42,23s-43,-14.27 -43,-22 20.91,-6 43,-6S362.61,553.27 362.61,561Z"
141+
android:fillColor="#fff"/>
142+
<path
143+
android:pathData="M983.06,186V136.92a113,113 0,0 1,-72.94 -54.3h0a21.47,21.47 0,0 1,-12.83 4.22h-39A161.06,161.06 0,0 0,983.06 186Z"
144+
android:fillColor="#4f332e"/>
145+
<path
146+
android:pathData="M983.06,134.1V86.93A26.26,26.26 0,0 0,956.8 60.65H918.92V65.2a21.58,21.58 0,0 1,-6.67 15.64A110.31,110.31 0,0 0,983.06 134.1Z"
147+
android:fillColor="#4f332e"/>
148+
<path
149+
android:pathData="M800.94,86.84H776.55A21.63,21.63 0,0 1,754.92 65.2V60.65H719.39a26.28,26.28 0,0 0,-26.28 26.27h0V671.68a26.23,26.23 0,0 0,26.21 26.26H956.79a24.9,24.9 0,0 0,3.23 -0.2,26.28 26.28,0 0,0 23,-26.06V241.21C896.72,231.21 824.78,169.6 800.94,86.84Z"
150+
android:fillColor="#4f332e"/>
151+
<path
152+
android:pathData="M855.33,86.84H803.79c23.72,81.23 94.43,141.66 179.27,151.62V188.83A163.9,163.9 0,0 1,855.33 86.84Z"
153+
android:fillColor="#4f332e"/>
154+
<path
155+
android:fillColor="#FF000000"
156+
android:pathData="M779.08,688.9c0.65,-0.65 16.17,-16.37 29.32,-53.66 12.07,-34.21 24.25,-93.87 13.73,-183.81 -19.94,-170.39 82.3,-279 83.33,-280.06l-3,-2.91c-0.27,0.28 -26.55,27.91 -49.94,76.42a375.48,375.48 0,0 0,-34.54 207c19.9,170.1 -41.22,233.4 -41.84,234Z"
157+
android:strokeAlpha="0.1"
158+
android:fillAlpha="0.1"/>
159+
<path
160+
android:fillColor="#FF000000"
161+
android:pathData="M936.86,141.25m-27.26,0a27.26,27.26 0,1 1,54.52 0a27.26,27.26 0,1 1,-54.52 0"
162+
android:strokeAlpha="0.1"
163+
android:fillAlpha="0.1"/>
164+
<path
165+
android:fillColor="#FF000000"
166+
android:pathData="M829.44,218.65m-27.26,0a27.26,27.26 0,1 1,54.52 0a27.26,27.26 0,1 1,-54.52 0"
167+
android:strokeAlpha="0.1"
168+
android:fillAlpha="0.1"/>
169+
<path
170+
android:fillColor="#FF000000"
171+
android:pathData="M870.601,297.798m-4.368,26.908a27.26,27.26 54.22,1 1,8.736 -53.816a27.26,27.26 54.22,1 1,-8.736 53.816"
172+
android:strokeAlpha="0.1"
173+
android:fillAlpha="0.1"/>
174+
<path
175+
android:fillColor="#FF000000"
176+
android:pathData="M787.87,335.87m-27.26,0a27.26,27.26 0,1 1,54.52 0a27.26,27.26 0,1 1,-54.52 0"
177+
android:strokeAlpha="0.1"
178+
android:fillAlpha="0.1"/>
179+
<path
180+
android:fillColor="#FF000000"
181+
android:pathData="M856.655,443.36m-4.368,26.908a27.26,27.26 54.22,1 1,8.736 -53.816a27.26,27.26 54.22,1 1,-8.736 53.816"
182+
android:strokeAlpha="0.1"
183+
android:fillAlpha="0.1"/>
184+
<path
185+
android:fillColor="#FF000000"
186+
android:pathData="M762.84,686s42.4,-58.73 -25.12,-127Z"
187+
android:strokeAlpha="0.1"
188+
android:fillAlpha="0.1"/>
189+
<path
190+
android:fillColor="#FF000000"
191+
android:pathData="M795.7,692.74s29,-66.39 122.13,-43Z"
192+
android:strokeAlpha="0.1"
193+
android:fillAlpha="0.1"/>
194+
<path
195+
android:pathData="M723.93,457.47h229.14v45.11h-229.14z"
196+
android:fillColor="#f57c00"/>
197+
<path
198+
android:pathData="M793.92,361.87a68.84,68.84 0,1 1,31.94 25.65,22.27 22.27,0 1,1 -31.94,-25.65Z"
199+
android:fillColor="#f2f2f2"/>
200+
<path
201+
android:pathData="M865.63,298.82c-1.63,-0.94 -7.85,6.65 -14.7,17.69 -6.86,-11 -13.07,-18.63 -14.7,-17.69 -1.83,1.05 2.65,12.26 10.1,25.47 -7.45,13.22 -11.93,24.42 -10.1,25.47 1.63,0.95 7.84,-6.64 14.7,-17.69 6.85,11.05 13.07,18.64 14.7,17.69 1.82,-1.05 -2.66,-12.25 -10.1,-25.47C863,311.08 867.45,299.87 865.63,298.82Z"
202+
android:fillColor="#f57c00"/>
203+
</vector>

0 commit comments

Comments
 (0)