Fixed route menu cards state. Dropped calling gpx database at gpx layer.
This commit is contained in:
parent
9260f6ee96
commit
e9eb1fd2a0
8 changed files with 62 additions and 24 deletions
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -498,6 +498,17 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
updateCards();
|
||||
}
|
||||
|
||||
private void applyCardsState(@NonNull List<BaseCard> newCards, @NonNull List<BaseCard> 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<BaseCard> 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() {
|
||||
|
|
|
@ -65,6 +65,10 @@ public abstract class BaseCard {
|
|||
}
|
||||
}
|
||||
|
||||
public void applyState(@NonNull BaseCard card) {
|
||||
// non implemented
|
||||
}
|
||||
|
||||
public CardListener getListener() {
|
||||
return listener;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<GpxDisplayGroup> 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<TrkSegment> segments = selectedGpxFile.getPointsToDisplay();
|
||||
for (TrkSegment ts : segments) {
|
||||
int color = gpxDataItem != null ? gpxDataItem.getColor() : 0;
|
||||
int color = selectedGpxFile.getGpxFile().getColor(0);
|
||||
if (currentTrack) {
|
||||
color = currentTrackColor;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue