Fixes #3295: Ultimate achievement: Too many contributions (#3378)

This commit is contained in:
Kshitij Bhardwaj 2020-03-08 13:09:38 -04:00 committed by GitHub
parent 16f1ba8640
commit 7450b44ab7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 9 deletions

View file

@ -110,6 +110,9 @@ public class AchievementsActivity extends NavigationBaseActivity {
private CompositeDisposable compositeDisposable = new CompositeDisposable(); private CompositeDisposable compositeDisposable = new CompositeDisposable();
// To keep track of the number of wiki edits made by a user
private int numberOfEdits = 0;
/** /**
* This method helps in the creation Achievement screen and * This method helps in the creation Achievement screen and
* dynamically set the size of imageView * dynamically set the size of imageView
@ -140,8 +143,8 @@ public class AchievementsActivity extends NavigationBaseActivity {
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
hideLayouts(); hideLayouts();
setAchievements();
setWikidataEditCount(); setWikidataEditCount();
setAchievements();
initDrawer(); initDrawer();
} }
@ -230,12 +233,24 @@ public class AchievementsActivity extends NavigationBaseActivity {
Timber.d("success"); Timber.d("success");
layoutImageReverts.setVisibility(View.INVISIBLE); layoutImageReverts.setVisibility(View.INVISIBLE);
imageView.setVisibility(View.INVISIBLE); imageView.setVisibility(View.INVISIBLE);
showSnackBarWithRetry(); // If the number of edits made by the user are more than 150,000
// in some cases such high number of wiki edit counts cause the
// achievements calculator to fail in some cases, for more details
// refer Issue: #3295
if (numberOfEdits <= 150000) {
showSnackBarWithRetry(false);
} else {
showSnackBarWithRetry(true);
}
} }
}, },
t -> { t -> {
Timber.e(t, "Fetching achievements statistics failed"); Timber.e(t, "Fetching achievements statistics failed");
showSnackBarWithRetry(); if (numberOfEdits <= 150000) {
showSnackBarWithRetry(false);
} else {
showSnackBarWithRetry(true);
}
} }
)); ));
} }
@ -259,7 +274,10 @@ public class AchievementsActivity extends NavigationBaseActivity {
.getWikidataEdits(userName) .getWikidataEdits(userName)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(edits -> wikidataEditsText.setText(String.valueOf(edits)), e -> { .subscribe(edits -> {
numberOfEdits = edits;
wikidataEditsText.setText(String.valueOf(edits));
}, e -> {
Timber.e("Error:" + e); Timber.e("Error:" + e);
})); }));
} }
@ -267,11 +285,20 @@ public class AchievementsActivity extends NavigationBaseActivity {
/** /**
* Shows a snack bar which has an action button which on click dismisses the snackbar and invokes the * Shows a snack bar which has an action button which on click dismisses the snackbar and invokes the
* listener passed * listener passed
* @param tooManyAchievements if this value is true it means that the number of achievements of the
* user are so high that it wrecks havoc with the Achievements calculator due to which request may time
* out. Well this is the Ultimate Achievement
*/ */
private void showSnackBarWithRetry() { private void showSnackBarWithRetry(boolean tooManyAchievements) {
progressBar.setVisibility(View.GONE); if (tooManyAchievements) {
ViewUtil.showDismissibleSnackBar(findViewById(android.R.id.content), progressBar.setVisibility(View.GONE);
R.string.achievements_fetch_failed, R.string.retry, view -> setAchievements()); ViewUtil.showDismissibleSnackBar(findViewById(android.R.id.content),
R.string.achievements_fetch_failed_ultimate_achievement, R.string.retry, view -> setAchievements());
} else {
progressBar.setVisibility(View.GONE);
ViewUtil.showDismissibleSnackBar(findViewById(android.R.id.content),
R.string.achievements_fetch_failed, R.string.retry, view -> setAchievements());
}
} }
/** /**

View file

@ -458,6 +458,7 @@ Upload your first media by tapping on the add button.</string>
<string name="display_location_permission_title">Display location permission</string> <string name="display_location_permission_title">Display location permission</string>
<string name="display_location_permission_explanation">Ask for location permission when needed for nearby notification card view feature.</string> <string name="display_location_permission_explanation">Ask for location permission when needed for nearby notification card view feature.</string>
<string name="achievements_fetch_failed">Something went wrong, We could not fetch your achievements</string> <string name="achievements_fetch_failed">Something went wrong, We could not fetch your achievements</string>
<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>
<string name="ends_on">Ends on:</string> <string name="ends_on">Ends on:</string>
<string name="display_campaigns">Display campaigns</string> <string name="display_campaigns">Display campaigns</string>
<string name="display_campaigns_explanation">See the ongoing campaigns</string> <string name="display_campaigns_explanation">See the ongoing campaigns</string>