diff --git a/PatientAppAPNSAuthKey.p8 b/PatientAppAPNSAuthKey.p8
new file mode 100755
index 00000000..0515964e
--- /dev/null
+++ b/PatientAppAPNSAuthKey.p8
@@ -0,0 +1,6 @@
+-----BEGIN PRIVATE KEY-----
+MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgJ5XRSnefd1apSG/z
+YJTQ55ffLMlPgKlGM9edg88mUZagCgYIKoZIzj0DAQehRANCAATSA2MbS+J0cQsc
+uBU0xaoxOUgGvnHCQSEK4t22i8eeKPPhH6RHJhK1ugPvj+Eyadf7j6pn3QRonEJu
+mIL+qvqC
+-----END PRIVATE KEY-----
\ No newline at end of file
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index de6f8030..42fc0237 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -6,6 +6,9 @@
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
+
+
+
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 5e7fe57b..8452a083 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
@@ -30,12 +30,12 @@ enum class GeofenceTransition(val value: Int) {
fun fromInt(value: Int) = GeofenceTransition.values().first { it.value == value }
}
- fun named():String{
- if (value == 1)return "Enter"
- if (value == 2)return "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"
+ fun named(): String {
+ if (value == 1) return "Enter"
+ if (value == 2) return "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"
}
}
@@ -44,63 +44,65 @@ class HMG_Geofence {
// https://developer.android.com/training/location/geofencing#java
private lateinit var context: Context
- private lateinit var preferences:SharedPreferences
+ private lateinit var preferences: SharedPreferences
private val gson = Gson()
- private lateinit var geofencingClient:GeofencingClient
+ private lateinit var geofencingClient: GeofencingClient
private val geofencePendingIntent: PendingIntent by lazy {
val intent = Intent(context, GeofenceBroadcastReceiver::class.java)
PendingIntent.getBroadcast(
- context,
- 0,
- intent,
- PendingIntent.FLAG_UPDATE_CURRENT)
+ context,
+ 0,
+ intent,
+ PendingIntent.FLAG_IMMUTABLE
+ )
}
- companion object{
+ companion object {
var instance: HMG_Geofence? = null
- fun shared(context: Context) : HMG_Geofence {
- if (instance == null) {
+ fun shared(context: Context): HMG_Geofence {
+ if (instance == null) {
instance = HMG_Geofence()
instance?.context = context
instance?.geofencingClient = LocationServices.getGeofencingClient(context)
- instance?.preferences = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
+ instance?.preferences =
+ context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
}
- return instance!!
+ return instance!!
}
}
- fun limitize(zones: List):List{
+ private fun limitize(zones: List): List {
var geoZones_ = zones
- if(zones.size > 100)
+ if (zones.size > 100)
geoZones_ = zones.subList(0, 99)
return geoZones_
}
- fun register(completion:((Boolean, java.lang.Exception?)->Unit)){
+ fun register(completion: ((Boolean, java.lang.Exception?) -> Unit)) {
unRegisterAll { status, exception ->
val geoZones = getGeoZonesFromPreference(context)
- doRegister(geoZones){ status_, error ->
+ doRegister(geoZones) { status_, error ->
completion.let { it(status_, error) }
}
}
}
- fun unRegisterAll(completion: (status: Boolean, exception: Exception?) -> Unit){
+ fun unRegisterAll(completion: (status: Boolean, exception: Exception?) -> Unit) {
getActiveGeofences({ success ->
removeActiveGeofences()
- if(success.isNotEmpty())
+ if (success.isNotEmpty())
geofencingClient
- .removeGeofences(success)
- .addOnSuccessListener {
- completion(true, null)
- }
- .addOnFailureListener {
- completion(false, it)
- saveLog(context, "error:REMOVE_GEOFENCES", it.localizedMessage)
- }
+ .removeGeofences(success)
+ .addOnSuccessListener {
+ completion(true, null)
+ }
+ .addOnFailureListener {
+ completion(false, it)
+ saveLog(context, "error:REMOVE_GEOFENCES", it.localizedMessage)
+ }
else
completion(true, null)
@@ -109,7 +111,10 @@ class HMG_Geofence {
})
}
- private fun doRegister(geoZones: List, completion:((Boolean, java.lang.Exception?)->Unit)? = null){
+ private fun doRegister(
+ geoZones: List,
+ completion: ((Boolean, java.lang.Exception?) -> Unit)? = null
+ ) {
if (geoZones.isEmpty())
return
@@ -117,9 +122,9 @@ class HMG_Geofence {
fun buildGeofencingRequest(geofences: List): GeofencingRequest {
return GeofencingRequest.Builder()
- .setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_DWELL)
- .addGeofences(geofences)
- .build()
+ .setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_DWELL)
+ .addGeofences(geofences)
+ .build()
}
getActiveGeofences({ active ->
@@ -135,26 +140,41 @@ class HMG_Geofence {
if (checkPermission() && geofences.isNotEmpty()) {
geofencingClient
- .addGeofences(buildGeofencingRequest(geofences), geofencePendingIntent)
- .addOnSuccessListener {
- Logs.RegisterGeofence.save(context,"SUCCESS", "Successfuly registered the geofences", Logs.STATUS.SUCCESS)
- saveActiveGeofence(geofences.map { it.requestId }, listOf())
- completion?.let { it(true,null) }
- }
- .addOnFailureListener { exc ->
- Logs.RegisterGeofence.save(context,"FAILED_TO_REGISTER", "Failed to register geofence",Logs.STATUS.ERROR)
- completion?.let { it(false,exc) }
- }
+ .addGeofences(buildGeofencingRequest(geofences), geofencePendingIntent)
+ .addOnSuccessListener {
+ Logs.RegisterGeofence.save(
+ context,
+ "SUCCESS",
+ "Successfuly registered the geofences",
+ Logs.STATUS.SUCCESS
+ )
+ saveActiveGeofence(geofences.map { it.requestId }, listOf())
+ completion?.let { it(true, null) }
+ }
+ .addOnFailureListener { exc ->
+ Logs.RegisterGeofence.save(
+ context,
+ "FAILED_TO_REGISTER",
+ "Failed to register geofence",
+ Logs.STATUS.ERROR
+ )
+ completion?.let { it(false, exc) }
+ }
// 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.TriggerIntervalDuration)
+ HMGUtils.scheduleJob(
+ context,
+ ReregisterGeofenceJobService::class.java,
+ ReregisterGeofenceJobService.JobID,
+ ReregisterGeofenceJobService.TriggerIntervalDuration
+ )
}
}, null)
}
- fun getGeoZonesFromPreference(context: Context):List{
+ fun getGeoZonesFromPreference(context: Context): List {
val pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
val json = pref.getString(PREF_KEY_HMG_ZONES, "[]")
@@ -162,26 +182,29 @@ class HMG_Geofence {
return geoZones
}
- fun saveActiveGeofence(success: List, failed: List){
+ fun saveActiveGeofence(success: List, failed: List) {
val jsonSuccess = gson.toJson(success)
val jsonFailure = gson.toJson(failed)
preferences.edit().putString(PREF_KEY_SUCCESS, jsonSuccess).apply()
preferences.edit().putString(PREF_KEY_FAILED, jsonFailure).apply()
}
- fun removeActiveGeofences(){
+ fun removeActiveGeofences() {
preferences.edit().putString(PREF_KEY_SUCCESS, "[]").apply()
preferences.edit().putString(PREF_KEY_FAILED, "[]").apply()
}
- fun getActiveGeofences(success: (success: List) -> Unit, failure: ((failed: List) -> Unit)?){
- val type = object : TypeToken?>() {}.type
+ fun getActiveGeofences(
+ success: (success: List) -> Unit,
+ failure: ((failed: List) -> Unit)?
+ ) {
+ val type = object : TypeToken?>() {}.type
val jsonSuccess = preferences.getString(PREF_KEY_SUCCESS, "[]")
val success = gson.fromJson>(jsonSuccess, type)
success(success)
- if(failure != null){
+ if (failure != null) {
val jsonFailure = preferences.getString(PREF_KEY_FAILED, "[]")
val failed = gson.fromJson>(jsonFailure, type)
failure(failed)
@@ -189,47 +212,74 @@ class HMG_Geofence {
}
- private fun checkPermission() : Boolean{
- return ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
+ private fun checkPermission(): Boolean {
+ return ContextCompat.checkSelfPermission(
+ context,
+ Manifest.permission.ACCESS_FINE_LOCATION
+ ) == PackageManager.PERMISSION_GRANTED
}
- fun getPatientID():Int?{
+ fun getPatientID(): Int? {
var profileJson = preferences.getString("flutter.imei-user-data", null)
if (profileJson == null)
profileJson = preferences.getString("flutter.user-profile", null)
val type = object : TypeToken