Skip to content

Replace remaining AsyncTask with RxAndroid #2681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 0 additions & 127 deletions app/src/main/java/fr/free/nrw/commons/LicenseList.java

This file was deleted.

108 changes: 64 additions & 44 deletions app/src/main/java/fr/free/nrw/commons/Media.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public Media[] newArray(int i) {
protected int width;
protected int height;
protected String license;
protected String licenseUrl;
protected String creator;
protected ArrayList<String> categories; // as loaded at runtime?
protected boolean requestedDeletion;
Expand Down Expand Up @@ -332,12 +333,70 @@ public String getLicense() {
return license;
}

/**
* Creating Media object from MWQueryPage.
* Earlier only basic details were set for the media object but going forward,
* a full media object(with categories, descriptions, coordinates etc) can be constructed using this method
*
* @param page response from the API
* @return Media object
*/
@Nullable
public static Media from(MwQueryPage page) {
ImageInfo imageInfo = page.imageInfo();
if(imageInfo == null) {
return null;
}
ExtMetadata metadata = imageInfo.getMetadata();
if (metadata == null) {
return new Media(null, imageInfo.getOriginalUrl(),
page.title(), "", 0, null, null, null);
}

Media media = new Media(null,
imageInfo.getOriginalUrl(),
page.title(),
"",
0,
DateUtils.getDateFromString(metadata.dateTimeOriginal().value()),
DateUtils.getDateFromString(metadata.dateTime().value()),
StringUtils.getParsedStringFromHtml(metadata.artist().value())
);

String language = Locale.getDefault().getLanguage();
if (StringUtils.isNullOrWhiteSpace(language)) {
language = "default";
}

media.setDescriptions(Collections.singletonMap(language, metadata.imageDescription().value()));
media.setCategories(MediaDataExtractorUtil.extractCategoriesFromList(metadata.categories().value()));
String latitude = metadata.gpsLatitude().value();
String longitude = metadata.gpsLongitude().value();

if(!StringUtils.isNullOrWhiteSpace(latitude) && !StringUtils.isNullOrWhiteSpace(longitude)) {
LatLng latLng = new LatLng(Double.parseDouble(latitude), Double.parseDouble(longitude), 0);
media.setCoordinates(latLng);
}

media.setLicenseInformation(metadata.licenseShortName().value(), metadata.licenseUrl().value());
return media;
}

public String getLicenseUrl() {
return licenseUrl;
}

/**
* Sets the license name of the file.
* @param license license name as a String
*/
public void setLicense(String license) {
public void setLicenseInformation(String license, String licenseUrl) {
this.license = license;

if (!licenseUrl.startsWith("http://") && !licenseUrl.startsWith("https://")) {
licenseUrl = "https://" + licenseUrl;
}
this.licenseUrl = licenseUrl;
}

/**
Expand Down Expand Up @@ -457,50 +516,11 @@ public boolean getRequestedDeletion(){
}

/**
* Creating Media object from MWQueryPage.
* Earlier only basic details were set for the media object but going forward,
* a full media object(with categories, descriptions, coordinates etc) can be constructed using this method
* Sets the license name of the file.
*
* @param page response from the API
* @return Media object
* @param license license name as a String
*/
@Nullable
public static Media from(MwQueryPage page) {
ImageInfo imageInfo = page.imageInfo();
if(imageInfo == null) {
return null;
}
ExtMetadata metadata = imageInfo.getMetadata();
if (metadata == null) {
return new Media(null, imageInfo.getOriginalUrl(),
page.title(), "", 0, null, null, null);
}

Media media = new Media(null,
imageInfo.getOriginalUrl(),
page.title(),
"",
0,
DateUtils.getDateFromString(metadata.dateTimeOriginal().value()),
DateUtils.getDateFromString(metadata.dateTime().value()),
StringUtils.getParsedStringFromHtml(metadata.artist().value())
);

String language = Locale.getDefault().getLanguage();
if (StringUtils.isNullOrWhiteSpace(language)) {
language = "default";
}
media.setDescriptions(Collections.singletonMap(language, metadata.imageDescription().value()));
media.setCategories(MediaDataExtractorUtil.extractCategoriesFromList(metadata.categories().value()));
String latitude = metadata.gpsLatitude().value();
String longitude = metadata.gpsLongitude().value();

if(!StringUtils.isNullOrWhiteSpace(latitude) && !StringUtils.isNullOrWhiteSpace(longitude)) {
LatLng latLng = new LatLng(Double.parseDouble(latitude), Double.parseDouble(longitude), 0);
media.setCoordinates(latLng);
}

media.setLicense(metadata.licenseShortName().value());
return media;
public void setLicense(String license) {
this.license = license;
}
}
Loading