@@ -59,8 +59,7 @@ public QuizChecker(SessionManager sessionManager,
59
59
}
60
60
61
61
public void initQuizCheck (Activity activity ) {
62
- setUploadCount (activity );
63
- setRevertCount (activity );
62
+ calculateRevertParameterAndShowQuiz (activity );
64
63
}
65
64
66
65
public void cleanup () {
@@ -70,12 +69,12 @@ public void cleanup() {
70
69
/**
71
70
* to fet the total number of images uploaded
72
71
*/
73
- private void setUploadCount (Activity activity ) {
72
+ private void setUploadCount () {
74
73
compositeDisposable .add (okHttpJsonApiClient
75
74
.getUploadCount (sessionManager .getUserName ())
76
75
.subscribeOn (Schedulers .io ())
77
76
.observeOn (AndroidSchedulers .mainThread ())
78
- .subscribe (uploadCount -> setTotalUploadCount ( activity , uploadCount ) ,
77
+ .subscribe (this :: setTotalUploadCount ,
79
78
t -> Timber .e (t , "Fetching upload count failed" )
80
79
));
81
80
}
@@ -85,28 +84,27 @@ private void setUploadCount(Activity activity) {
85
84
* call function to check for quiz
86
85
* @param uploadCount user's upload count
87
86
*/
88
- private void setTotalUploadCount (Activity activity , int uploadCount ) {
87
+ private void setTotalUploadCount (int uploadCount ) {
89
88
totalUploadCount = uploadCount - revertKvStore .getInt (UPLOAD_SHARED_PREFERENCE , 0 );
90
89
if ( totalUploadCount < 0 ){
91
90
totalUploadCount = 0 ;
92
91
revertKvStore .putInt (UPLOAD_SHARED_PREFERENCE , 0 );
93
92
}
94
93
isUploadCountFetched = true ;
95
- calculateRevertParameter (activity );
96
94
}
97
95
98
96
/**
99
97
* To call the API to get reverts count in form of JSONObject
100
98
*/
101
- private void setRevertCount (Activity activity ) {
99
+ private void setRevertCount () {
102
100
compositeDisposable .add (okHttpJsonApiClient
103
101
.getAchievements (sessionManager .getUserName ())
104
102
.subscribeOn (Schedulers .io ())
105
103
.observeOn (AndroidSchedulers .mainThread ())
106
104
.subscribe (
107
105
response -> {
108
106
if (response != null ) {
109
- setRevertParameter (activity , response .getDeletedUploads ());
107
+ setRevertParameter (response .getDeletedUploads ());
110
108
}
111
109
}, throwable -> Timber .e (throwable , "Fetching feedback failed" ))
112
110
);
@@ -116,20 +114,21 @@ private void setRevertCount(Activity activity) {
116
114
* to calculate the number of images reverted after previous quiz
117
115
* @param revertCountFetched count of deleted uploads
118
116
*/
119
- private void setRevertParameter (Activity activity , int revertCountFetched ) {
117
+ private void setRevertParameter (int revertCountFetched ) {
120
118
revertCount = revertCountFetched - revertKvStore .getInt (REVERT_SHARED_PREFERENCE , 0 );
121
119
if (revertCount < 0 ){
122
120
revertCount = 0 ;
123
121
revertKvStore .putInt (REVERT_SHARED_PREFERENCE , 0 );
124
122
}
125
123
isRevertCountFetched = true ;
126
- calculateRevertParameter (activity );
127
124
}
128
125
129
126
/**
130
127
* to check whether the criterion to call quiz is satisfied
131
128
*/
132
- private void calculateRevertParameter (Activity activity ) {
129
+ private void calculateRevertParameterAndShowQuiz (Activity activity ) {
130
+ setUploadCount ();
131
+ setRevertCount ();
133
132
if ( revertCount < 0 || totalUploadCount < 0 ){
134
133
revertKvStore .putInt (REVERT_SHARED_PREFERENCE , 0 );
135
134
revertKvStore .putInt (UPLOAD_SHARED_PREFERENCE , 0 );
0 commit comments