From a6bc3b969195c6286d6c6554a9610c080b1a61f5 Mon Sep 17 00:00:00 2001 From: cepprice Date: Wed, 17 Mar 2021 18:00:00 +0500 Subject: [PATCH] Fix #11031 --- .../plus/track/GpxBlockStatisticsBuilder.java | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java index 09adb88117..b66877ab63 100644 --- a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java +++ b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java @@ -8,15 +8,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; -import androidx.annotation.ColorInt; -import androidx.annotation.ColorRes; -import androidx.annotation.DrawableRes; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.widget.AppCompatImageView; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - import net.osmand.AndroidUtils; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXTrackAnalysis; @@ -39,6 +30,15 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import androidx.annotation.ColorInt; +import androidx.annotation.ColorRes; +import androidx.annotation.DrawableRes; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatImageView; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + public class GpxBlockStatisticsBuilder { private static final Log log = PlatformUtil.getLog(GpxBlockStatisticsBuilder.class); @@ -116,12 +116,22 @@ public class GpxBlockStatisticsBuilder { public void initItems() { GPXFile gpxFile = getGPXFile(); - GpxDisplayItem gpxDisplayItem = getDisplayItem(gpxFile); + if (app == null || gpxFile == null) { + return; + } GPXTrackAnalysis analysis = null; boolean withoutGaps = true; - if (gpxDisplayItem != null) { - analysis = gpxDisplayItem.analysis; - withoutGaps = !selectedGpxFile.isJoinSegments() && gpxDisplayItem.isGeneralTrack(); + if (gpxFile.equals(app.getSavingTrackHelper().getCurrentGpx())) { + GPXFile currentGpx = app.getSavingTrackHelper().getCurrentTrack().getGpxFile(); + analysis = currentGpx.getAnalysis(0); + withoutGaps = !selectedGpxFile.isJoinSegments() + && (Algorithms.isEmpty(currentGpx.tracks) || currentGpx.tracks.get(0).generalTrack); + } else { + GpxDisplayItem gpxDisplayItem = getDisplayItem(gpxFile); + if (gpxDisplayItem != null) { + analysis = gpxDisplayItem.analysis; + withoutGaps = !selectedGpxFile.isJoinSegments() && gpxDisplayItem.isGeneralTrack(); + } } if (analysis != null) { float totalDistance = withoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;