mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Error handling for review image/category fetch (#1543)
This commit is contained in:
parent
76e9708025
commit
be7c850ce3
2 changed files with 23 additions and 13 deletions
|
|
@ -32,9 +32,11 @@ import fr.free.nrw.commons.auth.AuthenticatedActivity;
|
||||||
import fr.free.nrw.commons.mwapi.MediaResult;
|
import fr.free.nrw.commons.mwapi.MediaResult;
|
||||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||||
import fr.free.nrw.commons.utils.MediaDataExtractorUtil;
|
import fr.free.nrw.commons.utils.MediaDataExtractorUtil;
|
||||||
|
import fr.free.nrw.commons.utils.ViewUtil;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
import timber.log.Timber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by root on 18.05.2018.
|
* Created by root on 18.05.2018.
|
||||||
|
|
@ -113,17 +115,14 @@ public class ReviewActivity extends AuthenticatedActivity {
|
||||||
|
|
||||||
reviewPager.setCurrentItem(0);
|
reviewPager.setCurrentItem(0);
|
||||||
Observable.fromCallable(() -> {
|
Observable.fromCallable(() -> {
|
||||||
Media result = null;
|
String result = "";
|
||||||
try {
|
try {
|
||||||
result = mwApi.getRecentRandomImage();
|
Media media = mwApi.getRecentRandomImage();
|
||||||
|
if (media != null) {
|
||||||
//String thumBaseUrl = Utils.makeThumbBaseUrl(result.getFilename());
|
result = media.getFilename();
|
||||||
//reviewPagerAdapter.currentThumbBasedUrl = thumBaseUrl;
|
}
|
||||||
|
|
||||||
//Log.d("review", result.getWikiSource());
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d("review", e.toString());
|
Timber.e("Error fetching recent random image: " + e.toString());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
})
|
})
|
||||||
|
|
@ -133,17 +132,26 @@ public class ReviewActivity extends AuthenticatedActivity {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateImage(Media result) {
|
private void updateImage(String fileName) {
|
||||||
reviewController.onImageRefreshed(result.getFilename()); //file name is updated
|
if (fileName.length() == 0) {
|
||||||
|
ViewUtil.showSnackbar(drawerLayout, R.string.error_review);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
reviewController.onImageRefreshed(fileName); //file name is updated
|
||||||
reviewPagerAdapter.updateFilename();
|
reviewPagerAdapter.updateFilename();
|
||||||
reviewPager.setCurrentItem(0);
|
reviewPager.setCurrentItem(0);
|
||||||
Observable.fromCallable(() -> {
|
Observable.fromCallable(() -> {
|
||||||
MediaResult media = mwApi.fetchMediaByFilename("File:" + result.getFilename());
|
MediaResult media = mwApi.fetchMediaByFilename("File:" + fileName);
|
||||||
return MediaDataExtractorUtil.extractCategories(media.getWikiSource());
|
return MediaDataExtractorUtil.extractCategories(media.getWikiSource());
|
||||||
})
|
})
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(this::updateCategories);
|
.subscribe(this::updateCategories, this::categoryFetchError);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void categoryFetchError(Throwable throwable) {
|
||||||
|
Timber.e(throwable, "Error fetching categories");
|
||||||
|
ViewUtil.showSnackbar(drawerLayout, R.string.error_review_categories);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCategories(ArrayList<String> categories) {
|
private void updateCategories(ArrayList<String> categories) {
|
||||||
|
|
|
||||||
|
|
@ -292,6 +292,8 @@
|
||||||
<string name="no_internet">Internet unavailable</string>
|
<string name="no_internet">Internet unavailable</string>
|
||||||
<string name="internet_established">Internet available</string>
|
<string name="internet_established">Internet available</string>
|
||||||
<string name="error_notifications">Error fetching notifications</string>
|
<string name="error_notifications">Error fetching notifications</string>
|
||||||
|
<string name="error_review">Error fetching image for review. Press refresh to try again.</string>
|
||||||
|
<string name="error_review_categories">Error fetching image categories for review. Press refresh to try again.</string>
|
||||||
<string name="no_notifications">No notifications found</string>
|
<string name="no_notifications">No notifications found</string>
|
||||||
<string name="about_translate"><![CDATA[<u>Translate</u>]]></string>
|
<string name="about_translate"><![CDATA[<u>Translate</u>]]></string>
|
||||||
<string name="about_translate_title">Languages</string>
|
<string name="about_translate_title">Languages</string>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue