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.support.annotation.NonNull;
|
||||
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.PointDescription;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
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.mapcontextmenu.MenuBuilder;
|
||||
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.WikivoyageWptPtMenuController;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
public class WptPtMenuController extends MenuController {
|
||||
|
||||
private WptPt wpt;
|
||||
private MapMarker mapMarker;
|
||||
private MapActivity mapActivity;
|
||||
|
||||
public WptPtMenuController(@NonNull MenuBuilder menuBuilder, @NonNull MapActivity mapActivity, @NonNull PointDescription pointDescription, @NonNull final WptPt wpt) {
|
||||
super(menuBuilder, pointDescription, mapActivity);
|
||||
this.wpt = wpt;
|
||||
this.mapActivity = mapActivity;
|
||||
|
||||
final MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
|
||||
MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
|
||||
mapMarker = markersHelper.getMapMarker(wpt);
|
||||
if (mapMarker == null) {
|
||||
mapMarker = markersHelper.getMapMarker(new LatLon(wpt.lat, wpt.lon));
|
||||
} else {
|
||||
}
|
||||
if (mapMarker != null) {
|
||||
MapMarkerMenuController markerMenuController =
|
||||
new MapMarkerMenuController(mapActivity, mapMarker.getPointDescription(mapActivity), mapMarker);
|
||||
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) {
|
||||
SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedGPXFile(wpt);
|
||||
GPXUtilities.GPXFile gpxFile = selectedGpxFile != null ? selectedGpxFile.getGpxFile() : null;
|
||||
GPXUtilities.Metadata metadata = gpxFile != null ? gpxFile.metadata : null;
|
||||
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);
|
||||
WptPtMenuController controller = WikivoyageWptPtMenuController.getInstance(mapActivity, pointDescription, wpt);
|
||||
if (controller == null) {
|
||||
controller = new WptPtMenuController(new WikivoyageWptPtMenuBuilder(mapActivity, wpt), mapActivity, pointDescription, wpt);
|
||||
}
|
||||
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 {
|
||||
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);
|
||||
smallObjectsLatLon.add(new LatLon(o.lat, o.lon));
|
||||
} else {
|
||||
|
|
|
@ -3,7 +3,7 @@ package net.osmand.plus.wikivoyage.menu;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.mapcontextmenu.builders.WptPtMenuBuilder;
|
||||
|
@ -12,35 +12,27 @@ import net.osmand.util.Algorithms;
|
|||
import java.util.HashMap;
|
||||
|
||||
public class WikivoyageWptPtMenuBuilder extends WptPtMenuBuilder {
|
||||
final String KEY_PHONE = "Phone: ";
|
||||
final String KEY_EMAIL = "Email: ";
|
||||
final String KEY_WORKING_HOURS = "Working hours: ";
|
||||
final String KEY_PRICE = "Price: ";
|
||||
final String KEY_DIRECTIONS = "Directions: ";
|
||||
final String KEY_OTHER_DESCRIPTION = "Other description";
|
||||
private final static String KEY_PHONE = "Phone: ";
|
||||
private final static String KEY_EMAIL = "Email: ";
|
||||
private final static String KEY_WORKING_HOURS = "Working hours: ";
|
||||
private final static String KEY_PRICE = "Price: ";
|
||||
private final static String KEY_DIRECTIONS = "Directions: ";
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareDescription(final GPXUtilities.WptPt wpt, View view) {
|
||||
String description = wpt.desc;
|
||||
|
||||
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);
|
||||
|
||||
protected void prepareDescription(final WptPt wpt, View view) {
|
||||
HashMap<String, String> descTokens = getDescriptionTokens(wpt.desc, KEY_PHONE, KEY_EMAIL, KEY_WORKING_HOURS, KEY_PRICE, KEY_DIRECTIONS);
|
||||
String phones = descTokens.get(KEY_PHONE);
|
||||
String emails = descTokens.get(KEY_EMAIL);
|
||||
String workingHours = descTokens.get(KEY_WORKING_HOURS);
|
||||
String price = descTokens.get(KEY_PRICE);
|
||||
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)) {
|
||||
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) {
|
||||
String s = mTokens.get(KEY_OTHER_DESCRIPTION);
|
||||
mTokens.put(KEY_OTHER_DESCRIPTION, s != null ? s + "\n" + token : token);
|
||||
String s = mTokens.get(KEY_DESCRIPTION);
|
||||
mTokens.put(KEY_DESCRIPTION, s != null ? s + "\n" + token : token);
|
||||
}
|
||||
}
|
||||
return mTokens;
|
||||
|
|
|
@ -1,41 +1,56 @@
|
|||
package net.osmand.plus.wikivoyage.menu;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
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.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController;
|
||||
import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
||||
|
||||
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);
|
||||
GPXUtilities.Metadata metadata = gpxFile != null ? gpxFile.metadata : null;
|
||||
final TravelArticle article = metadata != null ? getTravelArticle(metadata) : null;
|
||||
if (article != null) {
|
||||
|
||||
private WikivoyageWptPtMenuController(@NonNull MapActivity mapActivity, @NonNull PointDescription pointDescription, @NonNull WptPt wpt, @NonNull TravelArticle article) {
|
||||
super(new WikivoyageWptPtMenuBuilder(mapActivity, wpt), mapActivity, pointDescription, wpt);
|
||||
final long tripId = article.getTripId();
|
||||
final String lang = article.getLang();
|
||||
leftTitleButtonController = new TitleButtonController() {
|
||||
@Override
|
||||
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.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) {
|
||||
String title = metadata.getArticleTitle();
|
||||
String lang = metadata.getArticleLang();
|
||||
if (!TextUtils.isEmpty(title) && !TextUtils.isEmpty(lang)) {
|
||||
return getMapActivity().getMyApplication().getTravelDbHelper().getArticle(title, lang);
|
||||
public static WptPtMenuController getInstance(@NonNull MapActivity mapActivity, @NonNull PointDescription pointDescription, @NonNull WptPt wpt) {
|
||||
TravelArticle travelArticle = getTravelArticle(mapActivity, wpt);
|
||||
if (travelArticle != null) {
|
||||
return new WikivoyageWptPtMenuController(mapActivity, pointDescription, wpt, travelArticle);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue