Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't show the quiz pop-up twice #3398

Merged
merged 2 commits into from
Feb 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions app/src/main/java/fr/free/nrw/commons/quiz/QuizChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public QuizChecker(SessionManager sessionManager,
}

public void initQuizCheck(Activity activity) {
setUploadCount(activity);
setRevertCount(activity);
calculateRevertParameterAndShowQuiz(activity);
}

public void cleanup() {
Expand All @@ -70,12 +69,12 @@ public void cleanup() {
/**
* to fet the total number of images uploaded
*/
private void setUploadCount(Activity activity) {
private void setUploadCount() {
compositeDisposable.add(okHttpJsonApiClient
.getUploadCount(sessionManager.getUserName())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(uploadCount -> setTotalUploadCount(activity, uploadCount),
.subscribe(this::setTotalUploadCount,
t -> Timber.e(t, "Fetching upload count failed")
));
}
Expand All @@ -85,28 +84,27 @@ private void setUploadCount(Activity activity) {
* call function to check for quiz
* @param uploadCount user's upload count
*/
private void setTotalUploadCount(Activity activity, int uploadCount) {
private void setTotalUploadCount(int uploadCount) {
totalUploadCount = uploadCount - revertKvStore.getInt(UPLOAD_SHARED_PREFERENCE, 0);
if ( totalUploadCount < 0){
totalUploadCount = 0;
revertKvStore.putInt(UPLOAD_SHARED_PREFERENCE, 0);
}
isUploadCountFetched = true;
calculateRevertParameter(activity);
}

/**
* To call the API to get reverts count in form of JSONObject
*/
private void setRevertCount(Activity activity) {
private void setRevertCount() {
compositeDisposable.add(okHttpJsonApiClient
.getAchievements(sessionManager.getUserName())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
response -> {
if (response != null) {
setRevertParameter(activity, response.getDeletedUploads());
setRevertParameter(response.getDeletedUploads());
}
}, throwable -> Timber.e(throwable, "Fetching feedback failed"))
);
Expand All @@ -116,20 +114,21 @@ private void setRevertCount(Activity activity) {
* to calculate the number of images reverted after previous quiz
* @param revertCountFetched count of deleted uploads
*/
private void setRevertParameter(Activity activity, int revertCountFetched) {
private void setRevertParameter(int revertCountFetched) {
revertCount = revertCountFetched - revertKvStore.getInt(REVERT_SHARED_PREFERENCE, 0);
if (revertCount < 0){
revertCount = 0;
revertKvStore.putInt(REVERT_SHARED_PREFERENCE, 0);
}
isRevertCountFetched = true;
calculateRevertParameter(activity);
}

/**
* to check whether the criterion to call quiz is satisfied
*/
private void calculateRevertParameter(Activity activity) {
private void calculateRevertParameterAndShowQuiz(Activity activity) {
setUploadCount();
setRevertCount();
if ( revertCount < 0 || totalUploadCount < 0){
revertKvStore.putInt(REVERT_SHARED_PREFERENCE, 0);
revertKvStore.putInt(UPLOAD_SHARED_PREFERENCE, 0);
Expand Down