From 76e95221b28ad8b8e604d1b1b06929cdaac83d49 Mon Sep 17 00:00:00 2001 From: Kaartic Sivaraam Date: Sun, 9 Feb 2020 01:19:19 +0530 Subject: [PATCH 1/2] 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 --- .../main/java/fr/free/nrw/commons/quiz/QuizChecker.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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..0eeb8a2a26 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() { @@ -92,7 +91,6 @@ private void setTotalUploadCount(Activity activity, int uploadCount) { revertKvStore.putInt(UPLOAD_SHARED_PREFERENCE, 0); } isUploadCountFetched = true; - calculateRevertParameter(activity); } /** @@ -123,13 +121,14 @@ private void setRevertParameter(Activity activity, int revertCountFetched) { 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(activity); + setRevertCount(activity); if ( revertCount < 0 || totalUploadCount < 0){ revertKvStore.putInt(REVERT_SHARED_PREFERENCE, 0); revertKvStore.putInt(UPLOAD_SHARED_PREFERENCE, 0); From c75622ebce5a1215a4397f02c3ee490df2d7a8d7 Mon Sep 17 00:00:00 2001 From: Kaartic Sivaraam Date: Sun, 9 Feb 2020 01:26:15 +0530 Subject: [PATCH 2/2] 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. --- .../fr/free/nrw/commons/quiz/QuizChecker.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 0eeb8a2a26..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 @@ -69,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") )); } @@ -84,7 +84,7 @@ 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; @@ -96,7 +96,7 @@ private void setTotalUploadCount(Activity activity, int uploadCount) { /** * 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()) @@ -104,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")) ); @@ -114,7 +114,7 @@ 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; @@ -127,8 +127,8 @@ private void setRevertParameter(Activity activity, int revertCountFetched) { * to check whether the criterion to call quiz is satisfied */ private void calculateRevertParameterAndShowQuiz(Activity activity) { - setUploadCount(activity); - setRevertCount(activity); + setUploadCount(); + setRevertCount(); if ( revertCount < 0 || totalUploadCount < 0){ revertKvStore.putInt(REVERT_SHARED_PREFERENCE, 0); revertKvStore.putInt(UPLOAD_SHARED_PREFERENCE, 0);