Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/Helpers/OAGPXUIHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *) getDescription:(OASGpxDataItem *)gpx;

+ (long) getSegmentTime:(OASTrkSegment *)segment;
+ (long)liveTimeSpanForGpx:(OASGpxFile *)gpx withoutGaps:(BOOL)withoutGaps;
+ (double) getSegmentDistance:(OASTrkSegment *)segment;

+ (NSArray<OAGpxFileInfo *> *) getSortedGPXFilesInfo:(nullable NSString *)dir
Expand Down
28 changes: 28 additions & 0 deletions Sources/Helpers/OAGPXUIHelper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,34 @@ + (long)getSegmentTime:(OASTrkSegment *)segment
return endTime - startTime;
}

+ (long)liveTimeSpanForGpx:(OASGpxFile *)gpx withoutGaps:(BOOL)withoutGaps
{
long totalActiveDuration = 0;
long earliestSegmentStart = LONG_MAX;
long latestSegmentEnd = 0;
for (OASTrack *track in gpx.tracks)
{
for (OASTrkSegment *segment in track.segments)
{
NSArray<OASWptPt *> *points = segment.points;
if (points.count < 2)
continue;

long segmentDuration = [self getSegmentTime:segment];
totalActiveDuration += segmentDuration;
long segmentStartTime = ((OASWptPt *)points.firstObject).time;
long segmentEndTime = ((OASWptPt *)points.lastObject).time;
earliestSegmentStart = MIN(earliestSegmentStart, segmentStartTime);
latestSegmentEnd = MAX(latestSegmentEnd, segmentEndTime);
}
}

if (earliestSegmentStart == LONG_MAX)
return 0;

return withoutGaps ? totalActiveDuration : (latestSegmentEnd - earliestSegmentStart);
}

+ (double) getSegmentDistance:(OASTrkSegment *)segment
{
double distance = 0;
Expand Down
7 changes: 2 additions & 5 deletions Sources/Plugins/Monitoring/OATripRecordingTimeWidget.mm
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ - (instancetype)initWithСustomId:(NSString *)customId

[weakSelf setIcon:@"widget_track_recording_duration"];
OASGpxFile *currentTrack = [OASavingTrackHelper sharedInstance].currentTrack;
BOOL withoutGaps = ![[OAAppSettings sharedManager].currentTrackIsJoinSegments get] &&
((!currentTrack.tracks || currentTrack.tracks.count == 0) || currentTrack.tracks[0].generalTrack);

OASGpxTrackAnalysis *analysis = [currentTrack getAnalysisFileTimestamp:0];
long timeSpan = withoutGaps ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we have same code in java (android). Why it works correctly in android and wrong in ios?

BOOL withoutGaps = ![[OAAppSettings sharedManager].currentTrackIsJoinSegments get];
long timeSpan = [OAGPXUIHelper liveTimeSpanForGpx:currentTrack withoutGaps:withoutGaps];

if (cachedTimeSpan != timeSpan)
{
Expand Down