mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
parent
3b7b6f91a2
commit
31c688860d
7 changed files with 89 additions and 0 deletions
|
|
@ -39,6 +39,7 @@ public class Media implements Parcelable {
|
||||||
protected String imageUrl;
|
protected String imageUrl;
|
||||||
protected String filename;
|
protected String filename;
|
||||||
protected String description; // monolingual description on input...
|
protected String description; // monolingual description on input...
|
||||||
|
protected String discussion;
|
||||||
protected long dataLength;
|
protected long dataLength;
|
||||||
protected Date dateCreated;
|
protected Date dateCreated;
|
||||||
protected @Nullable Date dateUploaded;
|
protected @Nullable Date dateUploaded;
|
||||||
|
|
@ -195,6 +196,22 @@ public class Media implements Parcelable {
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the discussion of the file.
|
||||||
|
* @param discussion
|
||||||
|
*/
|
||||||
|
public void setDiscussion(String discussion) {
|
||||||
|
this.discussion = discussion;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the file discussion as a string.
|
||||||
|
* @return file discussion as a string
|
||||||
|
*/
|
||||||
|
public String getDiscussion() {
|
||||||
|
return discussion;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the file description.
|
* Gets the file description.
|
||||||
* @return file description as a string
|
* @return file description as a string
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package fr.free.nrw.commons;
|
package fr.free.nrw.commons;
|
||||||
|
|
||||||
|
import android.text.Html;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
|
@ -39,6 +40,7 @@ public class MediaDataExtractor {
|
||||||
private boolean deletionStatus;
|
private boolean deletionStatus;
|
||||||
private ArrayList<String> categories;
|
private ArrayList<String> categories;
|
||||||
private Map<String, String> descriptions;
|
private Map<String, String> descriptions;
|
||||||
|
private String discussion;
|
||||||
private String license;
|
private String license;
|
||||||
private @Nullable LatLng coordinates;
|
private @Nullable LatLng coordinates;
|
||||||
|
|
||||||
|
|
@ -48,6 +50,7 @@ public class MediaDataExtractor {
|
||||||
this.descriptions = new HashMap<>();
|
this.descriptions = new HashMap<>();
|
||||||
this.fetched = false;
|
this.fetched = false;
|
||||||
this.mediaWikiApi = mwApi;
|
this.mediaWikiApi = mwApi;
|
||||||
|
this.discussion = new String();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -70,6 +73,9 @@ public class MediaDataExtractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaResult result = mediaWikiApi.fetchMediaByFilename(filename);
|
MediaResult result = mediaWikiApi.fetchMediaByFilename(filename);
|
||||||
|
MediaResult discussion = mediaWikiApi.fetchMediaByFilename(filename.replace("File", "File talk"));
|
||||||
|
setDiscussion(discussion.getWikiSource());
|
||||||
|
|
||||||
|
|
||||||
// In-page category links are extracted from source, as XML doesn't cover [[links]]
|
// In-page category links are extracted from source, as XML doesn't cover [[links]]
|
||||||
extractCategories(result.getWikiSource());
|
extractCategories(result.getWikiSource());
|
||||||
|
|
@ -94,6 +100,14 @@ public class MediaDataExtractor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setDiscussion(String source) {
|
||||||
|
try {
|
||||||
|
discussion = Html.fromHtml(mediaWikiApi.parseWikicode(source)).toString();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void processWikiParseTree(String source, LicenseList licenseList) throws IOException {
|
private void processWikiParseTree(String source, LicenseList licenseList) throws IOException {
|
||||||
Document doc;
|
Document doc;
|
||||||
try {
|
try {
|
||||||
|
|
@ -307,6 +321,7 @@ public class MediaDataExtractor {
|
||||||
media.setCategories(categories);
|
media.setCategories(categories);
|
||||||
media.setDescriptions(descriptions);
|
media.setDescriptions(descriptions);
|
||||||
media.setCoordinates(coordinates);
|
media.setCoordinates(coordinates);
|
||||||
|
media.setDiscussion(discussion);
|
||||||
if (license != null) {
|
if (license != null) {
|
||||||
media.setLicense(license);
|
media.setLicense(license);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,8 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
||||||
TextView coordinates;
|
TextView coordinates;
|
||||||
@BindView(R.id.mediaDetailuploadeddate)
|
@BindView(R.id.mediaDetailuploadeddate)
|
||||||
TextView uploadedDate;
|
TextView uploadedDate;
|
||||||
|
@BindView(R.id.mediaDetailDisc)
|
||||||
|
TextView mediaDiscussion;
|
||||||
@BindView(R.id.seeMore)
|
@BindView(R.id.seeMore)
|
||||||
TextView seeMore;
|
TextView seeMore;
|
||||||
@BindView(R.id.nominatedDeletionBanner)
|
@BindView(R.id.nominatedDeletionBanner)
|
||||||
|
|
@ -341,6 +343,7 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
||||||
license.setText(prettyLicense(media));
|
license.setText(prettyLicense(media));
|
||||||
coordinates.setText(prettyCoordinates(media));
|
coordinates.setText(prettyCoordinates(media));
|
||||||
uploadedDate.setText(prettyUploadedDate(media));
|
uploadedDate.setText(prettyUploadedDate(media));
|
||||||
|
mediaDiscussion.setText(prettyDiscussion(media));
|
||||||
|
|
||||||
categoryNames.clear();
|
categoryNames.clear();
|
||||||
categoryNames.addAll(media.getCategories());
|
categoryNames.addAll(media.getCategories());
|
||||||
|
|
@ -502,6 +505,14 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private String prettyDiscussion(Media media) {
|
||||||
|
String disc = media.getDiscussion().trim();
|
||||||
|
if (disc.equals("")) {
|
||||||
|
return getString(R.string.detail_discussion_empty);
|
||||||
|
} else {
|
||||||
|
return disc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String prettyLicense(Media media) {
|
private String prettyLicense(Media media) {
|
||||||
String licenseKey = media.getLicense();
|
String licenseKey = media.getLicense();
|
||||||
|
|
|
||||||
|
|
@ -306,6 +306,17 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
||||||
.getString("/api/query/pages/page/imageinfo/ii/@thumburl");
|
.getString("/api/query/pages/page/imageinfo/ii/@thumburl");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String parseWikicode(String source) throws IOException {
|
||||||
|
return api.action("flow-parsoid-utils")
|
||||||
|
.param("from", "wikitext")
|
||||||
|
.param("to", "html")
|
||||||
|
.param("content", source)
|
||||||
|
.param("title", "Main_page")
|
||||||
|
.get()
|
||||||
|
.getString("/api/flow-parsoid-utils/@content");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public MediaResult fetchMediaByFilename(String filename) throws IOException {
|
public MediaResult fetchMediaByFilename(String filename) throws IOException {
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,8 @@ public interface MediaWikiApi {
|
||||||
@Nullable
|
@Nullable
|
||||||
boolean addWikidataEditTag(String revisionId) throws IOException;
|
boolean addWikidataEditTag(String revisionId) throws IOException;
|
||||||
|
|
||||||
|
String parseWikicode(String source) throws IOException;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
MediaResult fetchMediaByFilename(String filename) throws IOException;
|
MediaResult fetchMediaByFilename(String filename) throws IOException;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -309,6 +309,37 @@
|
||||||
android:textStyle="bold"/>
|
android:textStyle="bold"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<fr.free.nrw.commons.media.MediaDetailSpacer
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/small_gap" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/subBackground"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="@dimen/standard_gap">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingBottom="@dimen/tiny_gap"
|
||||||
|
android:text="@string/media_detail_discussion"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="@dimen/normal_text"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/mediaDetailDisc"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="start"
|
||||||
|
android:background="?attr/subBackground"
|
||||||
|
android:padding="@dimen/small_gap"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="@dimen/description_text_size" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/copyWikicode"
|
android:id="@+id/copyWikicode"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
||||||
|
|
@ -158,6 +158,7 @@
|
||||||
<string name="detail_panel_cats_loading">Loading…</string>
|
<string name="detail_panel_cats_loading">Loading…</string>
|
||||||
<string name="detail_panel_cats_none">None selected</string>
|
<string name="detail_panel_cats_none">None selected</string>
|
||||||
<string name="detail_description_empty">No description</string>
|
<string name="detail_description_empty">No description</string>
|
||||||
|
<string name="detail_discussion_empty">No discussion</string>
|
||||||
<string name="detail_license_empty">Unknown license</string>
|
<string name="detail_license_empty">Unknown license</string>
|
||||||
<string name="menu_refresh">Refresh</string>
|
<string name="menu_refresh">Refresh</string>
|
||||||
<string name="storage_permission_title">Requesting Storage Permission</string>
|
<string name="storage_permission_title">Requesting Storage Permission</string>
|
||||||
|
|
@ -173,6 +174,7 @@
|
||||||
<string name="no">No</string>
|
<string name="no">No</string>
|
||||||
<string name="media_detail_title">Title</string>
|
<string name="media_detail_title">Title</string>
|
||||||
<string name="media_detail_description">Description</string>
|
<string name="media_detail_description">Description</string>
|
||||||
|
<string name="media_detail_discussion">Discussion</string>
|
||||||
<string name="media_detail_author">Author</string>
|
<string name="media_detail_author">Author</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_license">License</string>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue