mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Get coordinate template when parsing image page
Currently the image detail view does not display the coordinates. This commit adds the coordinate template to the parser and displays the results rounded to 4 digits.
This commit is contained in:
parent
81d23a3b94
commit
c6a2f2c7ea
4 changed files with 91 additions and 0 deletions
|
|
@ -144,6 +144,14 @@ public class Media implements Parcelable {
|
||||||
this.license = license;
|
this.license = license;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCoordinates() {
|
||||||
|
return coordinates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoordinates(String coordinates) {
|
||||||
|
this.coordinates = coordinates;
|
||||||
|
}
|
||||||
|
|
||||||
// Primary metadata fields
|
// Primary metadata fields
|
||||||
protected Uri localUri;
|
protected Uri localUri;
|
||||||
protected String imageUrl;
|
protected String imageUrl;
|
||||||
|
|
@ -155,6 +163,7 @@ public class Media implements Parcelable {
|
||||||
protected int width;
|
protected int width;
|
||||||
protected int height;
|
protected int height;
|
||||||
protected String license;
|
protected String license;
|
||||||
|
protected String coordinates;
|
||||||
protected String creator;
|
protected String creator;
|
||||||
protected ArrayList<String> categories; // as loaded at runtime?
|
protected ArrayList<String> categories; // as loaded at runtime?
|
||||||
protected Map<String, String> descriptions; // multilingual descriptions as loaded
|
protected Map<String, String> descriptions; // multilingual descriptions as loaded
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ public class MediaDataExtractor {
|
||||||
private String author;
|
private String author;
|
||||||
private Date date;
|
private Date date;
|
||||||
private String license;
|
private String license;
|
||||||
|
private String coordinates;
|
||||||
private LicenseList licenseList;
|
private LicenseList licenseList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -122,6 +123,14 @@ public class MediaDataExtractor {
|
||||||
author = getFlatText(authorNode);
|
author = getFlatText(authorNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Node coordinateTemplateNode = findTemplate(doc.getDocumentElement(), "location");
|
||||||
|
|
||||||
|
if (coordinateTemplateNode != null) {
|
||||||
|
coordinates = getCoordinates(coordinateTemplateNode);
|
||||||
|
} else {
|
||||||
|
coordinates = "No coordinates found";
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Pull up the license data list...
|
Pull up the license data list...
|
||||||
look for the templates in two ways:
|
look for the templates in two ways:
|
||||||
|
|
@ -242,6 +251,35 @@ public class MediaDataExtractor {
|
||||||
return parentNode.getTextContent();
|
return parentNode.getTextContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rounds the float to 4 digits.
|
||||||
|
*
|
||||||
|
* @param coordinate A coordinate value as string.
|
||||||
|
* @return String of the rounded number.
|
||||||
|
*/
|
||||||
|
private String formatCoordinate(String coordinate) {
|
||||||
|
Float floatNumber = Float.parseFloat(coordinate);
|
||||||
|
double roundedNumber = Math.round(floatNumber * 10000d) / 10000d;
|
||||||
|
return String.valueOf(roundedNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the coordinates from the template and returns them as pretty formatted string.
|
||||||
|
* Loops over the children of the coordinate template:
|
||||||
|
* {{Location|47.50111007666667|19.055700301944444}}
|
||||||
|
* and extracts the latitude and longitude as a pretty string.
|
||||||
|
*
|
||||||
|
* @param parentNode The node of the coordinates template.
|
||||||
|
* @return Pretty formatted coordinates.
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private String getCoordinates(Node parentNode) throws IOException {
|
||||||
|
NodeList childNodes = parentNode.getChildNodes();
|
||||||
|
String latitudeText = formatCoordinate(childNodes.item(1).getTextContent());
|
||||||
|
String longitudeText = formatCoordinate(childNodes.item(2).getTextContent());
|
||||||
|
return latitudeText + " N," + longitudeText + " E";
|
||||||
|
}
|
||||||
|
|
||||||
// Extract a dictionary of multilingual texts from a subset of the parse tree.
|
// Extract a dictionary of multilingual texts from a subset of the parse tree.
|
||||||
// Texts are wrapped in things like {{en|foo} or {{en|1=foo bar}}.
|
// Texts are wrapped in things like {{en|foo} or {{en|1=foo bar}}.
|
||||||
// Text outside those wrappers is stuffed into a 'default' faux language key if present.
|
// Text outside those wrappers is stuffed into a 'default' faux language key if present.
|
||||||
|
|
@ -287,6 +325,7 @@ public class MediaDataExtractor {
|
||||||
|
|
||||||
media.setCategories(categories);
|
media.setCategories(categories);
|
||||||
media.setDescriptions(descriptions);
|
media.setDescriptions(descriptions);
|
||||||
|
media.setCoordinates(coordinates);
|
||||||
if (license != null) {
|
if (license != null) {
|
||||||
media.setLicense(license);
|
media.setLicense(license);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ public class MediaDetailFragment extends Fragment {
|
||||||
private TextView title;
|
private TextView title;
|
||||||
private TextView desc;
|
private TextView desc;
|
||||||
private TextView license;
|
private TextView license;
|
||||||
|
private TextView coordinates;
|
||||||
private LinearLayout categoryContainer;
|
private LinearLayout categoryContainer;
|
||||||
private ScrollView scrollView;
|
private ScrollView scrollView;
|
||||||
private ArrayList<String> categoryNames;
|
private ArrayList<String> categoryNames;
|
||||||
|
|
@ -123,6 +124,7 @@ public class MediaDetailFragment extends Fragment {
|
||||||
title = (TextView) view.findViewById(R.id.mediaDetailTitle);
|
title = (TextView) view.findViewById(R.id.mediaDetailTitle);
|
||||||
desc = (TextView) view.findViewById(R.id.mediaDetailDesc);
|
desc = (TextView) view.findViewById(R.id.mediaDetailDesc);
|
||||||
license = (TextView) view.findViewById(R.id.mediaDetailLicense);
|
license = (TextView) view.findViewById(R.id.mediaDetailLicense);
|
||||||
|
coordinates = (TextView) view.findViewById(R.id.mediaDetailCoordinates);
|
||||||
categoryContainer = (LinearLayout) view.findViewById(R.id.mediaDetailCategoryContainer);
|
categoryContainer = (LinearLayout) view.findViewById(R.id.mediaDetailCategoryContainer);
|
||||||
|
|
||||||
licenseList = new LicenseList(getActivity());
|
licenseList = new LicenseList(getActivity());
|
||||||
|
|
@ -226,6 +228,7 @@ public class MediaDetailFragment extends Fragment {
|
||||||
// Set text of desc, license, and categories
|
// Set text of desc, license, and categories
|
||||||
desc.setText(prettyDescription(media));
|
desc.setText(prettyDescription(media));
|
||||||
license.setText(prettyLicense(media));
|
license.setText(prettyLicense(media));
|
||||||
|
coordinates.setText(prettyCoordinates(media));
|
||||||
|
|
||||||
categoryNames.removeAll(categoryNames);
|
categoryNames.removeAll(categoryNames);
|
||||||
categoryNames.addAll(media.getCategories());
|
categoryNames.addAll(media.getCategories());
|
||||||
|
|
@ -388,4 +391,15 @@ public class MediaDetailFragment extends Fragment {
|
||||||
return licenseObj.getName();
|
return licenseObj.getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the coordinates nicely formatted.
|
||||||
|
*
|
||||||
|
* @return Coordinates as text.
|
||||||
|
*/
|
||||||
|
private String prettyCoordinates(Media media) {
|
||||||
|
String coordinates = media.getCoordinates();
|
||||||
|
|
||||||
|
return coordinates;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,35 @@
|
||||||
/>
|
/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/subBackground"
|
||||||
|
android:padding="16dp"
|
||||||
|
>
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:text="Coordinates"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:paddingBottom="6dp"
|
||||||
|
/>
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="License link"
|
||||||
|
android:id="@+id/mediaDetailCoordinates"
|
||||||
|
android:layout_gravity="left|start"
|
||||||
|
android:background="?attr/subBackground"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:padding="12dp"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<fr.free.nrw.commons.media.MediaDetailSpacer
|
<fr.free.nrw.commons.media.MediaDetailSpacer
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="8dp"
|
android:layout_height="8dp"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue