mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Merge pull request #777 from akaita/media_detail
Fix issues in Media Detail screen
This commit is contained in:
commit
19a3fa3adc
6 changed files with 51 additions and 30 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
public class License {
|
||||
String key;
|
||||
String template;
|
||||
|
|
@ -36,7 +38,7 @@ public class License {
|
|||
}
|
||||
}
|
||||
|
||||
public String getUrl(String language) {
|
||||
public @Nullable String getUrl(String language) {
|
||||
if (url == null) {
|
||||
return null;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package fr.free.nrw.commons;
|
|||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
|
@ -12,6 +13,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>() {
|
||||
|
|
@ -99,7 +102,7 @@ public class Media implements Parcelable {
|
|||
this.dateCreated = date;
|
||||
}
|
||||
|
||||
public Date getDateUploaded() {
|
||||
public @Nullable Date getDateUploaded() {
|
||||
return dateUploaded;
|
||||
}
|
||||
|
||||
|
|
@ -135,11 +138,11 @@ public class Media implements Parcelable {
|
|||
this.license = license;
|
||||
}
|
||||
|
||||
public String getCoordinates() {
|
||||
public @Nullable LatLng getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
public void setCoordinates(String coordinates) {
|
||||
public void setCoordinates(LatLng coordinates) {
|
||||
this.coordinates = coordinates;
|
||||
}
|
||||
|
||||
|
|
@ -150,11 +153,11 @@ public class Media implements Parcelable {
|
|||
protected String description; // monolingual description on input...
|
||||
protected long dataLength;
|
||||
protected Date dateCreated;
|
||||
protected Date dateUploaded;
|
||||
protected @Nullable Date dateUploaded;
|
||||
protected int width;
|
||||
protected int height;
|
||||
protected String license;
|
||||
private String coordinates;
|
||||
private @Nullable 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,8 @@
|
|||
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;
|
||||
import org.w3c.dom.Node;
|
||||
|
|
@ -38,7 +41,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;
|
||||
|
||||
/**
|
||||
|
|
@ -112,7 +115,7 @@ public class MediaDataExtractor {
|
|||
if (coordinateTemplateNode != null) {
|
||||
coordinates = getCoordinates(coordinateTemplateNode);
|
||||
} else {
|
||||
coordinates = "No coordinates found";
|
||||
coordinates = null;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -236,22 +239,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.
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@ package fr.free.nrw.commons.media;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.database.DataSetObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
|
|
@ -18,6 +20,7 @@ import java.io.IOException;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import fr.free.nrw.commons.License;
|
||||
import fr.free.nrw.commons.LicenseList;
|
||||
|
|
@ -26,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 {
|
||||
|
|
@ -262,6 +266,7 @@ public class MediaDetailFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void rebuildCatList() {
|
||||
categoryContainer.removeAllViews();
|
||||
// @fixme add the category items
|
||||
for (String cat : categoryNames) {
|
||||
View catLabel = buildCatLabel(cat);
|
||||
|
|
@ -327,7 +332,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");
|
||||
|
|
@ -340,6 +345,9 @@ 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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
|
@ -76,7 +77,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:text="@string/media_detail_media_title"
|
||||
android:id="@+id/mediaDetailTitle"
|
||||
android:layout_gravity="left|start"
|
||||
android:layout_gravity="start"
|
||||
android:textColor="@android:color/white"
|
||||
android:background="?attr/subBackground"
|
||||
android:textSize="14sp"
|
||||
|
|
@ -112,7 +113,7 @@
|
|||
android:background="?attr/subBackground"
|
||||
android:id="@+id/mediaDetailDesc"
|
||||
android:textColor="@android:color/white"
|
||||
android:layout_gravity="left|start"
|
||||
android:layout_gravity="start"
|
||||
android:textSize="14sp"
|
||||
android:padding="12dp"
|
||||
/>
|
||||
|
|
@ -130,26 +131,28 @@
|
|||
android:background="?attr/subBackground"
|
||||
android:padding="16dp"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/media_detail_license"
|
||||
android:textColor="@android:color/white"
|
||||
android:text="License"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:paddingBottom="6dp"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/mediaDetailLicense"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="License link"
|
||||
android:id="@+id/mediaDetailLicense"
|
||||
android:layout_gravity="left|start"
|
||||
android:layout_gravity="start"
|
||||
android:background="?attr/subBackground"
|
||||
android:text="@string/media_detail_license"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="14sp"
|
||||
android:padding="12dp"
|
||||
/>
|
||||
tools:text="License link" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
|
@ -163,7 +166,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@android:color/white"
|
||||
android:text="Coordinates"
|
||||
android:text="@string/media_detail_coordinates"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:paddingBottom="6dp"
|
||||
|
|
@ -171,13 +174,14 @@
|
|||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="License link"
|
||||
android:text="@string/media_detail_coordinates"
|
||||
android:id="@+id/mediaDetailCoordinates"
|
||||
android:layout_gravity="left|start"
|
||||
android:layout_gravity="start"
|
||||
android:background="?attr/subBackground"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="14sp"
|
||||
android:padding="12dp"
|
||||
tools:text="Coordinates link"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
|
|
@ -199,7 +203,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:text="@string/detail_panel_cats_label"
|
||||
android:textSize="16sp"
|
||||
android:layout_gravity="left|start"
|
||||
android:layout_gravity="start"
|
||||
android:textColor="@android:color/white"
|
||||
android:paddingBottom="6dp"
|
||||
/>
|
||||
|
|
@ -239,7 +243,7 @@
|
|||
android:background="?attr/subBackground"
|
||||
android:id="@+id/mediaDetailuploadeddate"
|
||||
android:textColor="@android:color/white"
|
||||
android:layout_gravity="left|start"
|
||||
android:layout_gravity="start"
|
||||
android:textSize="14sp"
|
||||
android:padding="12dp"
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -153,7 +153,10 @@ Tap this message (or hit back) to skip this step.</string>
|
|||
<string name="media_detail_media_title">Title of the media</string>
|
||||
<string name="media_detail_description">Description</string>
|
||||
<string name="media_detail_description_explanation">Description of the media goes here. This can potentially be fairly long, and will need to wrap across multiple lines. We hope it looks nice though.</string>
|
||||
<string name="media_detail_uploaded_date">Uploaded date</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