|
2 | 2 |
|
3 | 3 | import android.accounts.Account;
|
4 | 4 | import android.annotation.SuppressLint;
|
5 |
| -import android.annotation.TargetApi; |
6 | 5 | import android.content.Context;
|
7 |
| -import android.content.DialogInterface; |
8 | 6 | import android.content.Intent;
|
9 | 7 | import android.graphics.Bitmap;
|
10 |
| -import android.graphics.BitmapFactory; |
11 |
| -import android.graphics.Canvas; |
12 |
| -import android.graphics.Color; |
13 |
| -import android.graphics.Paint; |
14 |
| -import android.graphics.Rect; |
15 | 8 | import android.graphics.drawable.BitmapDrawable;
|
16 | 9 | import android.graphics.drawable.Drawable;
|
17 | 10 | import android.net.Uri;
|
|
20 | 13 | import android.support.v7.app.AlertDialog;
|
21 | 14 | import android.support.v7.widget.Toolbar;
|
22 | 15 | import android.util.DisplayMetrics;
|
23 |
| -import android.util.Log; |
24 | 16 | import android.view.ContextThemeWrapper;
|
25 | 17 | import android.view.LayoutInflater;
|
26 | 18 | import android.view.Menu;
|
|
34 | 26 |
|
35 | 27 | import com.dinuscxj.progressbar.CircleProgressBar;
|
36 | 28 |
|
37 |
| -import org.json.JSONException; |
38 |
| -import org.json.JSONObject; |
39 |
| - |
40 | 29 | import java.io.File;
|
41 | 30 | import java.io.FileOutputStream;
|
42 | 31 | import java.io.IOException;
|
43 |
| -import java.util.Optional; |
| 32 | +import java.util.Objects; |
44 | 33 |
|
45 | 34 | import javax.inject.Inject;
|
46 | 35 |
|
@@ -141,7 +130,6 @@ protected void onCreate(Bundle savedInstanceState) {
|
141 | 130 | hideLayouts();
|
142 | 131 | setAchievements();
|
143 | 132 | setUploadCount();
|
144 |
| - setRevertCount(); |
145 | 133 | initDrawer();
|
146 | 134 | }
|
147 | 135 |
|
@@ -201,61 +189,37 @@ void shareScreen(Bitmap bitmap) {
|
201 | 189 | * which then calls parseJson when results are fetched
|
202 | 190 | */
|
203 | 191 | private void setAchievements() {
|
204 |
| - if(checkAccount()) { |
205 |
| - compositeDisposable.add(mediaWikiApi |
206 |
| - .getAchievements(sessionManager.getCurrentAccount().name) |
207 |
| - .subscribeOn(Schedulers.io()) |
208 |
| - .observeOn(AndroidSchedulers.mainThread()) |
209 |
| - .subscribe( |
210 |
| - jsonObject -> parseJson(jsonObject), |
211 |
| - t -> Timber.e(t, "Fetching achievements statisticss failed") |
212 |
| - )); |
213 |
| - } |
214 |
| - } |
215 | 192 |
|
216 |
| - /** |
217 |
| - * To call the API to get reverts count in form of JSONObject |
218 |
| - * |
219 |
| - */ |
220 |
| - |
221 |
| - private void setRevertCount(){ |
222 | 193 | if(checkAccount()) {
|
223 | 194 | compositeDisposable.add(mediaWikiApi
|
224 |
| - .getRevertRespObjectSingle(sessionManager.getCurrentAccount().name) |
| 195 | + .getAchievements(Objects.requireNonNull(sessionManager.getCurrentAccount()).name) |
225 | 196 | .subscribeOn(Schedulers.io())
|
226 | 197 | .observeOn(AndroidSchedulers.mainThread())
|
227 | 198 | .subscribe(
|
228 |
| - object -> parseJsonRevertCount(object), |
229 |
| - t -> Timber.e(t, "Fetching revert count failed") |
| 199 | + response -> { |
| 200 | + if (response != null) { |
| 201 | + achievements = Achievements.from(response); |
| 202 | + isRevertFetched = true; |
| 203 | + isStatisticsFetched = true; |
| 204 | + } |
| 205 | + hideProgressBar(); |
| 206 | + }, |
| 207 | + t -> Timber.e(t, "Fetching achievements statisticss failed") |
230 | 208 | ));
|
231 | 209 | }
|
232 | 210 | }
|
233 | 211 |
|
234 |
| - /** |
235 |
| - * used to set number of deleted images |
236 |
| - * @param object |
237 |
| - */ |
238 |
| - private void parseJsonRevertCount(JSONObject object){ |
239 |
| - try { |
240 |
| - achievements.setRevertCount(object.getInt("deletedUploads")); |
241 |
| - } catch (JSONException e) { |
242 |
| - Timber.d( e, e.getMessage()); |
243 |
| - } |
244 |
| - isRevertFetched = true; |
245 |
| - hideProgressBar(); |
246 |
| - } |
247 |
| - |
248 | 212 | /**
|
249 | 213 | * used to the count of images uploaded by user
|
250 | 214 | */
|
251 | 215 | private void setUploadCount() {
|
252 | 216 | if(checkAccount()) {
|
253 | 217 | compositeDisposable.add(mediaWikiApi
|
254 |
| - .getUploadCount(sessionManager.getCurrentAccount().name) |
| 218 | + .getUploadCount(Objects.requireNonNull(sessionManager.getCurrentAccount()).name) |
255 | 219 | .subscribeOn(Schedulers.io())
|
256 | 220 | .observeOn(AndroidSchedulers.mainThread())
|
257 | 221 | .subscribe(
|
258 |
| - uploadCount -> setAchievementsUploadCount(uploadCount), |
| 222 | + this::setAchievementsUploadCount, |
259 | 223 | t -> Timber.e(t, "Fetching upload count failed")
|
260 | 224 | ));
|
261 | 225 | }
|
@@ -293,33 +257,12 @@ private void setImageRevertPercentage(int notRevertPercentage){
|
293 | 257 | imagesRevertLimitText.setText(getResources().getString(R.string.achievements_revert_limit_message)+ levelInfo.getMinNonRevertPercentage() + "%");
|
294 | 258 | }
|
295 | 259 |
|
296 |
| - /** |
297 |
| - * used to parse the JSONObject containing results |
298 |
| - * @param object |
299 |
| - */ |
300 |
| - private void parseJson(JSONObject object) { |
301 |
| - try { |
302 |
| - achievements.setUniqueUsedImages(object.getInt("uniqueUsedImages")); |
303 |
| - achievements.setArticlesUsingImages(object.getInt("articlesUsingImages")); |
304 |
| - achievements.setThanksReceived(object.getInt("thanksReceived")); |
305 |
| - achievements.setImagesEditedBySomeoneElse(object.getInt("imagesEditedBySomeoneElse")); |
306 |
| - JSONObject featuredImages = object.getJSONObject("featuredImages"); |
307 |
| - achievements.setFeaturedImages |
308 |
| - (featuredImages.getInt("Quality_images") + |
309 |
| - featuredImages.getInt("Featured_pictures_on_Wikimedia_Commons")); |
310 |
| - } catch (JSONException e) { |
311 |
| - e.printStackTrace(); |
312 |
| - } |
313 |
| - isStatisticsFetched = true; |
314 |
| - hideProgressBar(); |
315 |
| - } |
316 |
| - |
317 | 260 | /**
|
318 | 261 | * Used the inflate the fetched statistics of the images uploaded by user
|
319 | 262 | * and assign badge and level
|
320 | 263 | * @param achievements
|
321 | 264 | */
|
322 |
| - private void inflateAchievements(Achievements achievements ){ |
| 265 | + private void inflateAchievements(Achievements achievements) { |
323 | 266 | thanksReceived.setText(Integer.toString(achievements.getThanksReceived()));
|
324 | 267 | imagesUsedByWikiProgessbar.setProgress
|
325 | 268 | (100*achievements.getUniqueUsedImages()/levelInfo.getMaxUniqueImages() );
|
@@ -393,17 +336,8 @@ public void showAlert(Bitmap screenshot){
|
393 | 336 | TextView shareMessage = (TextView) view.findViewById(R.id.alert_text);
|
394 | 337 | shareMessage.setText(R.string.achievements_share_message);
|
395 | 338 | alertadd.setView(view);
|
396 |
| - alertadd.setPositiveButton("Proceed", new DialogInterface.OnClickListener() { |
397 |
| - public void onClick(DialogInterface dialog, int which) { |
398 |
| - shareScreen(screenshot); |
399 |
| - } |
400 |
| - }); |
401 |
| - alertadd.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
402 |
| - @Override |
403 |
| - public void onClick(DialogInterface dialog, int which) { |
404 |
| - dialog.cancel(); |
405 |
| - } |
406 |
| - }); |
| 339 | + alertadd.setPositiveButton("Proceed", (dialog, which) -> shareScreen(screenshot)); |
| 340 | + alertadd.setNegativeButton("Cancel", (dialog, which) -> dialog.cancel()); |
407 | 341 | alertadd.show();
|
408 | 342 | }
|
409 | 343 |
|
|
0 commit comments