9
9
import android .graphics .drawable .Drawable ;
10
10
import android .net .Uri ;
11
11
import android .os .Bundle ;
12
+ import android .support .design .widget .Snackbar ;
12
13
import android .support .v4 .content .res .ResourcesCompat ;
13
14
import android .support .v7 .app .AlertDialog ;
14
15
import android .support .v7 .widget .Toolbar ;
23
24
import android .widget .ProgressBar ;
24
25
import android .widget .RelativeLayout ;
25
26
import android .widget .TextView ;
26
-
27
- import com .dinuscxj .progressbar .CircleProgressBar ;
28
-
29
- import java .io .File ;
30
- import java .io .FileOutputStream ;
31
- import java .io .IOException ;
32
- import java .util .Objects ;
33
-
34
- import javax .inject .Inject ;
35
-
36
27
import butterknife .BindView ;
37
28
import butterknife .ButterKnife ;
38
29
import butterknife .OnClick ;
30
+ import com .dinuscxj .progressbar .CircleProgressBar ;
39
31
import fr .free .nrw .commons .R ;
40
32
import fr .free .nrw .commons .Utils ;
41
33
import fr .free .nrw .commons .auth .SessionManager ;
45
37
import io .reactivex .android .schedulers .AndroidSchedulers ;
46
38
import io .reactivex .disposables .CompositeDisposable ;
47
39
import io .reactivex .schedulers .Schedulers ;
40
+ import java .io .File ;
41
+ import java .io .FileOutputStream ;
42
+ import java .io .IOException ;
43
+ import java .util .Objects ;
44
+ import javax .inject .Inject ;
48
45
import timber .log .Timber ;
49
46
50
47
/**
@@ -185,6 +182,7 @@ void shareScreen(Bitmap bitmap) {
185
182
* which then calls parseJson when results are fetched
186
183
*/
187
184
private void setAchievements () {
185
+ progressBar .setVisibility (View .VISIBLE );
188
186
if (checkAccount ()) {
189
187
compositeDisposable .add (mediaWikiApi
190
188
.getAchievements (Objects .requireNonNull (sessionManager .getCurrentAccount ()).name )
@@ -195,17 +193,32 @@ private void setAchievements() {
195
193
if (response != null ) {
196
194
setUploadCount (Achievements .from (response ));
197
195
} else {
198
- onError ();
196
+ showSnackBarWithRetry ();
199
197
}
200
198
},
201
199
t -> {
202
200
Timber .e (t , "Fetching achievements statistics failed" );
203
- onError ();
201
+ showSnackBarWithRetry ();
204
202
}
205
203
));
206
204
}
207
205
}
208
206
207
+ /**
208
+ * As there would be no other way to refresh data when api call fails, lets give him an option
209
+ * to retry using the snackbar
210
+ */
211
+ private void showSnackBarWithRetry () {
212
+ progressBar .setVisibility (View .GONE );
213
+ Snackbar snackbar = Snackbar .make (findViewById (android .R .id .content ),
214
+ getString (R .string .achievements_fetch_failed ), Snackbar .LENGTH_INDEFINITE );
215
+ snackbar .setAction (getString (R .string .retry ), view -> {
216
+ snackbar .dismiss ();
217
+ setAchievements ();
218
+ });
219
+ snackbar .show ();
220
+ }
221
+
209
222
/**
210
223
* Shows a generic error toast when error occurs while loading achievements or uploads
211
224
*/
0 commit comments