From 55e182d64d295cb0d42d5d75ae207b8d99cc518a Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Sun, 29 Dec 2024 16:48:06 +0700 Subject: [PATCH] Only start positioning service timer if we're active --- src/service/qfieldpositioningservice.cpp | 44 ++++++++++++++++++------ src/service/qfieldpositioningservice.h | 2 +- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/service/qfieldpositioningservice.cpp b/src/service/qfieldpositioningservice.cpp index d67e72ad6a..29fd0dfa3c 100644 --- a/src/service/qfieldpositioningservice.cpp +++ b/src/service/qfieldpositioningservice.cpp @@ -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( "ch/opengis/" APP_PACKAGE_NAME "/QFieldPositioningService", - "triggerShowNotification", - message.object(), - 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( "ch/opengis/" APP_PACKAGE_NAME "/QFieldPositioningService", + "triggerShowNotification", + message.object(), + true ); + } } -void QFieldPositioningService::triggerCloseNotification() +void QFieldPositioningService::triggerReturnNotification() { QJniObject message = QJniObject::fromString( tr( "Positioning service running" ) ); QJniObject::callStaticMethod( "ch/opengis/" APP_PACKAGE_NAME "/QFieldPositioningService", diff --git a/src/service/qfieldpositioningservice.h b/src/service/qfieldpositioningservice.h index d0fd83cc9f..b863a3b150 100644 --- a/src/service/qfieldpositioningservice.h +++ b/src/service/qfieldpositioningservice.h @@ -36,7 +36,7 @@ class QFIELD_SERVICE_EXPORT QFieldPositioningService : public QAndroidService private slots: void triggerShowNotification(); - void triggerCloseNotification(); + void triggerReturnNotification(); private: PositioningSource *mPositioningSource = nullptr;