diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxDbHelper.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxDbHelper.kt index ca7bfa10e7c..26034ae34c4 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxDbHelper.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxDbHelper.kt @@ -33,7 +33,6 @@ object GpxDbHelper : GpxReaderAdapter { private const val READER_TASKS_LIMIT = 4 private var readers = mutableListOf() private var readerSync = Synchronizable() - var readTrackItemCount: Long = 0 private var initialized: Boolean = false @@ -250,7 +249,6 @@ object GpxDbHelper : GpxReaderAdapter { } val item = dataItems[file] if (GpxDbUtils.isAnalyseNeeded(item)) { - readTrackItemCount++ readGpxItem(file, item, callback) } return item diff --git a/OsmAnd/test/java/net/osmand/test/activities/GPXTrackAnalysisUpdatesTest.java b/OsmAnd/test/java/net/osmand/test/activities/GPXTrackAnalysisUpdatesTest.java index c5c6a7b3c0a..f5dd4262835 100644 --- a/OsmAnd/test/java/net/osmand/test/activities/GPXTrackAnalysisUpdatesTest.java +++ b/OsmAnd/test/java/net/osmand/test/activities/GPXTrackAnalysisUpdatesTest.java @@ -22,8 +22,12 @@ import net.osmand.plus.track.helpers.GpxSelectionHelper; import net.osmand.plus.utils.OsmAndFormatter; import net.osmand.plus.views.OsmandMapTileView; +import net.osmand.shared.data.KQuadRect; +import net.osmand.shared.gpx.GpxDataItem; import net.osmand.shared.gpx.GpxDbHelper; +import net.osmand.shared.gpx.GpxDbHelper.GpxDataItemCallback; import net.osmand.shared.gpx.GpxFile; +import net.osmand.shared.gpx.GpxTrackAnalysis; import net.osmand.test.common.AndroidTest; import net.osmand.test.common.BaseIdlingResource; import net.osmand.test.common.ResourcesImporter; @@ -77,6 +81,12 @@ public void onGpxSaved(@Nullable String error, @NotNull GpxFile gpxFile) { file = new File(ImportHelper.getGpxDestinationDir(app, true), SELECTED_GPX_NAME); gpxFile.setPath(file.getAbsolutePath()); selectionHelper.selectGpxFile(gpxFile, GpxSelectionParams.getDefaultSelectionParams()); + + KQuadRect rect = gpxFile.getRect(); + if (rect.getLeft() != 0 && rect.getRight() != 0) { + app.getOsmandMap().getMapView().fitRectToMap(rect.getLeft(), rect.getRight(), + rect.getTop(), rect.getBottom(), (int) rect.width(), (int) rect.height(), 0); + } } } }); @@ -110,6 +120,8 @@ private class ObserveDistToFinishIdlingResource extends BaseIdlingResource { private static final int LOW_FPS_VALUE = 15; private static final int LOW_FPS_COUNT = 10; + private GpxTrackAnalysis analysis; + private int checksCounter; private int lowFpsCounter; @@ -124,7 +136,7 @@ private void startHandler() { checksCounter++; checkFPS(); - checkAnalysisUpdate(); + checkAnalysisUpdate(); // simulate multiple calls for getting GpxDataItem if (isIdleNow()) { notifyIdleTransition(); @@ -151,10 +163,21 @@ private void checkFPS() { } private void checkAnalysisUpdate() { - gpxDbHelper.getItem(SharedUtil.kFile(file)); // simulate multiple calls for getting GpxDataItem - long readItemCount = gpxDbHelper.getReadTrackItemCount(); - if (readItemCount > 2) { - throw new AssertionError("To many updates of analysis " + readItemCount); + GpxDataItem dataItem = gpxDbHelper.getItem(SharedUtil.kFile(file), new GpxDataItemCallback() { + @Override + public boolean isCancelled() { + return false; + } + + @Override + public void onGpxDataItemReady(@NotNull GpxDataItem item) { + if (analysis != item.getAnalysis()) { + throw new AssertionError("To many updates of analysis "); + } + } + }); + if (analysis == null && dataItem != null) { + analysis = dataItem.getAnalysis(); } }