@@ -54,10 +54,7 @@ public class AchievementsActivity extends NavigationBaseActivity {
54
54
55
55
private static final double BADGE_IMAGE_WIDTH_RATIO = 0.4 ;
56
56
private static final double BADGE_IMAGE_HEIGHT_RATIO = 0.3 ;
57
- private Boolean isUploadFetched = false ;
58
- private Boolean isStatisticsFetched = false ;
59
- private Boolean isRevertFetched = false ;
60
- private Achievements achievements = new Achievements ();
57
+
61
58
private LevelController .LevelInfo levelInfo ;
62
59
63
60
@ BindView (R .id .achievement_badge )
@@ -129,7 +126,6 @@ protected void onCreate(Bundle savedInstanceState) {
129
126
progressBar .setVisibility (View .VISIBLE );
130
127
hideLayouts ();
131
128
setAchievements ();
132
- setUploadCount ();
133
129
initDrawer ();
134
130
}
135
131
@@ -189,7 +185,6 @@ void shareScreen(Bitmap bitmap) {
189
185
* which then calls parseJson when results are fetched
190
186
*/
191
187
private void setAchievements () {
192
-
193
188
if (checkAccount ()) {
194
189
compositeDisposable .add (mediaWikiApi
195
190
.getAchievements (Objects .requireNonNull (sessionManager .getCurrentAccount ()).name )
@@ -198,29 +193,42 @@ private void setAchievements() {
198
193
.subscribe (
199
194
response -> {
200
195
if (response != null ) {
201
- achievements = Achievements .from (response );
202
- isRevertFetched = true ;
203
- isStatisticsFetched = true ;
196
+ setUploadCount ( Achievements .from (response ) );
197
+ } else {
198
+ onError () ;
204
199
}
205
- hideProgressBar ();
206
200
},
207
- t -> Timber .e (t , "Fetching achievements statisticss failed" )
201
+ t -> {
202
+ Timber .e (t , "Fetching achievements statistics failed" );
203
+ onError ();
204
+ }
208
205
));
209
206
}
210
207
}
211
208
209
+ /**
210
+ * Shows a generic error toast when error occurs while loading achievements or uploads
211
+ */
212
+ private void onError () {
213
+ ViewUtil .showLongToast (this , getResources ().getString (R .string .error_occurred ));
214
+ progressBar .setVisibility (View .GONE );
215
+ }
216
+
212
217
/**
213
218
* used to the count of images uploaded by user
214
219
*/
215
- private void setUploadCount () {
220
+ private void setUploadCount (Achievements achievements ) {
216
221
if (checkAccount ()) {
217
222
compositeDisposable .add (mediaWikiApi
218
223
.getUploadCount (Objects .requireNonNull (sessionManager .getCurrentAccount ()).name )
219
224
.subscribeOn (Schedulers .io ())
220
225
.observeOn (AndroidSchedulers .mainThread ())
221
226
.subscribe (
222
- this ::setAchievementsUploadCount ,
223
- t -> Timber .e (t , "Fetching upload count failed" )
227
+ uploadCount -> setAchievementsUploadCount (achievements , uploadCount ),
228
+ t -> {
229
+ Timber .e (t , "Fetching upload count failed" );
230
+ onError ();
231
+ }
224
232
));
225
233
}
226
234
}
@@ -229,10 +237,9 @@ private void setUploadCount() {
229
237
* used to set achievements upload count and call hideProgressbar
230
238
* @param uploadCount
231
239
*/
232
- private void setAchievementsUploadCount (int uploadCount ){
240
+ private void setAchievementsUploadCount (Achievements achievements , int uploadCount ) {
233
241
achievements .setImagesUploaded (uploadCount );
234
- isUploadFetched = true ;
235
- hideProgressBar ();
242
+ hideProgressBar (achievements );
236
243
}
237
244
238
245
/**
@@ -293,8 +300,8 @@ public static void startYourself(Context context) {
293
300
/**
294
301
* to hide progressbar
295
302
*/
296
- private void hideProgressBar () {
297
- if (progressBar != null && isUploadFetched && isStatisticsFetched && isRevertFetched ) {
303
+ private void hideProgressBar (Achievements achievements ) {
304
+ if (progressBar != null ) {
298
305
levelInfo = LevelController .LevelInfo .from (achievements .getImagesUploaded (),
299
306
achievements .getUniqueUsedImages (),
300
307
achievements .getNotRevertPercentage ());
0 commit comments