From 508bc191bea7ec1d6749fe9748fcb24bbc0e48b8 Mon Sep 17 00:00:00 2001
From: Zohaib Kambrani <>
Date: Sun, 20 Dec 2020 13:44:29 +0300
Subject: [PATCH] geofencing login check fix
---
android/app/src/main/AndroidManifest.xml | 2 +-
.../geofence/GeoZoneModel.kt | 2 +
.../geofence/GeofenceBroadcastReceiver.kt | 17 +++++++-
.../GeofenceBroadcastReceiverWithService.kt | 13 ++++++
.../GeofenceTransitionsJobIntentService.kt | 37 +++--------------
.../GeofencingRebootBroadcastReceiver.kt | 3 +-
.../geofence/HMG_Geofence.kt | 41 ++++++++++++++++++-
.../diplomaticquarterapp/utils/HMGUtils.kt | 35 ++++++++++++++--
ios/Runner/AppDelegate.swift | 22 ----------
ios/Runner/Helper/Extensions.swift | 10 +++++
ios/Runner/Helper/GlobalHelper.swift | 30 +++++++++++++-
ios/Runner/Helper/HMG_Geofence.swift | 14 ++++---
lib/pages/landing/landing_page.dart | 30 ++++++--------
13 files changed, 169 insertions(+), 87 deletions(-)
create mode 100644 android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/GeofenceBroadcastReceiverWithService.kt
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 1032b29b..c114b44d 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -80,7 +80,7 @@
-
+
diff --git a/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/GeoZoneModel.kt b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/GeoZoneModel.kt
index 7eba1ead..328014e6 100644
--- a/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/GeoZoneModel.kt
+++ b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/GeoZoneModel.kt
@@ -37,6 +37,7 @@ class GeoZoneModel {
val rad = Radius.toFloat()
if(lat != null && long != null){
+ val loiteringDelayMinutes:Int = 5 // in Minutes
return Geofence.Builder()
.setRequestId(identifier())
.setCircularRegion(
@@ -46,6 +47,7 @@ class GeoZoneModel {
)
.setTransitionTypes(GeofenceTransition.ENTER_EXIT.value)
// .setNotificationResponsiveness(0)
+// .setLoiteringDelay(loiteringDelayMinutes * 60 * 1000)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.build()
}
diff --git a/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/GeofenceBroadcastReceiver.kt b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/GeofenceBroadcastReceiver.kt
index 8fc1faae..f8a861bb 100644
--- a/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/GeofenceBroadcastReceiver.kt
+++ b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/GeofenceBroadcastReceiver.kt
@@ -5,9 +5,24 @@ package com.cloud.diplomaticquarterapp.geofence
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
+import android.util.Log
+import com.cloud.diplomaticquarterapp.utils.saveLog
+import com.google.android.gms.location.GeofencingEvent
class GeofenceBroadcastReceiver : BroadcastReceiver() {
+ private val LOG_TAG = "GeofenceBroadcastReceiver"
override fun onReceive(context: Context, intent: Intent) {
- GeofenceTransitionsJobIntentService.enqueueWork(context, intent)
+
+ val geofencingEvent = GeofencingEvent.fromIntent(intent)
+ if (geofencingEvent.hasError()) {
+ val errorMessage = GeofenceErrorMessages.getErrorString(context, geofencingEvent.errorCode)
+ Log.e(LOG_TAG, errorMessage)
+ saveLog(context,LOG_TAG,errorMessage)
+ return
+ }
+
+ HMG_Geofence.shared(context).handleEvent(geofencingEvent.triggeringGeofences,geofencingEvent.triggeringLocation, GeofenceTransition.fromInt(geofencingEvent.geofenceTransition));
+
}
+
}
\ No newline at end of file
diff --git a/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/GeofenceBroadcastReceiverWithService.kt b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/GeofenceBroadcastReceiverWithService.kt
new file mode 100644
index 00000000..0332f745
--- /dev/null
+++ b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/GeofenceBroadcastReceiverWithService.kt
@@ -0,0 +1,13 @@
+
+
+package com.cloud.diplomaticquarterapp.geofence
+
+import android.content.BroadcastReceiver
+import android.content.Context
+import android.content.Intent
+
+class GeofenceBroadcastReceiverWithService : BroadcastReceiver() {
+ override fun onReceive(context: Context, intent: Intent) {
+ GeofenceTransitionsJobIntentService.enqueueWork(context, intent)
+ }
+}
\ No newline at end of file
diff --git a/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/GeofenceTransitionsJobIntentService.kt b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/GeofenceTransitionsJobIntentService.kt
index f28e1720..18ee92d9 100755
--- a/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/GeofenceTransitionsJobIntentService.kt
+++ b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/GeofenceTransitionsJobIntentService.kt
@@ -52,8 +52,9 @@ class GeofenceTransitionsJobIntentService : JobIntentService() {
private const val LOG_TAG = "GeoTrIntentService"
private const val JOB_ID = 573
-
+ var context_: Context? = null
fun enqueueWork(context: Context, intent: Intent) {
+ context_ = context
enqueueWork(
context,
GeofenceTransitionsJobIntentService::class.java, JOB_ID,
@@ -70,37 +71,9 @@ class GeofenceTransitionsJobIntentService : JobIntentService() {
}
if (geofencingEvent.geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geofencingEvent.geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
- handleEvent(geofencingEvent.triggeringGeofences,geofencingEvent.triggeringLocation, GeofenceTransition.fromInt(geofencingEvent.geofenceTransition));
- }
- }
-
- private fun handleEvent(triggerGeofences: List, location:Location, transition:GeofenceTransition) {
- val hmg = HMG_Geofence.shared(this)
- hmg.getPatientID()?.let { patientId ->
-
- hmg.getActiveGeofences({ activeGeofences ->
-
- triggerGeofences.forEach { geofence ->
- // Extract PointID from 'geofence.requestId' and find from active geofences
- val pointID = activeGeofences.firstOrNull {it == geofence.requestId}?.split('_')?.first()
- if(!pointID.isNullOrEmpty() && pointID.toIntOrNull() != null){
-
- val body = mapOf(
- "PointsID" to pointID.toIntOrNull(),
- "GeoType" to transition.value,
- "PatientID" to patientId
- )
-
- httpPost