From e9eb1fd2a01038013b3243d026e75046342b8273 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Mon, 14 Oct 2019 18:32:28 +0300 Subject: [PATCH] Fixed route menu cards state. Dropped calling gpx database at gpx layer. --- OsmAnd/src/net/osmand/plus/GPXDatabase.java | 5 ++++- .../net/osmand/plus/GpxSelectionHelper.java | 19 ++++++++++--------- .../MapRouteInfoMenu.java | 16 +++++++++++++++- .../routepreparationmenu/cards/BaseCard.java | 4 ++++ .../cards/HistoryCard.java | 9 +++++++++ .../cards/MapMarkersCard.java | 8 ++++++++ .../cards/TracksCard.java | 9 +++++++++ .../src/net/osmand/plus/views/GPXLayer.java | 16 +++------------- 8 files changed, 62 insertions(+), 24 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index e4a4f20692..9673b186cc 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -473,8 +473,11 @@ public class GPXDatabase { } public boolean updateAnalysis(GpxDataItem item, GPXTrackAnalysis a) { + if (a == null) { + return false; + } SQLiteConnection db = openConnection(false); - if (db != null && a != null) { + if (db != null) { try { String fileName = getFileName(item.file); String fileDir = getFileDir(item.file); diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 78ac863c0b..22d214b7bd 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -572,7 +572,7 @@ public class GpxSelectionHelper { app.getSettings().SELECTED_GPX.set(ar.toString()); } - private SelectedGpxFile selectGpxFileImpl(GPXFile gpx, boolean show, boolean notShowNavigationDialog, boolean syncGroup, boolean selectedByUser) { + private SelectedGpxFile selectGpxFileImpl(GPXFile gpx, GpxDataItem dataItem, boolean show, boolean notShowNavigationDialog, boolean syncGroup, boolean selectedByUser) { boolean displayed; SelectedGpxFile sf; if (gpx != null && gpx.showCurrentTrack) { @@ -588,6 +588,9 @@ public class GpxSelectionHelper { displayed = sf != null; if (show && sf == null) { sf = new SelectedGpxFile(); + if (dataItem != null && dataItem.getColor() != 0) { + gpx.setColor(dataItem.getColor()); + } sf.setGpxFile(gpx); sf.notShowNavigationDialog = notShowNavigationDialog; sf.selectedByUser = selectedByUser; @@ -612,20 +615,18 @@ public class GpxSelectionHelper { return selectGpxFile(gpx, show, notShowNavigationDialog, true, true, true); } - public SelectedGpxFile selectGpxFile(GPXFile gpx, boolean show, boolean notShowNavigationDialog, boolean syncGroup, boolean selectedByUser) { - SelectedGpxFile sf = selectGpxFileImpl(gpx, show, notShowNavigationDialog, syncGroup, selectedByUser); + public SelectedGpxFile selectGpxFile(GPXFile gpx, GpxDataItem dataItem, boolean show, boolean notShowNavigationDialog, boolean syncGroup, boolean selectedByUser) { + SelectedGpxFile sf = selectGpxFileImpl(gpx, dataItem, show, notShowNavigationDialog, syncGroup, selectedByUser); saveCurrentSelections(); return sf; } public SelectedGpxFile selectGpxFile(GPXFile gpx, boolean show, boolean notShowNavigationDialog, boolean syncGroup, boolean selectedByUser, boolean canAddToMarkers) { - if (canAddToMarkers && show) { - GPXDatabase.GpxDataItem dataItem = app.getGpxDatabase().getItem(new File(gpx.path)); - if (dataItem != null && dataItem.isShowAsMarkers()) { - app.getMapMarkersHelper().addOrEnableGroup(gpx); - } + GpxDataItem dataItem = app.getGpxDatabase().getItem(new File(gpx.path)); + if (canAddToMarkers && show && dataItem != null && dataItem.isShowAsMarkers()) { + app.getMapMarkersHelper().addOrEnableGroup(gpx); } - return selectGpxFile(gpx, show, notShowNavigationDialog, syncGroup, selectedByUser); + return selectGpxFile(gpx, dataItem, show, notShowNavigationDialog, syncGroup, selectedByUser); } public void clearPoints(GPXFile gpxFile) { diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index b4923d3e39..095394e5b4 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -498,6 +498,17 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener updateCards(); } + private void applyCardsState(@NonNull List newCards, @NonNull List prevCards) { + for (BaseCard newCard : newCards) { + for (BaseCard prevCard : prevCards) { + if (newCard.getClass() == prevCard.getClass()) { + newCard.applyState(prevCard); + break; + } + } + } + } + private void updateCards() { MapActivity mapActivity = getMapActivity(); if (mapActivity == null) { @@ -510,7 +521,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper(); RoutingHelper routingHelper = app.getRoutingHelper(); - menuCards.clear(); + List menuCards = new ArrayList<>(); boolean bottomShadowVisible = true; if (isBasicRouteCalculated()) { @@ -646,6 +657,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener } } } + applyCardsState(menuCards, this.menuCards); + this.menuCards = menuCards; setBottomShadowVisible(bottomShadowVisible); setupCards(); } @@ -2188,6 +2201,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener app.getRoutingHelper().removeListener(this); } removeTargetPointListener(); + menuCards = new ArrayList<>(); } public boolean needShowMenu() { diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/BaseCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/BaseCard.java index 1277d09746..2665610a8b 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/BaseCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/BaseCard.java @@ -65,6 +65,10 @@ public abstract class BaseCard { } } + public void applyState(@NonNull BaseCard card) { + // non implemented + } + public CardListener getListener() { return listener; } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HistoryCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HistoryCard.java index 77757d849b..94d4cad622 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HistoryCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HistoryCard.java @@ -2,6 +2,7 @@ package net.osmand.plus.routepreparationmenu.cards; import android.annotation.SuppressLint; import android.graphics.drawable.Drawable; +import android.support.annotation.NonNull; import android.support.v7.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; @@ -126,4 +127,12 @@ public class HistoryCard extends BaseCard { ((TextView) view.findViewById(R.id.gpx_card_title)).setText(R.string.shared_string_history); } + + @Override + public void applyState(@NonNull BaseCard card) { + super.applyState(card); + if (card instanceof HistoryCard) { + limit = ((HistoryCard) card).limit; + } + } } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/MapMarkersCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/MapMarkersCard.java index 530c06c043..62727168b0 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/MapMarkersCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/MapMarkersCard.java @@ -142,4 +142,12 @@ public class MapMarkersCard extends BaseCard { ((TextView) view.findViewById(R.id.gpx_card_title)).setText(R.string.map_markers); } + + @Override + public void applyState(@NonNull BaseCard card) { + super.applyState(card); + if (card instanceof MapMarkersCard) { + showLimited = ((MapMarkersCard) card).showLimited; + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksCard.java index 3022cbf7c5..40b9d5ff9a 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksCard.java @@ -1,6 +1,7 @@ package net.osmand.plus.routepreparationmenu.cards; import android.annotation.SuppressLint; +import android.support.annotation.NonNull; import android.support.v4.content.ContextCompat; import android.support.v7.view.ContextThemeWrapper; import android.view.LayoutInflater; @@ -148,4 +149,12 @@ public class TracksCard extends BaseCard { ((TextView) view.findViewById(R.id.gpx_card_title)).setText( String.format("%s (%d)", app.getString(R.string.tracks_on_map), list.size())); } + + @Override + public void applyState(@NonNull BaseCard card) { + super.applyState(card); + if (card instanceof TracksCard) { + showLimited = ((TracksCard) card).showLimited; + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 8cf1b8182d..ef8ee27e83 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -30,7 +30,6 @@ import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; import net.osmand.data.QuadTree; import net.osmand.data.RotatedTileBox; -import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; @@ -292,8 +291,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex for (SelectedGpxFile g : selectedGPXFiles) { List groups = g.getDisplayGroups(); if (groups != null && !groups.isEmpty()) { - GpxDataItem gpxDataItem = view.getApplication().getGpxDatabase().getItem(new File(g.getGpxFile().path)); - int color = gpxDataItem != null ? gpxDataItem.getColor() : 0; + int color = g.getGpxFile().getColor(0); if (color == 0) { color = g.getModifiableGpxFile().getColor(0); } @@ -437,11 +435,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex private void drawXAxisPoints(Canvas canvas, RotatedTileBox tileBox) { int color = trackChartPoints.getSegmentColor(); if (color == 0) { - GpxDataItem gpxDataItem = null; - if (!trackChartPoints.getGpx().showCurrentTrack) { - gpxDataItem = view.getApplication().getGpxDatabase().getItem(new File(trackChartPoints.getGpx().path)); - } - color = gpxDataItem != null ? gpxDataItem.getColor() : 0; + color = trackChartPoints.getGpx().getColor(0); if (trackChartPoints.getGpx().showCurrentTrack) { color = currentTrackColor; } @@ -522,13 +516,9 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex private void drawSelectedFileSegments(SelectedGpxFile selectedGpxFile, boolean currentTrack, Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { - GpxDataItem gpxDataItem = null; - if (!currentTrack) { - gpxDataItem = view.getApplication().getGpxDatabase().getItem(new File(selectedGpxFile.getGpxFile().path)); - } List segments = selectedGpxFile.getPointsToDisplay(); for (TrkSegment ts : segments) { - int color = gpxDataItem != null ? gpxDataItem.getColor() : 0; + int color = selectedGpxFile.getGpxFile().getColor(0); if (currentTrack) { color = currentTrackColor; }