Merge pull request #5372 from osmandapp/PaulsBranch

Fixed the short description for wikipedia & removed OBJs and tumbnail…
This commit is contained in:
vshcherb 2018-05-10 14:18:33 +02:00 committed by GitHub
commit f662b35a9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 56 deletions

View file

@ -397,10 +397,8 @@ public class AmenityMenuBuilder extends MenuBuilder {
final String langSelected = lng;
String content = amenity.getDescription(langSelected);
vl = (content != null) ? Html.fromHtml(content).toString() : "";
if (vl.length() > 300) {
vl = vl.substring(0, 300);
}
vl = (content != null) ? WikiArticleHelper.getPartialContent(content) : "";
vl = vl == null ? "" : vl;
hasWiki = true;
isWiki = true;
needLinks = false;

View file

@ -7,6 +7,8 @@ import android.content.DialogInterface;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Html;
import android.util.Log;
import net.osmand.IndexConstants;
@ -33,6 +35,8 @@ import java.util.List;
public class WikiArticleHelper {
private static final String TAG = WikiArticleHelper.class.getSimpleName();
private static final int PARTIAL_CONTENT_PHRASES = 3;
private static final String ZIP_EXT = ".zip";
private static final String PAGE_PREFIX_HTTP = "http://";
private static final String PAGE_PREFIX_HTTPS = "https://";
@ -230,4 +234,48 @@ public class WikiArticleHelper {
.setNegativeButton(R.string.shared_string_cancel, null)
.show();
}
@Nullable
public static String getPartialContent(String content) {
if (content == null) {
return null;
}
String pOpened = "<p>";
String pClosed = "</p>";
int firstParagraphStart = content.indexOf(pOpened);
int firstParagraphEnd = content.indexOf(pClosed);
if (firstParagraphStart == -1 || firstParagraphEnd == -1
|| firstParagraphEnd < firstParagraphStart) {
return null;
}
int pClosedLength = pClosed.length();
String firstParagraphHtml = content.substring(firstParagraphStart, firstParagraphEnd + pClosedLength);
while (firstParagraphHtml.length() == (pOpened.length() + pClosedLength)
&& (firstParagraphEnd + pClosedLength) < content.length()) {
firstParagraphStart = content.indexOf(pOpened, firstParagraphEnd);
firstParagraphEnd = firstParagraphStart == -1 ? -1 : content.indexOf(pClosed, firstParagraphStart);
if (firstParagraphStart != -1 && firstParagraphEnd != -1) {
firstParagraphHtml = content.substring(firstParagraphStart, firstParagraphEnd + pClosedLength);
} else {
break;
}
}
String firstParagraphText = Html.fromHtml(firstParagraphHtml.replaceAll("(<(/)(a|img)>)|(<(a|img).+?>)|(<div.+?/div>)", ""))
.toString().trim();
String[] phrases = firstParagraphText.split("\\. ");
StringBuilder res = new StringBuilder();
int limit = Math.min(phrases.length, PARTIAL_CONTENT_PHRASES);
for (int i = 0; i < limit; i++) {
res.append(phrases[i]);
if (i < limit - 1) {
res.append(". ");
}
}
return res.toString();
}
}

View file

@ -2,12 +2,10 @@ package net.osmand.plus.wikivoyage;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
@ -17,10 +15,8 @@ import net.osmand.data.PointDescription;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.wikipedia.WikiArticleHelper;
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
import net.osmand.plus.wikivoyage.data.TravelArticle;
import net.osmand.plus.wikivoyage.explore.WikivoyageExploreDialogFragment;

View file

@ -3,7 +3,6 @@ package net.osmand.plus.wikivoyage.data;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.Size;
import android.text.Html;
import android.text.TextUtils;
import net.osmand.plus.GPXUtilities.GPXFile;
@ -17,8 +16,6 @@ public class TravelArticle {
private static final String THUMB_PREFIX = "320px-";
private static final String REGULAR_PREFIX = "800px-";
private static final int PARTIAL_CONTENT_PHRASES = 3;
String id;
String title;
String content;
@ -85,49 +82,6 @@ public class TravelArticle {
return aggregatedPartOf;
}
@Nullable
public String getPartialContent() {
if (content == null) {
return null;
}
String pOpened = "<p>";
String pClosed = "</p>";
int firstParagraphStart = content.indexOf(pOpened);
int firstParagraphEnd = content.indexOf(pClosed);
if (firstParagraphStart == -1 || firstParagraphEnd == -1
|| firstParagraphEnd < firstParagraphStart) {
return null;
}
int pClosedLength = pClosed.length();
String firstParagraphHtml = content.substring(firstParagraphStart, firstParagraphEnd + pClosedLength);
while (firstParagraphHtml.length() == (pOpened.length() + pClosedLength)
&& (firstParagraphEnd + pClosedLength) < content.length()) {
firstParagraphStart = content.indexOf(pOpened, firstParagraphEnd);
firstParagraphEnd = firstParagraphStart == -1 ? -1 : content.indexOf(pClosed, firstParagraphStart);
if (firstParagraphStart != -1 && firstParagraphEnd != -1) {
firstParagraphHtml = content.substring(firstParagraphStart, firstParagraphEnd + pClosedLength);
} else {
break;
}
}
String firstParagraphText = Html.fromHtml(firstParagraphHtml).toString().trim();
String[] phrases = firstParagraphText.split("\\. ");
StringBuilder res = new StringBuilder();
int limit = Math.min(phrases.length, PARTIAL_CONTENT_PHRASES);
for (int i = 0; i < limit; i++) {
res.append(phrases[i]);
if (i < limit - 1) {
res.append(". ");
}
}
return res.toString();
}
@Nullable
public String getGeoDescription() {
if (TextUtils.isEmpty(aggregatedPartOf)) {

View file

@ -6,6 +6,7 @@ import android.support.annotation.Nullable;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
import net.osmand.plus.wikipedia.WikiArticleHelper;
import java.io.File;
import java.util.ArrayList;
@ -102,7 +103,7 @@ public class TravelLocalDataHelper {
saved.lang = article.lang;
saved.aggregatedPartOf = article.aggregatedPartOf;
saved.imageTitle = article.imageTitle;
saved.content = article.getPartialContent();
saved.content = WikiArticleHelper.getPartialContent(article.getContent());
saved.lat = article.lat;
saved.lon = article.lon;
savedArticles.add(saved);

View file

@ -16,6 +16,7 @@ import net.osmand.PicassoUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.widgets.tools.CropCircleTransformation;
import net.osmand.plus.wikipedia.WikiArticleHelper;
import net.osmand.plus.wikivoyage.WikivoyageUtils;
import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
import net.osmand.plus.wikivoyage.data.TravelArticle;
@ -64,7 +65,7 @@ public class ArticleTravelCard extends BaseTravelCard {
holder.icon.setVisibility(cached != null && cached ? View.VISIBLE : View.GONE);
holder.title.setText(article.getTitle());
holder.content.setText(article.getPartialContent());
holder.content.setText(WikiArticleHelper.getPartialContent(article.getContent()));
holder.partOf.setText(article.getGeoDescription());
holder.leftButton.setText(app.getString(R.string.shared_string_read));
View.OnClickListener readClickListener = new View.OnClickListener() {