|
3 | 3 | import android.accounts.Account;
|
4 | 4 | import android.annotation.SuppressLint;
|
5 | 5 | import android.content.Context;
|
| 6 | +import android.content.DialogInterface; |
6 | 7 | import android.content.Intent;
|
7 | 8 | import android.graphics.Bitmap;
|
8 | 9 | import android.graphics.drawable.BitmapDrawable;
|
|
13 | 14 | import android.support.v7.app.AlertDialog;
|
14 | 15 | import android.support.v7.widget.Toolbar;
|
15 | 16 | import android.util.DisplayMetrics;
|
| 17 | +import android.util.Log; |
16 | 18 | import android.view.ContextThemeWrapper;
|
17 | 19 | import android.view.LayoutInflater;
|
18 | 20 | import android.view.Menu;
|
|
26 | 28 |
|
27 | 29 | import com.dinuscxj.progressbar.CircleProgressBar;
|
28 | 30 |
|
| 31 | +import org.w3c.dom.Text; |
| 32 | + |
29 | 33 | import java.io.File;
|
30 | 34 | import java.io.FileOutputStream;
|
31 | 35 | import java.io.IOException;
|
|
42 | 46 | import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
43 | 47 | import fr.free.nrw.commons.theme.NavigationBaseActivity;
|
44 | 48 | import fr.free.nrw.commons.utils.ViewUtil;
|
| 49 | +import io.reactivex.Single; |
45 | 50 | import io.reactivex.android.schedulers.AndroidSchedulers;
|
46 | 51 | import io.reactivex.disposables.CompositeDisposable;
|
47 | 52 | import io.reactivex.schedulers.Schedulers;
|
@@ -85,6 +90,12 @@ public class AchievementsActivity extends NavigationBaseActivity {
|
85 | 90 | RelativeLayout layoutImageUsedByWiki;
|
86 | 91 | @BindView(R.id.layout_statistics)
|
87 | 92 | LinearLayout layoutStatistics;
|
| 93 | + @BindView(R.id.images_used_by_wiki_text) |
| 94 | + TextView imageByWikiText; |
| 95 | + @BindView(R.id.images_reverted_text) |
| 96 | + TextView imageRevertedText; |
| 97 | + @BindView(R.id.images_upload_text_param) |
| 98 | + TextView imageUploadedText; |
88 | 99 | @Inject
|
89 | 100 | SessionManager sessionManager;
|
90 | 101 | @Inject
|
@@ -186,23 +197,42 @@ void shareScreen(Bitmap bitmap) {
|
186 | 197 | */
|
187 | 198 | private void setAchievements() {
|
188 | 199 | if (checkAccount()) {
|
189 |
| - compositeDisposable.add(mediaWikiApi |
190 |
| - .getAchievements(Objects.requireNonNull(sessionManager.getCurrentAccount()).name) |
191 |
| - .subscribeOn(Schedulers.io()) |
192 |
| - .observeOn(AndroidSchedulers.mainThread()) |
193 |
| - .subscribe( |
194 |
| - response -> { |
195 |
| - if (response != null) { |
196 |
| - setUploadCount(Achievements.from(response)); |
197 |
| - } else { |
| 200 | + //Timber.d(String.valueOf(mediaWikiApi.getAchievements(sessionManager.getCurrentAccount().name))); |
| 201 | + /*layoutImageReverts.setVisibility(View.VISIBLE); |
| 202 | + imageView.setVisibility(View.VISIBLE);*/ |
| 203 | + try{ |
| 204 | + |
| 205 | + compositeDisposable.add(mediaWikiApi |
| 206 | + .getAchievements(Objects.requireNonNull(sessionManager.getCurrentAccount()).name) |
| 207 | + .subscribeOn(Schedulers.io()) |
| 208 | + .observeOn(AndroidSchedulers.mainThread()) |
| 209 | + .subscribe( |
| 210 | + response -> { |
| 211 | + if (response != null) { |
| 212 | + setUploadCount(Achievements.from(response)); |
| 213 | + } else { |
| 214 | + Timber.d("success"); |
| 215 | + layoutImageReverts.setVisibility(View.INVISIBLE); |
| 216 | + imageView.setVisibility(View.INVISIBLE); |
| 217 | + levelNumber.setText("You haven't qualified any level yet"); |
| 218 | + //onError(); |
| 219 | + } |
| 220 | + }, |
| 221 | + t -> { |
| 222 | + Timber.e(t, "Fetching achievements statistics failed"); |
198 | 223 | onError();
|
199 | 224 | }
|
200 |
| - }, |
201 |
| - t -> { |
202 |
| - Timber.e(t, "Fetching achievements statistics failed"); |
203 |
| - onError(); |
204 |
| - } |
205 |
| - )); |
| 225 | + )); |
| 226 | + } |
| 227 | + catch (Exception e){ |
| 228 | + Timber.d(e+"success"); |
| 229 | + /*layoutImageReverts.setVisibility(View.INVISIBLE); |
| 230 | + imageView.setVisibility(View.INVISIBLE); |
| 231 | + levelNumber.setText("You haven't qualified any level yet");*/ |
| 232 | + } |
| 233 | + |
| 234 | + |
| 235 | + |
206 | 236 | }
|
207 | 237 | }
|
208 | 238 |
|
@@ -247,10 +277,38 @@ private void setAchievementsUploadCount(Achievements achievements, int uploadCou
|
247 | 277 | * @param uploadCount
|
248 | 278 | */
|
249 | 279 | private void setUploadProgress(int uploadCount){
|
250 |
| - imagesUploadedProgressbar.setProgress |
251 |
| - (100*uploadCount/levelInfo.getMaxUploadCount()); |
252 |
| - imagesUploadedProgressbar.setProgressTextFormatPattern |
253 |
| - (uploadCount +"/" + levelInfo.getMaxUploadCount() ); |
| 280 | + if (uploadCount==0){ |
| 281 | + setZeroAchievements(); |
| 282 | + }else { |
| 283 | + |
| 284 | + imagesUploadedProgressbar.setProgress |
| 285 | + (100*uploadCount/levelInfo.getMaxUploadCount()); |
| 286 | + imagesUploadedProgressbar.setProgressTextFormatPattern |
| 287 | + (uploadCount +"/" + levelInfo.getMaxUploadCount() ); |
| 288 | + } |
| 289 | + |
| 290 | + } |
| 291 | + |
| 292 | + private void setZeroAchievements() { |
| 293 | + AlertDialog.Builder builder=new AlertDialog.Builder(this) |
| 294 | + .setMessage("You haven't made any contributions yet") |
| 295 | + .setPositiveButton("Ok", (dialog, which) -> { |
| 296 | + //dismiss |
| 297 | + }); |
| 298 | + AlertDialog dialog = builder.create(); |
| 299 | + dialog.show(); |
| 300 | + imagesUploadedProgressbar.setVisibility(View.INVISIBLE); |
| 301 | + imageRevertsProgressbar.setVisibility(View.INVISIBLE); |
| 302 | + imagesUsedByWikiProgessbar.setVisibility(View.INVISIBLE); |
| 303 | + //levelNumber.setText("LEVEL 0"); |
| 304 | + imageView.setVisibility(View.INVISIBLE); |
| 305 | + imageByWikiText.setText("No images used"); |
| 306 | + imageRevertedText.setText("No image reverted"); |
| 307 | + imageUploadedText.setText("No images Uploaded"); |
| 308 | + /*BitmapDrawable bitmapImage = BitmapUtils.writeOnDrawable(bitmap, Integer.toString(levelInfo.getLevelNumber()),this); |
| 309 | + imageView.setImageDrawable(bitmapImage);*/ |
| 310 | + imageView.setVisibility(View.INVISIBLE); |
| 311 | + |
254 | 312 | }
|
255 | 313 |
|
256 | 314 | /**
|
@@ -315,6 +373,7 @@ private void hideProgressBar(Achievements achievements) {
|
315 | 373 | layoutStatistics.setVisibility(View.VISIBLE);
|
316 | 374 | imageView.setVisibility(View.VISIBLE);
|
317 | 375 | levelNumber.setVisibility(View.VISIBLE);
|
| 376 | + //levelNumber.setText("You haven't qualified any level yet"); |
318 | 377 | }
|
319 | 378 | }
|
320 | 379 |
|
@@ -388,10 +447,10 @@ private void launchAlert(String title, String message){
|
388 | 447 | private boolean checkAccount(){
|
389 | 448 | Account currentAccount = sessionManager.getCurrentAccount();
|
390 | 449 | if (currentAccount == null) {
|
391 |
| - Timber.d("Current account is null"); |
392 |
| - ViewUtil.showLongToast(this, getResources().getString(R.string.user_not_logged_in)); |
393 |
| - sessionManager.forceLogin(this); |
394 |
| - return false; |
| 450 | + Timber.d("Current account is null"); |
| 451 | + ViewUtil.showLongToast(this, getResources().getString(R.string.user_not_logged_in)); |
| 452 | + sessionManager.forceLogin(this); |
| 453 | + return false; |
395 | 454 | }
|
396 | 455 | return true;
|
397 | 456 | }
|
|
0 commit comments