|
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;
|
|
26 | 27 |
|
27 | 28 | import com.dinuscxj.progressbar.CircleProgressBar;
|
28 | 29 |
|
| 30 | +import org.w3c.dom.Text; |
| 31 | + |
29 | 32 | import java.io.File;
|
30 | 33 | import java.io.FileOutputStream;
|
31 | 34 | import java.io.IOException;
|
|
42 | 45 | import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
43 | 46 | import fr.free.nrw.commons.theme.NavigationBaseActivity;
|
44 | 47 | import fr.free.nrw.commons.utils.ViewUtil;
|
| 48 | +import io.reactivex.Single; |
45 | 49 | import io.reactivex.android.schedulers.AndroidSchedulers;
|
46 | 50 | import io.reactivex.disposables.CompositeDisposable;
|
47 | 51 | import io.reactivex.schedulers.Schedulers;
|
48 | 52 | import timber.log.Timber;
|
49 | 53 |
|
| 54 | + |
| 55 | + |
50 | 56 | /**
|
51 | 57 | * activity for sharing feedback on uploaded activity
|
52 | 58 | */
|
@@ -85,6 +91,12 @@ public class AchievementsActivity extends NavigationBaseActivity {
|
85 | 91 | RelativeLayout layoutImageUsedByWiki;
|
86 | 92 | @BindView(R.id.layout_statistics)
|
87 | 93 | LinearLayout layoutStatistics;
|
| 94 | + @BindView(R.id.images_used_by_wiki_text) |
| 95 | + TextView imageByWikiText; |
| 96 | + @BindView(R.id.images_reverted_text) |
| 97 | + TextView imageRevertedText; |
| 98 | + @BindView(R.id.images_upload_text_param) |
| 99 | + TextView imageUploadedText; |
88 | 100 | @Inject
|
89 | 101 | SessionManager sessionManager;
|
90 | 102 | @Inject
|
@@ -183,30 +195,39 @@ void shareScreen(Bitmap bitmap) {
|
183 | 195 | private void setAchievements() {
|
184 | 196 | progressBar.setVisibility(View.VISIBLE);
|
185 | 197 | if (checkAccount()) {
|
186 |
| - compositeDisposable.add(mediaWikiApi |
187 |
| - .getAchievements(Objects.requireNonNull(sessionManager.getCurrentAccount()).name) |
188 |
| - .subscribeOn(Schedulers.io()) |
189 |
| - .observeOn(AndroidSchedulers.mainThread()) |
190 |
| - .subscribe( |
191 |
| - response -> { |
192 |
| - if (response != null) { |
193 |
| - setUploadCount(Achievements.from(response)); |
194 |
| - } else { |
| 198 | + try{ |
| 199 | + |
| 200 | + compositeDisposable.add(mediaWikiApi |
| 201 | + .getAchievements(Objects.requireNonNull(sessionManager.getCurrentAccount()).name) |
| 202 | + .subscribeOn(Schedulers.io()) |
| 203 | + .observeOn(AndroidSchedulers.mainThread()) |
| 204 | + .subscribe( |
| 205 | + response -> { |
| 206 | + if (response != null) { |
| 207 | + setUploadCount(Achievements.from(response)); |
| 208 | + } else { |
| 209 | + Timber.d("success"); |
| 210 | + layoutImageReverts.setVisibility(View.INVISIBLE); |
| 211 | + imageView.setVisibility(View.INVISIBLE); |
| 212 | + showSnackBarWithRetry(); |
| 213 | + } |
| 214 | + }, |
| 215 | + t -> { |
| 216 | + Timber.e(t, "Fetching achievements statistics failed"); |
195 | 217 | showSnackBarWithRetry();
|
196 | 218 | }
|
197 |
| - }, |
198 |
| - t -> { |
199 |
| - Timber.e(t, "Fetching achievements statistics failed"); |
200 |
| - showSnackBarWithRetry(); |
201 |
| - } |
202 |
| - )); |
| 219 | + )); |
| 220 | + } |
| 221 | + catch (Exception e){ |
| 222 | + Timber.d(e+"success"); |
| 223 | + } |
203 | 224 | }
|
204 | 225 | }
|
205 | 226 |
|
206 | 227 | private void showSnackBarWithRetry() {
|
207 | 228 | progressBar.setVisibility(View.GONE);
|
208 | 229 | ViewUtil.showDismissibleSnackBar(findViewById(android.R.id.content),
|
209 |
| - R.string.achievements_fetch_failed, R.string.retry, view -> setAchievements()); |
| 230 | + R.string.achievements_fetch_failed, R.string.retry, view -> setAchievements()); |
210 | 231 | }
|
211 | 232 |
|
212 | 233 | /**
|
@@ -250,10 +271,34 @@ private void setAchievementsUploadCount(Achievements achievements, int uploadCou
|
250 | 271 | * @param uploadCount
|
251 | 272 | */
|
252 | 273 | private void setUploadProgress(int uploadCount){
|
253 |
| - imagesUploadedProgressbar.setProgress |
254 |
| - (100*uploadCount/levelInfo.getMaxUploadCount()); |
255 |
| - imagesUploadedProgressbar.setProgressTextFormatPattern |
256 |
| - (uploadCount +"/" + levelInfo.getMaxUploadCount() ); |
| 274 | + if (uploadCount==0){ |
| 275 | + setZeroAchievements(); |
| 276 | + }else { |
| 277 | + |
| 278 | + imagesUploadedProgressbar.setProgress |
| 279 | + (100*uploadCount/levelInfo.getMaxUploadCount()); |
| 280 | + imagesUploadedProgressbar.setProgressTextFormatPattern |
| 281 | + (uploadCount +"/" + levelInfo.getMaxUploadCount() ); |
| 282 | + } |
| 283 | + |
| 284 | + } |
| 285 | + |
| 286 | + private void setZeroAchievements() { |
| 287 | + AlertDialog.Builder builder=new AlertDialog.Builder(this) |
| 288 | + .setMessage("You haven't made any contributions yet") |
| 289 | + .setPositiveButton("Ok", (dialog, which) -> { |
| 290 | + }); |
| 291 | + AlertDialog dialog = builder.create(); |
| 292 | + dialog.show(); |
| 293 | + imagesUploadedProgressbar.setVisibility(View.INVISIBLE); |
| 294 | + imageRevertsProgressbar.setVisibility(View.INVISIBLE); |
| 295 | + imagesUsedByWikiProgressBar.setVisibility(View.INVISIBLE); |
| 296 | + imageView.setVisibility(View.INVISIBLE); |
| 297 | + imageByWikiText.setText(R.string.no_image); |
| 298 | + imageRevertedText.setText(R.string.no_image_reverted); |
| 299 | + imageUploadedText.setText(R.string.no_image_uploaded); |
| 300 | + imageView.setVisibility(View.INVISIBLE); |
| 301 | + |
257 | 302 | }
|
258 | 303 |
|
259 | 304 | /**
|
@@ -391,10 +436,10 @@ private void launchAlert(String title, String message){
|
391 | 436 | private boolean checkAccount(){
|
392 | 437 | Account currentAccount = sessionManager.getCurrentAccount();
|
393 | 438 | if (currentAccount == null) {
|
394 |
| - Timber.d("Current account is null"); |
395 |
| - ViewUtil.showLongToast(this, getResources().getString(R.string.user_not_logged_in)); |
396 |
| - sessionManager.forceLogin(this); |
397 |
| - return false; |
| 439 | + Timber.d("Current account is null"); |
| 440 | + ViewUtil.showLongToast(this, getResources().getString(R.string.user_not_logged_in)); |
| 441 | + sessionManager.forceLogin(this); |
| 442 | + return false; |
398 | 443 | }
|
399 | 444 | return true;
|
400 | 445 | }
|
|
0 commit comments