From 26dde8c02b3d482128d5553b37acc6d8a4eda4bc Mon Sep 17 00:00:00 2001 From: Dave Craig Date: Mon, 19 Aug 2024 10:56:51 +0100 Subject: [PATCH] Use injected AudioEngine in Soundscape service We now have a Singleton AudioEngine that is managed by the dependency injection code. It is created if onboarding screens are run, and this change ensures that we use the same AudioEngine when the Soundscape service is run. --- .../soundscape/services/SoundscapeService.kt | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/scottishtecharmy/soundscape/services/SoundscapeService.kt b/app/src/main/java/org/scottishtecharmy/soundscape/services/SoundscapeService.kt index 46ff4ce1..d9e4212a 100644 --- a/app/src/main/java/org/scottishtecharmy/soundscape/services/SoundscapeService.kt +++ b/app/src/main/java/org/scottishtecharmy/soundscape/services/SoundscapeService.kt @@ -27,6 +27,7 @@ import com.google.android.gms.location.LocationRequest import com.google.android.gms.location.LocationResult import com.google.android.gms.location.LocationServices import com.google.android.gms.location.Priority +import dagger.hilt.android.AndroidEntryPoint import org.scottishtecharmy.soundscape.audio.NativeAudioEngine import org.scottishtecharmy.soundscape.R import org.scottishtecharmy.soundscape.activityrecognition.ActivityTransition @@ -53,11 +54,13 @@ import org.scottishtecharmy.soundscape.MainActivity import org.scottishtecharmy.soundscape.geojsonparser.geojson.LngLatAlt import retrofit2.awaitResponse import java.util.concurrent.Executors +import javax.inject.Inject import kotlin.time.Duration.Companion.seconds /** * Foreground service that provides location updates, device orientation updates, requests tiles, data persistence with realmDB. */ +@AndroidEntryPoint class SoundscapeService : Service() { private val binder = LocalBinder() @@ -74,7 +77,7 @@ class SoundscapeService : Service() { private var timerJob: Job? = null // Audio engine - private val audioEngine = NativeAudioEngine() + @Inject lateinit var audioEngine: NativeAudioEngine private var audioBeacon: Long = 0 // Flow to return beacon location @@ -146,13 +149,6 @@ class SoundscapeService : Service() { onSuccess = { }, onFailure = { }, ) - - - // Start secondary service - //startServiceRunningTicker() - - // Start audio engine - audioEngine.initialize(applicationContext) } override fun onDestroy() {