Skip to content

Commit

Permalink
Only start positioning service timer if we're active
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jan 12, 2025
1 parent df2d9d9 commit 55e182d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
44 changes: 33 additions & 11 deletions src/service/qfieldpositioningservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,52 @@ QFieldPositioningService::QFieldPositioningService( int &argc, char **argv )
} );

connect( mPositioningSource, &PositioningSource::backgroundModeChanged, this, [=] {
if ( mPositioningSource->backgroundMode() && mPositioningSource->active() )
if ( mPositioningSource->active() )
{
triggerShowNotification();
mNotificationTimer.start();
if ( mPositioningSource->backgroundMode() )
{
triggerShowNotification();
mNotificationTimer.start();
}
else
{
mNotificationTimer.stop();
triggerReturnNotification();
}
}
} );

connect( mPositioningSource, &PositioningSource::activeChanged, this, [=] {
if ( mPositioningSource->active() )
{
if ( mPositioningSource->backgroundMode() )
{
triggerShowNotification();
mNotificationTimer.start();
}
}
else
{
mNotificationTimer.stop();
triggerCloseNotification();
}
} );
}
}

void QFieldPositioningService::triggerShowNotification()
{
const GnssPositionInformation pos = mPositioningSource->positionInformation();
QJniObject message = QJniObject::fromString( tr( "Latitude %1 | Longitude %2 | Altitude %3 | Orientation %4" ).arg( QLocale::system().toString( pos.latitude(), 'f', 7 ), QLocale::system().toString( pos.longitude(), 'f', 7 ), QLocale::system().toString( pos.elevation(), 'f', 3 ), QLocale::system().toString( mPositioningSource->orientation(), 'f', 1 ) ) );
QJniObject::callStaticMethod<void>( "ch/opengis/" APP_PACKAGE_NAME "/QFieldPositioningService",
"triggerShowNotification",
message.object<jstring>(),
true );
if ( mPositioningSource->positionInformation()->active() )
{
const GnssPositionInformation pos = mPositioningSource->positionInformation();
QJniObject message = QJniObject::fromString( tr( "Latitude %1 | Longitude %2 | Altitude %3 | Orientation %4" ).arg( QLocale::system().toString( pos.latitude(), 'f', 7 ), QLocale::system().toString( pos.longitude(), 'f', 7 ), QLocale::system().toString( pos.elevation(), 'f', 3 ), QLocale::system().toString( mPositioningSource->orientation(), 'f', 1 ) ) );
QJniObject::callStaticMethod<void>( "ch/opengis/" APP_PACKAGE_NAME "/QFieldPositioningService",
"triggerShowNotification",
message.object<jstring>(),
true );
}
}

void QFieldPositioningService::triggerCloseNotification()
void QFieldPositioningService::triggerReturnNotification()
{
QJniObject message = QJniObject::fromString( tr( "Positioning service running" ) );
QJniObject::callStaticMethod<void>( "ch/opengis/" APP_PACKAGE_NAME "/QFieldPositioningService",
Expand Down
2 changes: 1 addition & 1 deletion src/service/qfieldpositioningservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class QFIELD_SERVICE_EXPORT QFieldPositioningService : public QAndroidService

private slots:
void triggerShowNotification();
void triggerCloseNotification();
void triggerReturnNotification();

private:
PositioningSource *mPositioningSource = nullptr;
Expand Down

0 comments on commit 55e182d

Please sign in to comment.