From 750986ad5732b958cb487e41513f2fe5b7b8cc2a Mon Sep 17 00:00:00 2001 From: Nazar Date: Wed, 20 Nov 2019 12:22:02 +0200 Subject: [PATCH] Fix #7501 --- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 6 +-- .../net/osmand/plus/GpxSelectionHelper.java | 47 +++++++++++-------- .../plus/activities/SavingTrackHelper.java | 6 +-- .../osmand/plus/activities/TrackActivity.java | 6 +-- .../net/osmand/plus/helpers/GpxUiHelper.java | 4 +- .../MeasurementToolFragment.java | 2 +- .../plus/myplaces/AvailableGPXFragment.java | 4 +- .../myplaces/SplitSegmentDialogFragment.java | 2 +- .../TrackActivityFragmentAdapter.java | 20 +++++++- .../plus/myplaces/TrackBitmapDrawer.java | 2 +- .../plus/myplaces/TrackSegmentFragment.java | 4 +- .../src/net/osmand/plus/views/GPXLayer.java | 2 +- 12 files changed, 67 insertions(+), 38 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index ca36576aa5..0a704b582b 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -1238,7 +1238,7 @@ public class OsmandAidlApi { @Override protected void onPostExecute(GPXFile gpx) { if (gpx.error == null) { - selectedGpx.setGpxFile(gpx); + selectedGpx.setGpxFile(gpx, app); refreshMap(); } } @@ -1417,7 +1417,7 @@ public class OsmandAidlApi { } long modifiedTime = gpxFile.modifiedTime; long fileSize = new File(gpxFile.path).length(); - files.add(new ASelectedGpxFile(path, modifiedTime, fileSize, createGpxFileDetails(selectedGpxFile.getTrackAnalysis()))); + files.add(new ASelectedGpxFile(path, modifiedTime, fileSize, createGpxFileDetails(selectedGpxFile.getTrackAnalysis(app)))); } } return true; @@ -1435,7 +1435,7 @@ public class OsmandAidlApi { } long modifiedTime = gpxFile.modifiedTime; long fileSize = new File(gpxFile.path).length(); - files.add(new net.osmand.aidlapi.gpx.ASelectedGpxFile(path, modifiedTime, fileSize, createGpxFileDetailsV2(selectedGpxFile.getTrackAnalysis()))); + files.add(new net.osmand.aidlapi.gpx.ASelectedGpxFile(path, modifiedTime, fileSize, createGpxFileDetailsV2(selectedGpxFile.getTrackAnalysis(app)))); } } return true; diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 876d2758c3..ba47591bc6 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -151,10 +151,13 @@ public class GpxSelectionHelper { return null; } - public void processSplit() { + public static boolean processSplit(OsmandApplication app) { + if (app == null || app.isApplicationInitializing()) { + return false; + } List items = app.getGpxDbHelper().getSplitItems(); for (GpxDataItem dataItem : items) { - SelectedGpxFile selectedGpxFile = getSelectedFileByPath(dataItem.getFile().getAbsolutePath()); + SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(dataItem.getFile().getAbsolutePath()); if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) { GPXFile gpxFile = selectedGpxFile.getGpxFile(); List groups = app.getSelectedGpxHelper().collectDisplayGroups(gpxFile); @@ -162,20 +165,21 @@ public class GpxSelectionHelper { for (GpxDisplayGroup model : groups) { model.noSplit(app); } - selectedGpxFile.setDisplayGroups(groups); + selectedGpxFile.setDisplayGroups(groups, app); } else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_DISTANCE) { for (GpxDisplayGroup model : groups) { model.splitByDistance(app, dataItem.getSplitInterval()); } - selectedGpxFile.setDisplayGroups(groups); + selectedGpxFile.setDisplayGroups(groups, app); } else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_TIME) { for (GpxDisplayGroup model : groups) { model.splitByTime(app, (int) dataItem.getSplitInterval()); } - selectedGpxFile.setDisplayGroups(groups); + selectedGpxFile.setDisplayGroups(groups, app); } } } + return true; } private String getString(int resId, Object... formatArgs) { @@ -508,6 +512,7 @@ public class GpxSelectionHelper { } else { selectGpxFile(gpx, true, false, true, selectedByUser, false); } + gpx.addGeneralTrack(); } else if (obj.has(CURRENT_TRACK)) { SelectedGpxFile file = savingTrackHelper.getCurrentTrack(); file.selectedByUser = selectedByUser; @@ -516,7 +521,6 @@ public class GpxSelectionHelper { selectedGPXFiles = newSelectedGPXFiles; } } - processSplit(); if (save) { saveCurrentSelections(); } @@ -589,7 +593,7 @@ public class GpxSelectionHelper { if (dataItem != null && dataItem.getColor() != 0) { gpx.setColor(dataItem.getColor()); } - sf.setGpxFile(gpx); + sf.setGpxFile(gpx, app); sf.notShowNavigationDialog = notShowNavigationDialog; sf.selectedByUser = selectedByUser; } @@ -606,6 +610,9 @@ public class GpxSelectionHelper { if (syncGroup) { syncGpxWithMarkers(gpx); } + if (sf != null) { + sf.splitProcessed = false; + } return sf; } @@ -667,36 +674,38 @@ public class GpxSelectionHelper { private int color; private GPXTrackAnalysis trackAnalysis; private long modifiedTime = -1; + private boolean splitProcessed = false; private List processedPointsToDisplay = new ArrayList<>(); private boolean routePoints; private List displayGroups; - public void setGpxFile(GPXFile gpxFile) { + public void setGpxFile(GPXFile gpxFile, OsmandApplication app) { this.gpxFile = gpxFile; if (gpxFile.tracks.size() > 0) { this.color = gpxFile.tracks.get(0).getColor(0); } - processPoints(); + processPoints(app); } - public GPXTrackAnalysis getTrackAnalysis() { + public GPXTrackAnalysis getTrackAnalysis(OsmandApplication app) { if (modifiedTime != gpxFile.modifiedTime) { - update(); + update(app); } return trackAnalysis; } - private void update() { + private void update(OsmandApplication app) { modifiedTime = gpxFile.modifiedTime; trackAnalysis = gpxFile.getAnalysis( Algorithms.isEmpty(gpxFile.path) ? System.currentTimeMillis() : new File(gpxFile.path).lastModified()); displayGroups = null; + splitProcessed = GpxSelectionHelper.processSplit(app); } - public void processPoints() { - update(); + public void processPoints(OsmandApplication app) { + update(app); this.processedPointsToDisplay = gpxFile.proccessPoints(); if (this.processedPointsToDisplay.isEmpty()) { this.processedPointsToDisplay = gpxFile.processRoutePoints(); @@ -737,16 +746,16 @@ public class GpxSelectionHelper { return color; } - public List getDisplayGroups() { - if (modifiedTime != gpxFile.modifiedTime) { - update(); + public List getDisplayGroups(OsmandApplication app) { + if (modifiedTime != gpxFile.modifiedTime || !splitProcessed) { + update(app); } return displayGroups; } - public void setDisplayGroups(List displayGroups) { + public void setDisplayGroups(List displayGroups, OsmandApplication app) { if (modifiedTime != gpxFile.modifiedTime) { - update(); + update(app); } this.displayGroups = displayGroups; } diff --git a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java index 45596f8607..c0687b6fe9 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java @@ -78,7 +78,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { this.currentTrack.setShowCurrentTrack(true); GPXFile gx = new GPXFile(Version.getFullVersion(ctx)); gx.showCurrentTrack = true; - this.currentTrack.setGpxFile(gx); + this.currentTrack.setGpxFile(gx, ctx); prepareCurrentTrackForRecording(); updateScript = "INSERT INTO " + TRACK_NAME + " (" + TRACK_COL_LAT + ", " + TRACK_COL_LON + ", " @@ -482,7 +482,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { lt.points.add(pt); } if (segmentAdded) { - currentTrack.processPoints(); + currentTrack.processPoints(ctx); } currentTrack.getModifiableGpxFile().modifiedTime = time; } @@ -629,7 +629,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { ctx.getSelectedGpxHelper().addPoints(entry.getValue().getPoints(), currentTrack.getModifiableGpxFile()); currentTrack.getModifiableGpxFile().tracks.addAll(entry.getValue().tracks); } - currentTrack.processPoints(); + currentTrack.processPoints(ctx); prepareCurrentTrackForRecording(); GPXTrackAnalysis analysis = currentTrack.getModifiableGpxFile().getAnalysis(System.currentTimeMillis()); distance = analysis.totalDistance; diff --git a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java index fd63e7fb86..974ab4b786 100644 --- a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java @@ -189,8 +189,8 @@ public class TrackActivity extends TabActivity { } if (file != null) { SelectedGpxFile sf = selectedGpxHelper.getSelectedFileByPath(gpxFile.path); - if (sf != null && file != null && sf.getDisplayGroups() != null) { - displayGroups = sf.getDisplayGroups(); + if (sf != null && file != null && sf.getDisplayGroups(app) != null) { + displayGroups = sf.getDisplayGroups(app); } } } @@ -479,7 +479,7 @@ public class TrackActivity extends TabActivity { } else { final SelectedGpxFile selectedGpx = helper.getSelectedFileByPath(result.path); if (selectedGpx != null && result.error == null) { - selectedGpx.setGpxFile(result); + selectedGpx.setGpxFile(result, app); } } } diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index da652ba975..be8fbe0a6c 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -796,7 +796,7 @@ public class GpxUiHelper { GPXTrackAnalysis analysis = null; if (currentlyRecordingTrack) { - analysis = app.getSavingTrackHelper().getCurrentTrack().getTrackAnalysis(); + analysis = app.getSavingTrackHelper().getCurrentTrack().getTrackAnalysis(app); } else if (dataItem != null) { analysis = dataItem.getAnalysis(); } @@ -1025,6 +1025,8 @@ public class GpxUiHelper { GPXFile res = GPXUtilities.loadGPXFile(f); if (res.error != null && !Algorithms.isEmpty(res.error.getMessage())) { w += res.error.getMessage() + "\n"; + } else { + res.addGeneralTrack(); } result[k++] = res; } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 060ce8697c..c1fe3d0ed2 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -1349,7 +1349,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { SelectedGpxFile sf = activity.getMyApplication().getSelectedGpxHelper().selectGpxFile(gpx, true, false); if (sf != null) { if (actionType == NewGpxData.ActionType.ADD_SEGMENT || actionType == NewGpxData.ActionType.EDIT_SEGMENT) { - sf.processPoints(); + sf.processPoints(getMyApplication()); } } } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index a8452edd9e..67204bbf5c 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -1867,9 +1867,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement SelectedGpxFile sgpx = getSelectedGpxFile(gpxInfo, app); GPXTrackAnalysis analysis = null; if (sgpx != null) { - analysis = sgpx.getTrackAnalysis(); + analysis = sgpx.getTrackAnalysis(app); } else if (gpxInfo.currentlyRecordingTrack) { - analysis = app.getSavingTrackHelper().getCurrentTrack().getTrackAnalysis(); + analysis = app.getSavingTrackHelper().getCurrentTrack().getTrackAnalysis(app); } else if (gpxInfo.file != null) { GpxDataItemCallback analyserCallback = null; if (callback != null) { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/SplitSegmentDialogFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/SplitSegmentDialogFragment.java index dfd78f2adf..37e4e6a904 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/SplitSegmentDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/SplitSegmentDialogFragment.java @@ -695,7 +695,7 @@ public class SplitSegmentDialogFragment extends DialogFragment { progressBar.setVisibility(View.GONE); if (mSelectedGpxFile != null) { List groups = getDisplayGroups(); - mSelectedGpxFile.setDisplayGroups(groups); + mSelectedGpxFile.setDisplayGroups(groups, app); } updateContent(); } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java index bb3fa65179..cb255cb162 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java @@ -720,12 +720,30 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { private void updateSplitIntervalView(View view) { final TextView text = (TextView) view.findViewById(R.id.split_interval_text); + selectedSplitInterval = getSelectedSplitInterval(); if (selectedSplitInterval == 0) { text.setText(app.getString(R.string.shared_string_none)); } else { text.setText(options.get(selectedSplitInterval)); } } + + private int getSelectedSplitInterval() { + if (getGpxDataItem() == null) { + return 0; + } + int splitType = getGpxDataItem().getSplitType(); + double splitInterval = getGpxDataItem().getSplitInterval(); + int position = 0; + + if (splitType == GPXDatabase.GPX_SPLIT_TYPE_DISTANCE) { + position = distanceSplit.indexOf(splitInterval); + } else if (splitType == GPXDatabase.GPX_SPLIT_TYPE_TIME) { + position = timeSplit.indexOf((int) splitInterval); + } + + return position > 0 ? position : 0; + } private void updateColorView(View colorView) { final ImageView colorImageView = (ImageView) colorView.findViewById(R.id.colorImage); @@ -1008,7 +1026,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { } if (selectedGpx != null) { List groups = fragment.getDisplayGroups(); - selectedGpx.setDisplayGroups(groups); + selectedGpx.setDisplayGroups(groups, app); } /* if (fragment.isVisible()) { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java index 0f803f960f..3d03360b1c 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java @@ -206,7 +206,7 @@ public class TrackBitmapDrawer { sf = app.getSavingTrackHelper().getCurrentTrack(); } else { sf = new GpxSelectionHelper.SelectedGpxFile(); - sf.setGpxFile(gpxFile); + sf.setGpxFile(gpxFile, app); } Bitmap bmp = mapBitmap.copy(mapBitmap.getConfig(), true); Canvas canvas = new Canvas(bmp); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java index d0c48c3eb4..07003dc819 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java @@ -1294,8 +1294,8 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit if (selectedGpx != null) { List groups = fragment.getDisplayGroups(); if (groups != null) { - selectedGpx.setDisplayGroups(groups); - selectedGpx.processPoints(); + selectedGpx.setDisplayGroups(groups, app); + selectedGpx.processPoints(app); } } fragment.updateContent(); diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index ef8ee27e83..2796f5132c 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -289,7 +289,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex if (tileBox.getZoom() >= startZoom) { // request to load for (SelectedGpxFile g : selectedGPXFiles) { - List groups = g.getDisplayGroups(); + List groups = g.getDisplayGroups(view.getApplication()); if (groups != null && !groups.isEmpty()) { int color = g.getGpxFile().getColor(0); if (color == 0) {