Missing Wiki links sow browser warning and article short description fix
This commit is contained in:
parent
35feb5a3fb
commit
8571e6ffad
2 changed files with 28 additions and 10 deletions
|
@ -88,14 +88,14 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
|
||||||
if (articleId != 0) {
|
if (articleId != 0) {
|
||||||
WikivoyageArticleDialogFragment.showInstance(app, fragmentManager, articleId, lang);
|
WikivoyageArticleDialogFragment.showInstance(app, fragmentManager, articleId, lang);
|
||||||
} else {
|
} else {
|
||||||
warnAboutExternalLoad(url);
|
warnAboutExternalLoad(url, context, nightMode);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (url.contains(WIKI_DOMAIN)) {
|
} else if (url.contains(WIKI_DOMAIN)) {
|
||||||
String articleName = getArticleNameFromUrl(url, getLang(url));
|
String articleName = getArticleNameFromUrl(url, getLang(url));
|
||||||
getWikiArticle(articleName, url);
|
getWikiArticle(articleName, url);
|
||||||
} else if (url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS)) {
|
} else if (url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS)) {
|
||||||
warnAboutExternalLoad(url);
|
warnAboutExternalLoad(url, context, nightMode);
|
||||||
} else if (url.startsWith(PREFIX_GEO)) {
|
} else if (url.startsWith(PREFIX_GEO)) {
|
||||||
if (article != null) {
|
if (article != null) {
|
||||||
List<GPXUtilities.WptPt> points = article.getGpxFile().getPoints();
|
List<GPXUtilities.WptPt> points = article.getGpxFile().getPoints();
|
||||||
|
@ -157,7 +157,7 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
|
||||||
return articleName;
|
return articleName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void warnAboutExternalLoad(final String url) {
|
private static void warnAboutExternalLoad(final String url, final Context context, final boolean nightMode) {
|
||||||
new AlertDialog.Builder(context)
|
new AlertDialog.Builder(context)
|
||||||
.setTitle(url)
|
.setTitle(url)
|
||||||
.setMessage(R.string.online_webpage_warning)
|
.setMessage(R.string.online_webpage_warning)
|
||||||
|
@ -186,7 +186,7 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
|
||||||
WikivoyageArticleWikiLinkFragment.showInstance(fragmentManager, regionName == null ?
|
WikivoyageArticleWikiLinkFragment.showInstance(fragmentManager, regionName == null ?
|
||||||
"" : regionName, url);
|
"" : regionName, url);
|
||||||
} else {
|
} else {
|
||||||
articleSearchTask = new WikiArticleSearchTask(name, indexes, (MapActivity) context);
|
articleSearchTask = new WikiArticleSearchTask(name, indexes, (MapActivity) context, nightMode, url);
|
||||||
articleSearchTask.execute();
|
articleSearchTask.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,12 +266,17 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
|
||||||
private String name;
|
private String name;
|
||||||
private List<AmenityIndexRepositoryBinary> indexes;
|
private List<AmenityIndexRepositoryBinary> indexes;
|
||||||
private WeakReference<MapActivity> weakContext;
|
private WeakReference<MapActivity> weakContext;
|
||||||
|
private boolean isNightMode;
|
||||||
|
private String url;
|
||||||
|
|
||||||
WikiArticleSearchTask(String articleName, List<AmenityIndexRepositoryBinary> indexes, MapActivity context) {
|
WikiArticleSearchTask(String articleName, List<AmenityIndexRepositoryBinary> indexes,
|
||||||
|
MapActivity context, boolean isNightMode, String url) {
|
||||||
name = articleName;
|
name = articleName;
|
||||||
this.indexes = indexes;
|
this.indexes = indexes;
|
||||||
weakContext = new WeakReference<>(context);
|
weakContext = new WeakReference<>(context);
|
||||||
dialog = createProgressDialog();
|
dialog = createProgressDialog();
|
||||||
|
this.isNightMode = isNightMode;
|
||||||
|
this.url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -309,7 +314,7 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
|
||||||
if (!found.isEmpty()) {
|
if (!found.isEmpty()) {
|
||||||
WikipediaDialogFragment.showInstance(activity, found.get(0));
|
WikipediaDialogFragment.showInstance(activity, found.get(0));
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(activity, R.string.wiki_article_not_found, Toast.LENGTH_LONG).show();
|
warnAboutExternalLoad(url, weakContext.get(), isNightMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,14 +91,27 @@ public class TravelArticle {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int firstParagraphStart = content.indexOf("<p>");
|
String pOpened = "<p>";
|
||||||
int firstParagraphEnd = content.indexOf("</p>");
|
String pClosed = "</p>";
|
||||||
|
|
||||||
|
int firstParagraphStart = content.indexOf(pOpened);
|
||||||
|
int firstParagraphEnd = content.indexOf(pClosed);
|
||||||
if (firstParagraphStart == -1 || firstParagraphEnd == -1) {
|
if (firstParagraphStart == -1 || firstParagraphEnd == -1) {
|
||||||
return null;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 4 is the length of </p> tag
|
|
||||||
String firstParagraphHtml = content.substring(firstParagraphStart, firstParagraphEnd + 4);
|
|
||||||
String firstParagraphText = Html.fromHtml(firstParagraphHtml).toString().trim();
|
String firstParagraphText = Html.fromHtml(firstParagraphHtml).toString().trim();
|
||||||
String[] phrases = firstParagraphText.split("\\. ");
|
String[] phrases = firstParagraphText.split("\\. ");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue