Skip to content

Commit 6683ea4

Browse files
Don't show the quiz pop-up twice (#3398)
* Avoid showing the quiz pop-up twice to the user Due to the current flow of code it's possible that in some cases the quiz pop-up is shown to the user twice. This is unnecessary and unintentional. So, change the logic in such a way that the quiz pop-up would be never be shown twice to the user. Fixes: #3281 * Quiz: remove unused parameters from methods Some methods don't seem to be using the parameters that they receive. So, just remove the unused parameters.
1 parent b65e4a1 commit 6683ea4

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

app/src/main/java/fr/free/nrw/commons/quiz/QuizChecker.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public QuizChecker(SessionManager sessionManager,
5959
}
6060

6161
public void initQuizCheck(Activity activity) {
62-
setUploadCount(activity);
63-
setRevertCount(activity);
62+
calculateRevertParameterAndShowQuiz(activity);
6463
}
6564

6665
public void cleanup() {
@@ -70,12 +69,12 @@ public void cleanup() {
7069
/**
7170
* to fet the total number of images uploaded
7271
*/
73-
private void setUploadCount(Activity activity) {
72+
private void setUploadCount() {
7473
compositeDisposable.add(okHttpJsonApiClient
7574
.getUploadCount(sessionManager.getUserName())
7675
.subscribeOn(Schedulers.io())
7776
.observeOn(AndroidSchedulers.mainThread())
78-
.subscribe(uploadCount -> setTotalUploadCount(activity, uploadCount),
77+
.subscribe(this::setTotalUploadCount,
7978
t -> Timber.e(t, "Fetching upload count failed")
8079
));
8180
}
@@ -85,28 +84,27 @@ private void setUploadCount(Activity activity) {
8584
* call function to check for quiz
8685
* @param uploadCount user's upload count
8786
*/
88-
private void setTotalUploadCount(Activity activity, int uploadCount) {
87+
private void setTotalUploadCount(int uploadCount) {
8988
totalUploadCount = uploadCount - revertKvStore.getInt(UPLOAD_SHARED_PREFERENCE, 0);
9089
if ( totalUploadCount < 0){
9190
totalUploadCount = 0;
9291
revertKvStore.putInt(UPLOAD_SHARED_PREFERENCE, 0);
9392
}
9493
isUploadCountFetched = true;
95-
calculateRevertParameter(activity);
9694
}
9795

9896
/**
9997
* To call the API to get reverts count in form of JSONObject
10098
*/
101-
private void setRevertCount(Activity activity) {
99+
private void setRevertCount() {
102100
compositeDisposable.add(okHttpJsonApiClient
103101
.getAchievements(sessionManager.getUserName())
104102
.subscribeOn(Schedulers.io())
105103
.observeOn(AndroidSchedulers.mainThread())
106104
.subscribe(
107105
response -> {
108106
if (response != null) {
109-
setRevertParameter(activity, response.getDeletedUploads());
107+
setRevertParameter(response.getDeletedUploads());
110108
}
111109
}, throwable -> Timber.e(throwable, "Fetching feedback failed"))
112110
);
@@ -116,20 +114,21 @@ private void setRevertCount(Activity activity) {
116114
* to calculate the number of images reverted after previous quiz
117115
* @param revertCountFetched count of deleted uploads
118116
*/
119-
private void setRevertParameter(Activity activity, int revertCountFetched) {
117+
private void setRevertParameter(int revertCountFetched) {
120118
revertCount = revertCountFetched - revertKvStore.getInt(REVERT_SHARED_PREFERENCE, 0);
121119
if (revertCount < 0){
122120
revertCount = 0;
123121
revertKvStore.putInt(REVERT_SHARED_PREFERENCE, 0);
124122
}
125123
isRevertCountFetched = true;
126-
calculateRevertParameter(activity);
127124
}
128125

129126
/**
130127
* to check whether the criterion to call quiz is satisfied
131128
*/
132-
private void calculateRevertParameter(Activity activity) {
129+
private void calculateRevertParameterAndShowQuiz(Activity activity) {
130+
setUploadCount();
131+
setRevertCount();
133132
if ( revertCount < 0 || totalUploadCount < 0){
134133
revertKvStore.putInt(REVERT_SHARED_PREFERENCE, 0);
135134
revertKvStore.putInt(UPLOAD_SHARED_PREFERENCE, 0);

0 commit comments

Comments
 (0)