diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 649af435..79bc3dc4 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -81,6 +81,7 @@
+
@@ -88,6 +89,8 @@
+
+
diff --git a/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/MainActivity.kt b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/MainActivity.kt
index 8b73b0c7..e67f646f 100644
--- a/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/MainActivity.kt
+++ b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/MainActivity.kt
@@ -2,8 +2,7 @@ package com.cloud.diplomaticquarterapp
import android.os.Bundle
import android.util.Log
import androidx.annotation.NonNull;
-import com.cloud.diplomaticquarterapp.utils.FlutterText
-import com.cloud.diplomaticquarterapp.utils.PlatformBridge
+import com.cloud.diplomaticquarterapp.utils.*
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
@@ -15,6 +14,16 @@ class MainActivity: FlutterFragmentActivity() {
// Create Flutter Platform Bridge
PlatformBridge(flutterEngine.dartExecutor.binaryMessenger, this).create()
+ val time = timeToMillis("04:00:00", "HH:mm:ss")
+ print(time)
+
+// val d1 = Logs.list(this)
+// val d2 = Logs.raw(this)
+// val d3 = Logs.RegisterGeofence.list(this)
+// val d4 = Logs.RegisterGeofence.raw(this)
+// val d5 = Logs.GeofenceEvent.list(this)
+// val d6 = Logs.GeofenceEvent.raw(this)
+ print("")
}
override fun onResume() {
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 328014e6..b3fb4f56 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,7 +37,7 @@ class GeoZoneModel {
val rad = Radius.toFloat()
if(lat != null && long != null){
- val loiteringDelayMinutes:Int = 5 // in Minutes
+ val loiteringDelayMinutes:Int = 2 // in Minutes
return Geofence.Builder()
.setRequestId(identifier())
.setCircularRegion(
@@ -46,8 +46,8 @@ class GeoZoneModel {
rad
)
.setTransitionTypes(GeofenceTransition.ENTER_EXIT.value)
-// .setNotificationResponsiveness(0)
-// .setLoiteringDelay(loiteringDelayMinutes * 60 * 1000)
+ .setNotificationResponsiveness(0)
+ .setLoiteringDelay(loiteringDelayMinutes * 60 * 1000)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.build()
}
diff --git a/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/HMG_Geofence.kt b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/HMG_Geofence.kt
index 919d478f..ba6691f7 100644
--- a/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/HMG_Geofence.kt
+++ b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/geofence/HMG_Geofence.kt
@@ -9,6 +9,7 @@ import android.content.pm.PackageManager
import android.location.Location
import androidx.core.content.ContextCompat
import com.cloud.diplomaticquarterapp.geofence.intent_receivers.GeofenceBroadcastReceiver
+import com.cloud.diplomaticquarterapp.geofence.intent_receivers.ReregisterGeofenceJobService
import com.cloud.diplomaticquarterapp.utils.*
import com.google.android.gms.location.Geofence
import com.google.android.gms.location.GeofencingClient
@@ -20,8 +21,10 @@ import com.google.gson.reflect.TypeToken
enum class GeofenceTransition(val value: Int) {
ENTER(1),
EXIT(2),
+ DWELL(4),
+
ENTER_EXIT((ENTER.value or EXIT.value)),
- DWELL(4);
+ DWELL_EXIT((DWELL.value or EXIT.value));
companion object {
fun fromInt(value: Int) = GeofenceTransition.values().first { it.value == value }
@@ -30,8 +33,9 @@ enum class GeofenceTransition(val value: Int) {
fun named():String{
if (value == 1)return "Enter"
if (value == 2)return "Exit"
- if (value == (ENTER.value or EXIT.value))return "Enter or Exit"
if (value == 4)return "dWell"
+ if (value == (ENTER.value or EXIT.value))return "Enter or Exit"
+ if (value == (DWELL.value or EXIT.value))return "DWell or Exit"
return "unknown"
}
}
@@ -73,13 +77,22 @@ class HMG_Geofence {
}
}
+ fun limitize(zones: List):List{
+ var geoZones_ = zones
+ if(zones.size > 100)
+ geoZones_ = zones.subList(0, 99)
+ return geoZones_
+ }
+
fun register(geoZones: List){
if (geoZones.isEmpty())
return
+ var geoZones_ = limitize(geoZones)
+
fun buildGeofencingRequest(geofences: List): GeofencingRequest {
return GeofencingRequest.Builder()
- .setInitialTrigger(0)
+ .setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_DWELL)
.addGeofences(geofences)
.build()
}
@@ -87,9 +100,9 @@ class HMG_Geofence {
getActiveGeofences({ active ->
val geofences = mutableListOf()
- geoZones.forEach {
- it.toGeofence()?.let { geof ->
- if(!active.contains(geof.requestId)){ // if not already registered then register
+ geoZones_.forEach {
+ it.toGeofence()?.let { geof ->
+ if (!active.contains(geof.requestId)) { // if not already registered then register
geofences.add(geof)
}
}
@@ -99,19 +112,25 @@ class HMG_Geofence {
geofencingClient
.addGeofences(buildGeofencingRequest(geofences), geofencePendingIntent)
.addOnSuccessListener {
+ Logs.RegisterGeofence.save(context,"SUCCESS", "Successfuly registered the geofences", Logs.STATUS.SUCCESS)
saveActiveGeofence(geofences.map { it.requestId }, listOf())
}
.addOnFailureListener {
- print(it.localizedMessage)
- saveLog(context,"error:ADD_GEOFENCES", it.localizedMessage)
+ Logs.RegisterGeofence.save(context,"FAILED_TO_REGISTER", "Failed to register geofence",Logs.STATUS.ERROR)
}
+
+ // Schedule the job to register after specified duration (due to: events not calling after long period.. days or days [Needs to register fences again])
+ HMGUtils.scheduleJob(context, ReregisterGeofenceJobService::class.java,ReregisterGeofenceJobService.JobID, ReregisterGeofenceJobService.TriggerIntervalMillis)
}
- },null)
+
+ }, null)
+
}
- fun unRegisterAll(completion: (status: Boolean, exception:Exception?) -> Unit){
+ fun unRegisterAll(completion: (status: Boolean, exception: Exception?) -> Unit){
getActiveGeofences({ success ->
val mList = success.toMutableList()
+ removeActiveGeofences()
geofencingClient
.removeGeofences(success)
.addOnSuccessListener {
@@ -119,14 +138,20 @@ class HMG_Geofence {
}
.addOnFailureListener {
completion(false, it)
- saveLog(context,"error:REMOVE_GEOFENCES", it.localizedMessage)
+ saveLog(context, "error:REMOVE_GEOFENCES", it.localizedMessage)
}
- removeActiveGeofences()
}, { failed ->
// Nothing to do with failed geofences.
})
}
+ fun reRegister(){
+ unRegisterAll { status, exception ->
+ val geoZones = HMGUtils.getGeoZonesFromPreference(context)
+ register(geoZones)
+ }
+ }
+
fun saveActiveGeofence(success: List, failed: List){
val jsonSuccess = gson.toJson(success)
val jsonFailure = gson.toJson(failed)
@@ -135,8 +160,8 @@ class HMG_Geofence {
}
fun removeActiveGeofences(){
- preferences.edit().putString(PREF_KEY_SUCCESS,"[]").apply()
- preferences.edit().putString(PREF_KEY_FAILED,"[]").apply()
+ preferences.edit().putString(PREF_KEY_SUCCESS, "[]").apply()
+ preferences.edit().putString(PREF_KEY_FAILED, "[]").apply()
}
fun getActiveGeofences(success: (success: List) -> Unit, failure: ((failed: List) -> Unit)?){
@@ -164,7 +189,7 @@ class HMG_Geofence {
profileJson = preferences.getString("flutter.user-profile", null)
val type = object : TypeToken