Skip to content

Commit

Permalink
Fixes #3295: Ultimate achievement: Too many contributions (#3378)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbhardwaj123 authored Mar 8, 2020
1 parent 16f1ba8 commit 7450b44
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public class AchievementsActivity extends NavigationBaseActivity {

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
* dynamically set the size of imageView
Expand Down Expand Up @@ -140,8 +143,8 @@ protected void onCreate(Bundle savedInstanceState) {
progressBar.setVisibility(View.VISIBLE);

hideLayouts();
setAchievements();
setWikidataEditCount();
setAchievements();
initDrawer();
}

Expand Down Expand Up @@ -230,12 +233,24 @@ private void setAchievements() {
Timber.d("success");
layoutImageReverts.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 -> {
Timber.e(t, "Fetching achievements statistics failed");
showSnackBarWithRetry();
if (numberOfEdits <= 150000) {
showSnackBarWithRetry(false);
} else {
showSnackBarWithRetry(true);
}
}
));
}
Expand All @@ -259,19 +274,31 @@ private void setWikidataEditCount() {
.getWikidataEdits(userName)
.subscribeOn(Schedulers.io())
.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);
}));
}

/**
* Shows a snack bar which has an action button which on click dismisses the snackbar and invokes the
* 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() {
progressBar.setVisibility(View.GONE);
ViewUtil.showDismissibleSnackBar(findViewById(android.R.id.content),
R.string.achievements_fetch_failed, R.string.retry, view -> setAchievements());
private void showSnackBarWithRetry(boolean tooManyAchievements) {
if (tooManyAchievements) {
progressBar.setVisibility(View.GONE);
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());
}
}

/**
Expand Down Expand Up @@ -504,4 +531,4 @@ private boolean checkAccount(){
return true;
}

}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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_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_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="display_campaigns">Display campaigns</string>
<string name="display_campaigns_explanation">See the ongoing campaigns</string>
Expand Down

0 comments on commit 7450b44

Please # to comment.