diff --git a/app/src/main/java/fr/free/nrw/commons/quiz/QuizChecker.java b/app/src/main/java/fr/free/nrw/commons/quiz/QuizChecker.java index 6669697597..e9ebda4b5c 100644 --- a/app/src/main/java/fr/free/nrw/commons/quiz/QuizChecker.java +++ b/app/src/main/java/fr/free/nrw/commons/quiz/QuizChecker.java @@ -59,8 +59,7 @@ public QuizChecker(SessionManager sessionManager, } public void initQuizCheck(Activity activity) { - setUploadCount(activity); - setRevertCount(activity); + calculateRevertParameterAndShowQuiz(activity); } public void cleanup() { @@ -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") )); } @@ -85,20 +84,19 @@ 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()) @@ -106,7 +104,7 @@ private void setRevertCount(Activity activity) { .subscribe( response -> { if (response != null) { - setRevertParameter(activity, response.getDeletedUploads()); + setRevertParameter(response.getDeletedUploads()); } }, throwable -> Timber.e(throwable, "Fetching feedback failed")) ); @@ -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);