Fix gpx layer. Fix travel menu.
This commit is contained in:
parent
78e7bb4d3d
commit
6a8d8b91e4
4 changed files with 59 additions and 62 deletions
|
@ -3,12 +3,10 @@ package net.osmand.plus.mapcontextmenu.controllers;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import net.osmand.GPXUtilities;
|
import net.osmand.GPXUtilities.WptPt;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.GPXUtilities.WptPt;
|
|
||||||
import net.osmand.plus.GpxSelectionHelper;
|
import net.osmand.plus.GpxSelectionHelper;
|
||||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||||
import net.osmand.plus.MapMarkersHelper;
|
import net.osmand.plus.MapMarkersHelper;
|
||||||
|
@ -18,30 +16,26 @@ import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||||
import net.osmand.plus.mapcontextmenu.MenuController;
|
import net.osmand.plus.mapcontextmenu.MenuController;
|
||||||
import net.osmand.plus.mapcontextmenu.builders.WptPtMenuBuilder;
|
|
||||||
import net.osmand.plus.wikivoyage.menu.WikivoyageWptPtMenuBuilder;
|
import net.osmand.plus.wikivoyage.menu.WikivoyageWptPtMenuBuilder;
|
||||||
import net.osmand.plus.wikivoyage.menu.WikivoyageWptPtMenuController;
|
import net.osmand.plus.wikivoyage.menu.WikivoyageWptPtMenuController;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class WptPtMenuController extends MenuController {
|
public class WptPtMenuController extends MenuController {
|
||||||
|
|
||||||
private WptPt wpt;
|
private WptPt wpt;
|
||||||
private MapMarker mapMarker;
|
private MapMarker mapMarker;
|
||||||
private MapActivity mapActivity;
|
|
||||||
|
|
||||||
public WptPtMenuController(@NonNull MenuBuilder menuBuilder, @NonNull MapActivity mapActivity, @NonNull PointDescription pointDescription, @NonNull final WptPt wpt) {
|
public WptPtMenuController(@NonNull MenuBuilder menuBuilder, @NonNull MapActivity mapActivity, @NonNull PointDescription pointDescription, @NonNull final WptPt wpt) {
|
||||||
super(menuBuilder, pointDescription, mapActivity);
|
super(menuBuilder, pointDescription, mapActivity);
|
||||||
this.wpt = wpt;
|
this.wpt = wpt;
|
||||||
this.mapActivity = mapActivity;
|
MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
|
||||||
|
|
||||||
final MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
|
|
||||||
mapMarker = markersHelper.getMapMarker(wpt);
|
mapMarker = markersHelper.getMapMarker(wpt);
|
||||||
if (mapMarker == null) {
|
if (mapMarker == null) {
|
||||||
mapMarker = markersHelper.getMapMarker(new LatLon(wpt.lat, wpt.lon));
|
mapMarker = markersHelper.getMapMarker(new LatLon(wpt.lat, wpt.lon));
|
||||||
} else {
|
}
|
||||||
|
if (mapMarker != null) {
|
||||||
MapMarkerMenuController markerMenuController =
|
MapMarkerMenuController markerMenuController =
|
||||||
new MapMarkerMenuController(mapActivity, mapMarker.getPointDescription(mapActivity), mapMarker);
|
new MapMarkerMenuController(mapActivity, mapMarker.getPointDescription(mapActivity), mapMarker);
|
||||||
leftTitleButtonController = markerMenuController.getLeftTitleButtonController();
|
leftTitleButtonController = markerMenuController.getLeftTitleButtonController();
|
||||||
|
@ -147,14 +141,10 @@ public class WptPtMenuController extends MenuController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WptPtMenuController getInstance(@NonNull MapActivity mapActivity, @NonNull PointDescription pointDescription, @NonNull final WptPt wpt) {
|
public static WptPtMenuController getInstance(@NonNull MapActivity mapActivity, @NonNull PointDescription pointDescription, @NonNull final WptPt wpt) {
|
||||||
SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedGPXFile(wpt);
|
WptPtMenuController controller = WikivoyageWptPtMenuController.getInstance(mapActivity, pointDescription, wpt);
|
||||||
GPXUtilities.GPXFile gpxFile = selectedGpxFile != null ? selectedGpxFile.getGpxFile() : null;
|
if (controller == null) {
|
||||||
GPXUtilities.Metadata metadata = gpxFile != null ? gpxFile.metadata : null;
|
controller = new WptPtMenuController(new WikivoyageWptPtMenuBuilder(mapActivity, wpt), mapActivity, pointDescription, wpt);
|
||||||
Map<String, String> extensions = metadata != null ? metadata.getExtensionsToRead() : null;
|
|
||||||
String metadataDesc = extensions != null ? metadata.getExtensionsToRead().get("desc") : null;
|
|
||||||
if (metadataDesc != null && metadataDesc.contains("wikivoyage.org/")) {
|
|
||||||
return new WikivoyageWptPtMenuController(new WikivoyageWptPtMenuBuilder(mapActivity, wpt), mapActivity, pointDescription, wpt, gpxFile);
|
|
||||||
}
|
}
|
||||||
return new WptPtMenuController(new WptPtMenuBuilder(mapActivity, wpt), mapActivity, pointDescription, wpt);
|
return controller;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -395,7 +395,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
||||||
} else {
|
} else {
|
||||||
color = getPointColor(o, fileColor);
|
color = getPointColor(o, fileColor);
|
||||||
}
|
}
|
||||||
paintIcon.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
|
paintIcon.setColorFilter(new PorterDuffColorFilter(color | 0xff000000, PorterDuff.Mode.MULTIPLY));
|
||||||
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
|
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
|
||||||
smallObjectsLatLon.add(new LatLon(o.lat, o.lon));
|
smallObjectsLatLon.add(new LatLon(o.lat, o.lon));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,7 +3,7 @@ package net.osmand.plus.wikivoyage.menu;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import net.osmand.GPXUtilities;
|
import net.osmand.GPXUtilities.WptPt;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.mapcontextmenu.builders.WptPtMenuBuilder;
|
import net.osmand.plus.mapcontextmenu.builders.WptPtMenuBuilder;
|
||||||
|
@ -12,35 +12,27 @@ import net.osmand.util.Algorithms;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class WikivoyageWptPtMenuBuilder extends WptPtMenuBuilder {
|
public class WikivoyageWptPtMenuBuilder extends WptPtMenuBuilder {
|
||||||
final String KEY_PHONE = "Phone: ";
|
private final static String KEY_PHONE = "Phone: ";
|
||||||
final String KEY_EMAIL = "Email: ";
|
private final static String KEY_EMAIL = "Email: ";
|
||||||
final String KEY_WORKING_HOURS = "Working hours: ";
|
private final static String KEY_WORKING_HOURS = "Working hours: ";
|
||||||
final String KEY_PRICE = "Price: ";
|
private final static String KEY_PRICE = "Price: ";
|
||||||
final String KEY_DIRECTIONS = "Directions: ";
|
private final static String KEY_DIRECTIONS = "Directions: ";
|
||||||
final String KEY_OTHER_DESCRIPTION = "Other description";
|
private final static String KEY_DESCRIPTION = "Description";
|
||||||
|
|
||||||
public WikivoyageWptPtMenuBuilder(@NonNull MapActivity mapActivity, @NonNull GPXUtilities.WptPt wpt) {
|
public WikivoyageWptPtMenuBuilder(@NonNull MapActivity mapActivity, @NonNull WptPt wpt) {
|
||||||
super(mapActivity, wpt);
|
super(mapActivity, wpt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void prepareDescription(final GPXUtilities.WptPt wpt, View view) {
|
protected void prepareDescription(final WptPt wpt, View view) {
|
||||||
String description = wpt.desc;
|
HashMap<String, String> descTokens = getDescriptionTokens(wpt.desc, KEY_PHONE, KEY_EMAIL, KEY_WORKING_HOURS, KEY_PRICE, KEY_DIRECTIONS);
|
||||||
|
|
||||||
if (!description.contains("\n")) {
|
|
||||||
super.prepareDescription(wpt, view);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
HashMap<String, String> descTokens = getDescriptionTokens(description, KEY_PHONE, KEY_EMAIL, KEY_WORKING_HOURS, KEY_PRICE, KEY_DIRECTIONS);
|
|
||||||
|
|
||||||
String phones = descTokens.get(KEY_PHONE);
|
String phones = descTokens.get(KEY_PHONE);
|
||||||
String emails = descTokens.get(KEY_EMAIL);
|
String emails = descTokens.get(KEY_EMAIL);
|
||||||
String workingHours = descTokens.get(KEY_WORKING_HOURS);
|
String workingHours = descTokens.get(KEY_WORKING_HOURS);
|
||||||
String price = descTokens.get(KEY_PRICE);
|
String price = descTokens.get(KEY_PRICE);
|
||||||
String direction = descTokens.get(KEY_DIRECTIONS);
|
String direction = descTokens.get(KEY_DIRECTIONS);
|
||||||
|
|
||||||
final String desc = descTokens.get(KEY_OTHER_DESCRIPTION);
|
final String desc = descTokens.get(KEY_DESCRIPTION);
|
||||||
if (!Algorithms.isEmpty(desc)) {
|
if (!Algorithms.isEmpty(desc)) {
|
||||||
buildRow(view, R.drawable.ic_action_note_dark, null, desc, 0, false, null, true, 10, false, null, false);
|
buildRow(view, R.drawable.ic_action_note_dark, null, desc, 0, false, null, true, 10, false, null, false);
|
||||||
}
|
}
|
||||||
|
@ -89,8 +81,8 @@ public class WikivoyageWptPtMenuBuilder extends WptPtMenuBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!matched) {
|
if (!matched) {
|
||||||
String s = mTokens.get(KEY_OTHER_DESCRIPTION);
|
String s = mTokens.get(KEY_DESCRIPTION);
|
||||||
mTokens.put(KEY_OTHER_DESCRIPTION, s != null ? s + "\n" + token : token);
|
mTokens.put(KEY_DESCRIPTION, s != null ? s + "\n" + token : token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mTokens;
|
return mTokens;
|
||||||
|
|
|
@ -1,41 +1,56 @@
|
||||||
package net.osmand.plus.wikivoyage.menu;
|
package net.osmand.plus.wikivoyage.menu;
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import net.osmand.GPXUtilities;
|
import net.osmand.GPXUtilities.GPXFile;
|
||||||
|
import net.osmand.GPXUtilities.Metadata;
|
||||||
|
import net.osmand.GPXUtilities.WptPt;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.plus.GpxSelectionHelper;
|
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||||
import net.osmand.plus.OsmandApplication;
|
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
|
||||||
import net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController;
|
import net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController;
|
||||||
import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
|
import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
|
||||||
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
||||||
|
|
||||||
public class WikivoyageWptPtMenuController extends WptPtMenuController {
|
public class WikivoyageWptPtMenuController extends WptPtMenuController {
|
||||||
public WikivoyageWptPtMenuController(@NonNull MenuBuilder menuBuilder, @NonNull final MapActivity mapActivity, @NonNull PointDescription pointDescription, @NonNull GPXUtilities.WptPt wpt, GPXUtilities.GPXFile gpxFile) {
|
|
||||||
super(menuBuilder, mapActivity, pointDescription, wpt);
|
private WikivoyageWptPtMenuController(@NonNull MapActivity mapActivity, @NonNull PointDescription pointDescription, @NonNull WptPt wpt, @NonNull TravelArticle article) {
|
||||||
GPXUtilities.Metadata metadata = gpxFile != null ? gpxFile.metadata : null;
|
super(new WikivoyageWptPtMenuBuilder(mapActivity, wpt), mapActivity, pointDescription, wpt);
|
||||||
final TravelArticle article = metadata != null ? getTravelArticle(metadata) : null;
|
final long tripId = article.getTripId();
|
||||||
if (article != null) {
|
final String lang = article.getLang();
|
||||||
leftTitleButtonController = new TitleButtonController() {
|
leftTitleButtonController = new TitleButtonController() {
|
||||||
@Override
|
@Override
|
||||||
public void buttonPressed() {
|
public void buttonPressed() {
|
||||||
WikivoyageArticleDialogFragment.showInstance(mapActivity.getMyApplication(), mapActivity.getSupportFragmentManager(), article.getTripId(), article.getLang());
|
MapActivity mapActivity = getMapActivity();
|
||||||
|
if (mapActivity != null) {
|
||||||
|
WikivoyageArticleDialogFragment.showInstance(mapActivity.getMyApplication(),
|
||||||
|
mapActivity.getSupportFragmentManager(), tripId, lang);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
leftTitleButtonController.caption = mapActivity.getString(R.string.context_menu_read_article);
|
leftTitleButtonController.caption = mapActivity.getString(R.string.context_menu_read_article);
|
||||||
leftTitleButtonController.leftIconId = R.drawable.ic_action_read_text;
|
leftTitleButtonController.leftIconId = R.drawable.ic_action_read_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static TravelArticle getTravelArticle(@NonNull MapActivity mapActivity, @NonNull WptPt wpt) {
|
||||||
|
SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedGPXFile(wpt);
|
||||||
|
GPXFile gpxFile = selectedGpxFile != null ? selectedGpxFile.getGpxFile() : null;
|
||||||
|
Metadata metadata = gpxFile != null ? gpxFile.metadata : null;
|
||||||
|
String title = metadata != null ? metadata.getArticleTitle() : null;
|
||||||
|
String lang = metadata != null ? metadata.getArticleLang() : null;
|
||||||
|
if (!TextUtils.isEmpty(title) && !TextUtils.isEmpty(lang)) {
|
||||||
|
return mapActivity.getMyApplication().getTravelDbHelper().getArticle(title, lang);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TravelArticle getTravelArticle(@NonNull GPXUtilities.Metadata metadata) {
|
public static WptPtMenuController getInstance(@NonNull MapActivity mapActivity, @NonNull PointDescription pointDescription, @NonNull WptPt wpt) {
|
||||||
String title = metadata.getArticleTitle();
|
TravelArticle travelArticle = getTravelArticle(mapActivity, wpt);
|
||||||
String lang = metadata.getArticleLang();
|
if (travelArticle != null) {
|
||||||
if (!TextUtils.isEmpty(title) && !TextUtils.isEmpty(lang)) {
|
return new WikivoyageWptPtMenuController(mapActivity, pointDescription, wpt, travelArticle);
|
||||||
return getMapActivity().getMyApplication().getTravelDbHelper().getArticle(title, lang);
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue