diff --git a/sdk/src/androidTest/java/network/xyo/client/LocationWitnessTest.kt b/sdk/src/androidTest/java/network/xyo/client/LocationWitnessTest.kt index e4dbe5e..654db9d 100644 --- a/sdk/src/androidTest/java/network/xyo/client/LocationWitnessTest.kt +++ b/sdk/src/androidTest/java/network/xyo/client/LocationWitnessTest.kt @@ -5,6 +5,9 @@ import android.content.Context import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.rule.GrantPermissionRule +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import network.xyo.client.witness.location.info.LocationActivity import network.xyo.client.witness.location.info.XyoLocationPayload import network.xyo.client.witness.location.info.XyoLocationWitness @@ -26,13 +29,15 @@ class LocationWitnessTest { // Get the application context val context = ApplicationProvider.getApplicationContext() - val witness = XyoLocationWitness() - val payload = witness.observe(context) + CoroutineScope(Dispatchers.Main).launch { + val witness = XyoLocationWitness() + val payload = witness.observe(context) - assertInstanceOf(payload) - assert(payload.schema == "network.xyo.location.android") - assert((payload.currentLocation) !== null) - assert(payload.currentLocation?.coords?.latitude !== null) - assert(payload.currentLocation?.coords?.longitude !== null) + assertInstanceOf(payload) + assert(payload.schema == "network.xyo.location.android") + assert((payload.currentLocation) !== null) + assert(payload.currentLocation?.coords?.latitude !== null) + assert(payload.currentLocation?.coords?.longitude !== null) + } } } \ No newline at end of file diff --git a/sdk/src/main/java/network/xyo/client/witness/location/info/XyoLocationPayload.kt b/sdk/src/main/java/network/xyo/client/witness/location/info/XyoLocationPayload.kt index 9f4d0a1..968acd7 100644 --- a/sdk/src/main/java/network/xyo/client/witness/location/info/XyoLocationPayload.kt +++ b/sdk/src/main/java/network/xyo/client/witness/location/info/XyoLocationPayload.kt @@ -33,7 +33,7 @@ class XyoLocationPayload ( companion object { @SuppressLint("MissingPermission") - fun detect(context: Context): XyoLocationPayload? { + suspend fun detect(context: Context): XyoLocationPayload? { return XyoLocationPayload( XyoLocationCurrent.detect(context) ) diff --git a/sdk/src/main/java/network/xyo/client/witness/location/info/XyoLocationWitness.kt b/sdk/src/main/java/network/xyo/client/witness/location/info/XyoLocationWitness.kt index c57c7b1..b07f5bf 100644 --- a/sdk/src/main/java/network/xyo/client/witness/location/info/XyoLocationWitness.kt +++ b/sdk/src/main/java/network/xyo/client/witness/location/info/XyoLocationWitness.kt @@ -3,13 +3,22 @@ package network.xyo.client.witness.location.info import android.content.Context import android.os.Build import androidx.annotation.RequiresApi +import network.xyo.client.DeferredObserver import network.xyo.client.XyoWitness import network.xyo.client.address.XyoAccount +class DeferredLocationObserver : DeferredObserver() { + override suspend fun deferredDetect( + context: Context, + previousHash: String? + ): XyoLocationPayload? { + return XyoLocationPayload.detect(context) + } +} @RequiresApi(Build.VERSION_CODES.M) class XyoLocationWitness(address: XyoAccount = XyoAccount()) : XyoWitness( - address, - fun (context: Context, _: String?): XyoLocationPayload? { - return XyoLocationPayload.detect(context) - }) \ No newline at end of file + DeferredLocationObserver(), + "", + address + ) \ No newline at end of file