mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Make uploaded image's coordinates clickable
This commit is contained in:
parent
1044fe13ae
commit
7667180bc5
4 changed files with 70 additions and 39 deletions
|
|
@ -12,6 +12,8 @@ import java.util.Map;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
|
||||
public class Media implements Parcelable {
|
||||
|
||||
public static Creator<Media> CREATOR = new Creator<Media>() {
|
||||
|
|
@ -135,11 +137,11 @@ public class Media implements Parcelable {
|
|||
this.license = license;
|
||||
}
|
||||
|
||||
public String getCoordinates() {
|
||||
public LatLng getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
public void setCoordinates(String coordinates) {
|
||||
public void setCoordinates(LatLng coordinates) {
|
||||
this.coordinates = coordinates;
|
||||
}
|
||||
|
||||
|
|
@ -154,7 +156,7 @@ public class Media implements Parcelable {
|
|||
protected int width;
|
||||
protected int height;
|
||||
protected String license;
|
||||
private String coordinates;
|
||||
private LatLng coordinates;
|
||||
protected String creator;
|
||||
protected ArrayList<String> categories; // as loaded at runtime?
|
||||
protected Map<String, String> descriptions; // multilingual descriptions as loaded
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.mediawiki.api.ApiResult;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
|
@ -37,7 +39,7 @@ public class MediaDataExtractor {
|
|||
private Map<String, String> descriptions;
|
||||
private Date date;
|
||||
private String license;
|
||||
private String coordinates;
|
||||
private @Nullable LatLng coordinates;
|
||||
private LicenseList licenseList;
|
||||
|
||||
/**
|
||||
|
|
@ -125,7 +127,7 @@ public class MediaDataExtractor {
|
|||
if (coordinateTemplateNode != null) {
|
||||
coordinates = getCoordinates(coordinateTemplateNode);
|
||||
} else {
|
||||
coordinates = "No coordinates found";
|
||||
coordinates = null;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -249,22 +251,20 @@ public class MediaDataExtractor {
|
|||
}
|
||||
|
||||
/**
|
||||
* Extracts the coordinates from the template and returns them as pretty formatted string.
|
||||
* Extracts the coordinates from the template.
|
||||
* Loops over the children of the coordinate template:
|
||||
* {{Location|47.50111007666667|19.055700301944444}}
|
||||
* and extracts the latitude and longitude as a pretty string.
|
||||
* and extracts the latitude and longitude.
|
||||
*
|
||||
* @param parentNode The node of the coordinates template.
|
||||
* @return Pretty formatted coordinates.
|
||||
* @return Extracted coordinates.
|
||||
* @throws IOException Parsing failed.
|
||||
*/
|
||||
private String getCoordinates(Node parentNode) throws IOException {
|
||||
private LatLng getCoordinates(Node parentNode) throws IOException {
|
||||
NodeList childNodes = parentNode.getChildNodes();
|
||||
double latitudeText = Double.parseDouble(childNodes.item(1).getTextContent());
|
||||
double longitudeText = Double.parseDouble(childNodes.item(2).getTextContent());
|
||||
LatLng coordinates = new LatLng(latitudeText, longitudeText, 0);
|
||||
|
||||
return coordinates.getPrettyCoordinateString();
|
||||
return new LatLng(latitudeText, longitudeText, 0);
|
||||
}
|
||||
|
||||
// Extract a dictionary of multilingual texts from a subset of the parse tree.
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import fr.free.nrw.commons.MediaDataExtractor;
|
|||
import fr.free.nrw.commons.MediaWikiImageView;
|
||||
import fr.free.nrw.commons.PageTitle;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class MediaDetailFragment extends Fragment {
|
||||
|
|
@ -215,30 +216,8 @@ public class MediaDetailFragment extends Fragment {
|
|||
if (success) {
|
||||
extractor.fill(media);
|
||||
|
||||
// Set text of desc, license, and categories
|
||||
desc.setText(prettyDescription(media));
|
||||
license.setText(prettyLicense(media));
|
||||
coordinates.setText(prettyCoordinates(media));
|
||||
uploadedDate.setText(prettyUploadedDate(media));
|
||||
|
||||
categoryNames.clear();
|
||||
categoryNames.addAll(media.getCategories());
|
||||
|
||||
categoriesLoaded = true;
|
||||
categoriesPresent = (categoryNames.size() > 0);
|
||||
if (!categoriesPresent) {
|
||||
// Stick in a filler element.
|
||||
categoryNames.add(getString(R.string.detail_panel_cats_none));
|
||||
}
|
||||
rebuildCatList();
|
||||
|
||||
// Set hyperlinks
|
||||
license.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
openWebBrowser(licenseLink(media));
|
||||
}
|
||||
});
|
||||
setTextFields(media);
|
||||
setOnClickListeners(media);
|
||||
} else {
|
||||
Timber.d("Failed to load photo details.");
|
||||
}
|
||||
|
|
@ -272,6 +251,41 @@ public class MediaDetailFragment extends Fragment {
|
|||
super.onDestroyView();
|
||||
}
|
||||
|
||||
private void setTextFields(Media media) {
|
||||
desc.setText(prettyDescription(media));
|
||||
license.setText(prettyLicense(media));
|
||||
coordinates.setText(prettyCoordinates(media));
|
||||
uploadedDate.setText(prettyUploadedDate(media));
|
||||
|
||||
categoryNames.clear();
|
||||
categoryNames.addAll(media.getCategories());
|
||||
|
||||
categoriesLoaded = true;
|
||||
categoriesPresent = (categoryNames.size() > 0);
|
||||
if (!categoriesPresent) {
|
||||
// Stick in a filler element.
|
||||
categoryNames.add(getString(R.string.detail_panel_cats_none));
|
||||
}
|
||||
rebuildCatList();
|
||||
}
|
||||
|
||||
private void setOnClickListeners(final Media media) {
|
||||
license.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
openWebBrowser(licenseLink(media));
|
||||
}
|
||||
});
|
||||
if (media.getCoordinates() != null) {
|
||||
coordinates.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
openMap(media.getCoordinates());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void rebuildCatList() {
|
||||
// @fixme add the category items
|
||||
for (String cat : categoryNames) {
|
||||
|
|
@ -338,7 +352,7 @@ public class MediaDetailFragment extends Fragment {
|
|||
|
||||
private String prettyUploadedDate(Media media) {
|
||||
Date date = media.getDateUploaded();
|
||||
if (date.toString() == null || date.toString().isEmpty()) {
|
||||
if (date == null || date.toString() == null || date.toString().isEmpty()) {
|
||||
return "Uploaded date not available";
|
||||
}
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("dd MMM yyyy");
|
||||
|
|
@ -351,7 +365,10 @@ public class MediaDetailFragment extends Fragment {
|
|||
* @return Coordinates as text.
|
||||
*/
|
||||
private String prettyCoordinates(Media media) {
|
||||
return media.getCoordinates();
|
||||
if (media.getCoordinates() == null) {
|
||||
return getString(R.string.media_detail_coordinates_empty);
|
||||
}
|
||||
return media.getCoordinates().getPrettyCoordinateString();
|
||||
}
|
||||
|
||||
private @Nullable String licenseLink(Media media) {
|
||||
|
|
@ -371,4 +388,15 @@ public class MediaDetailFragment extends Fragment {
|
|||
Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
startActivity(browser);
|
||||
}
|
||||
|
||||
private void openMap(LatLng coordinates) {
|
||||
//Open map app at given position
|
||||
Uri gmmIntentUri = Uri.parse(
|
||||
"geo:0,0?q=" + coordinates.getLatitude() + "," + coordinates.getLatitude());
|
||||
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
|
||||
|
||||
if (mapIntent.resolveActivity(getActivity().getPackageManager()) != null) {
|
||||
startActivity(mapIntent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@ Tap this message (or hit back) to skip this step.</string>
|
|||
<string name="media_detail_uploaded_date">Uploaded date</string>
|
||||
<string name="media_detail_license">License</string>
|
||||
<string name="media_detail_coordinates">Coordinates</string>
|
||||
<string name="media_detail_coordinates_empty">None provided</string>
|
||||
<string name="become_a_tester_title">Become a Beta Tester</string>
|
||||
<string name="become_a_tester_description">Opt-in to our beta channel on Google Play and get early access to new features and bug fixes</string>
|
||||
<string name="beta_opt_in_link">https://play.google.com/apps/testing/fr.free.nrw.commons</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue