Skip to content

Commit ccfe44a

Browse files
committed
fixing travis ci failed
1 parent 16f1ba8 commit ccfe44a

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

app/src/main/java/fr/free/nrw/commons/achievements/AchievementsActivity.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ public class AchievementsActivity extends NavigationBaseActivity {
110110

111111
private CompositeDisposable compositeDisposable = new CompositeDisposable();
112112

113+
// To keep track of the number of wiki edits made by a user
114+
private int numberOfEdits = 0;
115+
113116
/**
114117
* This method helps in the creation Achievement screen and
115118
* dynamically set the size of imageView
@@ -140,8 +143,8 @@ protected void onCreate(Bundle savedInstanceState) {
140143
progressBar.setVisibility(View.VISIBLE);
141144

142145
hideLayouts();
143-
setAchievements();
144146
setWikidataEditCount();
147+
setAchievements();
145148
initDrawer();
146149
}
147150

@@ -230,12 +233,24 @@ private void setAchievements() {
230233
Timber.d("success");
231234
layoutImageReverts.setVisibility(View.INVISIBLE);
232235
imageView.setVisibility(View.INVISIBLE);
233-
showSnackBarWithRetry();
236+
// If the number of edits made by the user are more than 150,000
237+
// in some cases such high number of wiki edit counts cause the
238+
// achievements calculator to fail in some cases, for more details
239+
// refer Issue: #3295
240+
if (numberOfEdits <= 150000) {
241+
showSnackBarWithRetry();
242+
} else {
243+
showSnackBarUltimateAchievementWithRetry();
244+
}
234245
}
235246
},
236247
t -> {
237248
Timber.e(t, "Fetching achievements statistics failed");
238-
showSnackBarWithRetry();
249+
if (numberOfEdits <= 150000) {
250+
showSnackBarWithRetry();
251+
} else {
252+
showSnackBarUltimateAchievementWithRetry();
253+
}
239254
}
240255
));
241256
}
@@ -259,7 +274,10 @@ private void setWikidataEditCount() {
259274
.getWikidataEdits(userName)
260275
.subscribeOn(Schedulers.io())
261276
.observeOn(AndroidSchedulers.mainThread())
262-
.subscribe(edits -> wikidataEditsText.setText(String.valueOf(edits)), e -> {
277+
.subscribe(edits -> {
278+
numberOfEdits += edits;
279+
wikidataEditsText.setText(String.valueOf(edits));
280+
}, e -> {
263281
Timber.e("Error:" + e);
264282
}));
265283
}
@@ -274,6 +292,17 @@ private void showSnackBarWithRetry() {
274292
R.string.achievements_fetch_failed, R.string.retry, view -> setAchievements());
275293
}
276294

295+
/**
296+
* Shows a snack bar which tells the users that their wiki edit count is so high that it (in some cases)
297+
* wreks havoc with the Achievements calculator due to which request may time out
298+
* Well this is the Ultimate Achievement
299+
*/
300+
private void showSnackBarUltimateAchievementWithRetry() {
301+
progressBar.setVisibility(View.GONE);
302+
ViewUtil.showDismissibleSnackBar(findViewById(android.R.id.content),
303+
R.string.achievements_fetch_failed_ultimate_achievement, R.string.retry, view -> setAchievements());
304+
}
305+
277306
/**
278307
* Shows a generic error toast when error occurs while loading achievements or uploads
279308
*/

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ Upload your first media by tapping on the add button.</string>
458458
<string name="display_location_permission_title">Display location permission</string>
459459
<string name="display_location_permission_explanation">Ask for location permission when needed for nearby notification card view feature.</string>
460460
<string name="achievements_fetch_failed">Something went wrong, We could not fetch your achievements</string>
461+
<string name="achievements_fetch_failed_ultimate_achievement">You\'ve made so many contributions our achievements calculation system can\'t cope. This is the ultimate achievement.</string>
461462
<string name="ends_on">Ends on:</string>
462463
<string name="display_campaigns">Display campaigns</string>
463464
<string name="display_campaigns_explanation">See the ongoing campaigns</string>

0 commit comments

Comments
 (0)