From 1469e075c0de62e6eff382207aab495c23ebf1c2 Mon Sep 17 00:00:00 2001 From: PaulStets Date: Wed, 18 Apr 2018 13:51:01 +0300 Subject: [PATCH 1/8] Open on map opens the gpx waypoint on the map --- .../WikivoyageBaseDialogFragment.java | 10 +++ .../wikivoyage/WikivoyageWebViewClient.java | 64 +++++++++++++++++-- .../WikivoyageArticleDialogFragment.java | 5 +- 3 files changed, 74 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageBaseDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageBaseDialogFragment.java index d3b3ab5329..87dea4e54b 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageBaseDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageBaseDialogFragment.java @@ -10,6 +10,8 @@ import android.support.annotation.DrawableRes; import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; import android.support.v4.content.ContextCompat; import android.support.v7.widget.Toolbar; import android.view.ContextThemeWrapper; @@ -48,6 +50,14 @@ public class WikivoyageBaseDialogFragment extends BaseOsmAndDialogFragment { return dialog; } + @Override + public void show(FragmentManager manager, String tag) { + FragmentTransaction ft = manager.beginTransaction(); + ft.add(this, tag); + ft.addToBackStack(tag); + ft.commit(); + } + @Override protected Drawable getContentIcon(int id) { return getIcon(id, R.color.icon_color); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java index 2dcde0426c..d4bc710b27 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java @@ -5,18 +5,29 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; +import android.support.v4.app.Fragment; 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; +import net.osmand.data.LatLon; +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.wikivoyage.article.WikivoyageArticleDialogFragment; +import net.osmand.plus.wikivoyage.explore.WikivoyageExploreDialogFragment; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; +import java.util.List; + +import static android.support.v4.app.FragmentManager.POP_BACK_STACK_INCLUSIVE; /** * Custom WebView client to handle the internal links. @@ -24,11 +35,16 @@ import java.net.URLDecoder; public class WikivoyageWebViewClient extends WebViewClient { + private static final String TAG = WikivoyageWebViewClient.class.getSimpleName(); + private OsmandApplication app; private FragmentManager fragmentManager; private Context context; + private GPXUtilities.GPXFile gpxFile; - private static final String PAGE_PREFIX = "https://"; + private static final String PREFIX_GEO = "geo:"; + private static final String PAGE_PREFIX_HTTP = "http://"; + private static final String PAGE_PREFIX_HTTPS = "https://"; private static final String WEB_DOMAIN = ".wikivoyage.com/wiki/"; public WikivoyageWebViewClient(FragmentActivity context, FragmentManager fm) { @@ -40,8 +56,8 @@ public class WikivoyageWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.contains(WEB_DOMAIN)) { - String lang = url.substring(url.startsWith(PAGE_PREFIX) ? PAGE_PREFIX.length() : 0, url.indexOf(".")); - String articleName = url.replace(PAGE_PREFIX + lang + WEB_DOMAIN, "") + String lang = url.substring(url.startsWith(PAGE_PREFIX_HTTPS) ? PAGE_PREFIX_HTTPS.length() : 0, url.indexOf(".")); + String articleName = url.replace(PAGE_PREFIX_HTTPS + lang + WEB_DOMAIN, "") .replaceAll("_", " "); try { articleName = URLDecoder.decode(articleName, "UTF-8"); @@ -55,8 +71,44 @@ public class WikivoyageWebViewClient extends WebViewClient { warnAboutExternalLoad(url); } return true; + } else if (url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS)) { + warnAboutExternalLoad(url); + } else if (url.startsWith(PREFIX_GEO)) { + if (gpxFile != null) { + List points = gpxFile.getPoints(); + GPXUtilities.WptPt gpxPoint = null; + String coordinates = url.replace(PREFIX_GEO, ""); + double lat; + double lon; + try { + lat = Double.valueOf(coordinates.substring(0, coordinates.indexOf(","))); + lon = Double.valueOf(coordinates.substring(coordinates.indexOf(",") + 1, + coordinates.length())); + } catch (NumberFormatException e) { + Log.w(TAG, e.getMessage(), e); + return true; + } + for (GPXUtilities.WptPt point : points) { + if (point.getLatitude() == lat && point.getLongitude() == lon) { + gpxPoint = point; + break; + } + } + if (gpxPoint != null) { + final OsmandSettings settings = app.getSettings(); + settings.setMapLocationToShow(lat, lon, settings.getLastKnownMapZoom(), + new PointDescription(PointDescription.POINT_TYPE_WPT, gpxPoint.name), + false, + gpxPoint); + fragmentManager.popBackStackImmediate(WikivoyageExploreDialogFragment.TAG, + POP_BACK_STACK_INCLUSIVE); + MapActivity.launchMapActivityMoveToTop(context); + } + } + } else { + Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + context.startActivity(i); } - warnAboutExternalLoad(url); return true; } @@ -74,4 +126,8 @@ public class WikivoyageWebViewClient extends WebViewClient { .setNegativeButton(R.string.shared_string_cancel, null) .show(); } + + public void setGpxFile(GPXUtilities.GPXFile gpxFile) { + this.gpxFile = gpxFile; + } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java index d811a5449e..5379864079 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java @@ -110,6 +110,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen private WebView contentWebView; private TextView articleToolbarText; + private WikivoyageWebViewClient webViewClient; @SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"}) @Nullable @@ -196,7 +197,8 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen webSettings.setJavaScriptEnabled(true); updateWebSettings(); contentWebView.addJavascriptInterface(new WikivoyageArticleWebAppInterface(), "Android"); - contentWebView.setWebViewClient(new WikivoyageWebViewClient(getActivity(), getFragmentManager())); + webViewClient = new WikivoyageWebViewClient(getActivity(), getFragmentManager()); + contentWebView.setWebViewClient(webViewClient); return mainView; } @@ -340,6 +342,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen articleToolbarText.setText(article.getTitle()); if (article.getGpxFile() != null) { trackButton.setText(getString(R.string.points) + " (" + article.getGpxFile().getPointsSize() + ")"); + webViewClient.setGpxFile(article.getGpxFile()); } TravelLocalDataHelper ldh = getMyApplication().getTravelDbHelper().getLocalDataHelper(); From bbf68f55b82006827479eaf67528c4989c2c2fb3 Mon Sep 17 00:00:00 2001 From: PaulStets Date: Wed, 18 Apr 2018 15:08:01 +0300 Subject: [PATCH 2/8] Open on map also displays the article's track --- .../wikivoyage/WikivoyageWebViewClient.java | 21 ++++++++++++------- .../WikivoyageArticleDialogFragment.java | 2 +- .../plus/wikivoyage/data/TravelDbHelper.java | 4 +++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java index d4bc710b27..e72f83939c 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java @@ -5,7 +5,6 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; -import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v7.app.AlertDialog; @@ -13,7 +12,6 @@ import android.util.Log; import android.webkit.WebView; import android.webkit.WebViewClient; -import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.GPXUtilities; import net.osmand.plus.OsmandApplication; @@ -21,8 +19,10 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment; +import net.osmand.plus.wikivoyage.data.TravelArticle; import net.osmand.plus.wikivoyage.explore.WikivoyageExploreDialogFragment; +import java.io.File; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.List; @@ -40,7 +40,7 @@ public class WikivoyageWebViewClient extends WebViewClient { private OsmandApplication app; private FragmentManager fragmentManager; private Context context; - private GPXUtilities.GPXFile gpxFile; + private TravelArticle article; private static final String PREFIX_GEO = "geo:"; private static final String PAGE_PREFIX_HTTP = "http://"; @@ -62,7 +62,7 @@ public class WikivoyageWebViewClient extends WebViewClient { try { articleName = URLDecoder.decode(articleName, "UTF-8"); } catch (UnsupportedEncodingException e) { - e.printStackTrace(); + Log.w(TAG, e.getMessage(), e); } long articleId = app.getTravelDbHelper().getArticleId(articleName, lang); if (articleId != 0) { @@ -74,8 +74,8 @@ public class WikivoyageWebViewClient extends WebViewClient { } else if (url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS)) { warnAboutExternalLoad(url); } else if (url.startsWith(PREFIX_GEO)) { - if (gpxFile != null) { - List points = gpxFile.getPoints(); + if (article != null) { + List points = article.getGpxFile().getPoints(); GPXUtilities.WptPt gpxPoint = null; String coordinates = url.replace(PREFIX_GEO, ""); double lat; @@ -102,6 +102,11 @@ public class WikivoyageWebViewClient extends WebViewClient { gpxPoint); fragmentManager.popBackStackImmediate(WikivoyageExploreDialogFragment.TAG, POP_BACK_STACK_INCLUSIVE); + + File path = app.getTravelDbHelper().createGpxFile(article); + GPXUtilities.GPXFile gpxFile = article.getGpxFile(); + gpxFile.path = path.getAbsolutePath(); + app.getSelectedGpxHelper().setGpxFileToDisplay(gpxFile); MapActivity.launchMapActivityMoveToTop(context); } } @@ -127,7 +132,7 @@ public class WikivoyageWebViewClient extends WebViewClient { .show(); } - public void setGpxFile(GPXUtilities.GPXFile gpxFile) { - this.gpxFile = gpxFile; + public void setArticle(TravelArticle article) { + this.article = article; } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java index 5379864079..76caaacf0f 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java @@ -342,7 +342,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen articleToolbarText.setText(article.getTitle()); if (article.getGpxFile() != null) { trackButton.setText(getString(R.string.points) + " (" + article.getGpxFile().getPointsSize() + ")"); - webViewClient.setGpxFile(article.getGpxFile()); + webViewClient.setArticle(article); } TravelLocalDataHelper ldh = getMyApplication().getTravelDbHelper().getLocalDataHelper(); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java index 58f77f89f5..933ac1ac8e 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java @@ -423,7 +423,9 @@ public class TravelDbHelper { public File createGpxFile(TravelArticle article) { final GPXFile gpx = article.getGpxFile(); File file = application.getAppPath(IndexConstants.GPX_TRAVEL_DIR + getGPXName(article)); - GPXUtilities.writeGpxFile(file, gpx, application); + if (!file.exists()) { + GPXUtilities.writeGpxFile(file, gpx, application); + } return file; } } From dd9b8d52ba570160d9063aaa4fad7d5151020d2b Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Wed, 18 Apr 2018 16:26:17 +0300 Subject: [PATCH 3/8] Fix fav/wpt edit layout bugs --- OsmAnd/res/layout/point_editor_fragment.xml | 125 +++++++++--------- .../activities/FavoritesTreeFragment.java | 3 +- .../osmand/plus/base/BaseOsmAndFragment.java | 26 +++- .../base/OsmandExpandableListFragment.java | 3 +- .../download/ui/LocalIndexesFragment.java | 3 +- .../firstusage/FirstUsageWizardFragment.java | 3 +- .../plus/liveupdates/LiveUpdatesFragment.java | 2 +- .../plus/liveupdates/ReportsFragment.java | 3 +- .../MapContextMenuFragment.java | 8 +- .../ContextMenuCardDialogFragment.java | 3 +- .../editors/FavoritePointEditorFragment.java | 3 +- .../editors/PointEditorFragment.java | 52 +++----- .../other/MapRouteInfoMenuFragment.java | 3 +- .../other/TrackDetailsMenuFragment.java | 3 +- .../mapillary/MapillaryFiltersFragment.java | 3 +- .../plus/mapmarkers/PlanRouteFragment.java | 3 +- .../MeasurementToolFragment.java | 3 +- .../plus/myplaces/AvailableGPXFragment.java | 3 +- .../plus/myplaces/TrackPointFragment.java | 2 +- .../plus/osmedit/AdvancedEditPoiFragment.java | 3 +- .../plus/osmedit/BasicEditPoiFragment.java | 3 +- .../quickaction/QuickActionListFragment.java | 3 +- 22 files changed, 140 insertions(+), 123 deletions(-) diff --git a/OsmAnd/res/layout/point_editor_fragment.xml b/OsmAnd/res/layout/point_editor_fragment.xml index ac42369a5a..b55876fb2b 100644 --- a/OsmAnd/res/layout/point_editor_fragment.xml +++ b/OsmAnd/res/layout/point_editor_fragment.xml @@ -1,11 +1,12 @@ @@ -231,76 +231,75 @@ - - - - - - - -