diff --git a/ios/Flutter/.last_build_id b/ios/Flutter/.last_build_id index 3aa2cd1e..9694297e 100644 --- a/ios/Flutter/.last_build_id +++ b/ios/Flutter/.last_build_id @@ -1 +1 @@ -3f3d14a0ae775b56806906c2cb14a1f0 \ No newline at end of file +067d482a9455eae7d109c3ac5a36de46 \ No newline at end of file diff --git a/ios/Runner/Helper/HMGPlatformBridge.swift b/ios/Runner/Helper/HMGPlatformBridge.swift index 1e8ee735..ba7fefbd 100644 --- a/ios/Runner/Helper/HMGPlatformBridge.swift +++ b/ios/Runner/Helper/HMGPlatformBridge.swift @@ -40,7 +40,7 @@ class HMGPlatformBridge{ }else if methodCall.method == "isHMGNetworkAvailable"{ self.isHMGNetworkAvailable(methodCall:methodCall, result: result) - }else if methodCall.method == "registerHmgGeofences"{ + }else if methodCall.method == "unRegisterHmgGeofences"{ self.registerHmgGeofences(result: result) } @@ -119,10 +119,16 @@ class HMGPlatformBridge{ if let jsonString = geoFencesJsonString as? String{ let allZones = GeoZoneModel.list(from: jsonString) HMG_Geofence.shared().register(geoZones: allZones) - + result(true) }else{ } } } + + // Register Geofence + func unRegisterHmgGeofences(result: @escaping FlutterResult){ + HMG_Geofence.shared().unRegisterAll() + result(true) + } } diff --git a/ios/Runner/Helper/HMG_Geofence.swift b/ios/Runner/Helper/HMG_Geofence.swift index 20d2d1e8..16247980 100644 --- a/ios/Runner/Helper/HMG_Geofence.swift +++ b/ios/Runner/Helper/HMG_Geofence.swift @@ -71,6 +71,12 @@ class HMG_Geofence:NSObject{ return locationManager.monitoredRegions } + func unRegisterAll(){ + for region in locationManager.monitoredRegions { + locationManager.stopMonitoring(for: circularRegion) + } + } + } // CLLocationManager Delegates @@ -150,8 +156,8 @@ extension HMG_Geofence{ func notifyServer(forRegion:CLRegion, transition:Transition, location:CLLocation?){ showNotification(title: "Notifying server..." , subtitle: forRegion.identifier, message: "") - if let userProfileJson = UserDefaults.standard.string(forKey: "user-profile"), - let userProfile = dictionary(from: userProfileJson), let patientId = userProfile["PatientID"] as? String{ + if let userProfileJson = UserDefaults.standard.string(forKey: "flutter.user-profile"), + let userProfile = dictionary(from: userProfileJson), let patientId = userProfile["PatientID"] as? Int{ if let idString = forRegion.identifier.split(separator: "_").first, let idInt = Int(idString){ let body:[String:Any] = [ @@ -168,21 +174,5 @@ extension HMG_Geofence{ } } - // func notifyServer(forRegion:GeoZoneModel, transition:Transition, location:CLLocation?){ - // flutterMethodChannel?.invokeMethod("getLogGeofenceFullUrl", arguments: nil){ fullUrlString in - // if let url = fullUrlString as? String{ - // flutterMethodChannel?.invokeMethod("getDefaultHttpParameters", arguments: nil){ params in - // if var body = params as? [String : Any]{ - // body.updateValue(forZone.geofenceId, forKey: "PointsID") - // body.updateValue(transition.rawValue, forKey: "GeoType") - // httpPostRequest(urlString: url, jsonBody: body){ (status,json) in - // showNotification(title: transition.name(), subtitle: forZone.identifier(), message: status ? "Success: sent to server ✔️" : "Failed: sent to server ✖️") - // } - // } - // } - // } - // } - // } - } diff --git a/lib/core/service/geofencing/GeofencingServices.dart b/lib/core/service/geofencing/GeofencingServices.dart index a186b4c4..4946f2c2 100644 --- a/lib/core/service/geofencing/GeofencingServices.dart +++ b/lib/core/service/geofencing/GeofencingServices.dart @@ -56,10 +56,10 @@ class GeofencingServices extends BaseService { } addTestingGeoZones(List zones) { - zones.add({"GEOF_ID": -1, "Description": "ZiK Home", "Latitude": "24.691136", "Longitude": "46.650116", "Radius": 100, "Type": 1}); - zones.add({"GEOF_ID": -2, "Description": "CS Office", "Latitude": "24.7087913", "Longitude": "46.6656461", "Radius": 100, "Type": 1}); - zones.add({"GEOF_ID": -3, "Description": "Mahmoud Shrouf Home", "Latitude": "24.777577", "Longitude": "46.652675", "Radius": 100, "Type": 1}); - zones.add({"GEOF_ID": -4, "Description": "Panorama Mall", "Latitude": "24.692453", "Longitude": "46.669168", "Radius": 450, "Type": 1}); - zones.add({"GEOF_ID": -5, "Description": "Saudi Architects Crossing", "Latitude": "24.698375", "Longitude": "46.668567", "Radius": 140, "Type": 1}); + zones.add({"GEOF_ID": 12, "Description": "ZiK Home", "Latitude": "24.691136", "Longitude": "46.650116", "Radius": 100, "Type": 1}); + zones.add({"GEOF_ID": 13, "Description": "CS Office", "Latitude": "24.7087913", "Longitude": "46.6656461", "Radius": 100, "Type": 1}); + zones.add({"GEOF_ID": 14, "Description": "Mahmoud Shrouf Home", "Latitude": "24.777577", "Longitude": "46.652675", "Radius": 100, "Type": 1}); + zones.add({"GEOF_ID": 14, "Description": "Panorama Mall", "Latitude": "24.692453", "Longitude": "46.669168", "Radius": 450, "Type": 1}); + zones.add({"GEOF_ID": 16, "Description": "Saudi Architects Crossing", "Latitude": "24.698375", "Longitude": "46.668567", "Radius": 140, "Type": 1}); } } diff --git a/lib/pages/landing/landing_page.dart b/lib/pages/landing/landing_page.dart index 799ca86e..4ff2cc9c 100644 --- a/lib/pages/landing/landing_page.dart +++ b/lib/pages/landing/landing_page.dart @@ -50,6 +50,8 @@ class LandingPage extends StatefulWidget { } class _LandingPageState extends State with WidgetsBindingObserver { + var authProvider = new AuthProvider(); + int currentTab = 0; PageController pageController; ProjectViewModel projectViewModel; @@ -148,9 +150,11 @@ class _LandingPageState extends State with WidgetsBindingObserver { if (results[Permission.locationAlways].isGranted || results[Permission.location].isGranted) { debugPrint("Fetching GEO ZONES from HMG service..."); locator().getAllGeoZones(GeoZonesRequestModel()).then((geoZones) { - debugPrint("GEO ZONES saved to AppPreferences with key '$HMG_GEOFENCES'"); debugPrint("Finished Fetching GEO ZONES from HMG service..."); - projectViewModel.platformBridge().registerHmgGeofences(); + debugPrint("GEO ZONES saved to AppPreferences with key '$HMG_GEOFENCES'"); + if (authProvider.isLogin) { + projectViewModel.platformBridge().registerHmgGeofences(); + } }); } diff --git a/lib/pages/login/login.dart b/lib/pages/login/login.dart index 700a0d0c..28961843 100644 --- a/lib/pages/login/login.dart +++ b/lib/pages/login/login.dart @@ -43,11 +43,9 @@ class _Login extends State { final authService = new AuthProvider(); var sharedPref = new AppSharedPreferences(); bool isLoading = false; - AppointmentRateViewModel appointmentRateViewModel = - locator(); + AppointmentRateViewModel appointmentRateViewModel = locator(); - AuthenticatedUserObject authenticatedUserObject = - locator(); + AuthenticatedUserObject authenticatedUserObject = locator(); ProjectViewModel projectViewModel; @@ -89,25 +87,15 @@ class _Login extends State { child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - MobileNo( - onNumberChange: (value) => - {mobileNo = value, validateForm()}, - onCountryChange: (value) => countryCode = value), + MobileNo(onNumberChange: (value) => {mobileNo = value, validateForm()}, onCountryChange: (value) => countryCode = value), Container( child: TextFields( fontWeight: FontWeight.normal, controller: nationalIDorFile, onChanged: (value) => {validateForm()}, - prefixIcon: Icon( - loginType == 1 - ? Icons.chrome_reader_mode - : Icons.receipt, - color: Color(0xFF40ACC9)), - padding: EdgeInsets.only( - top: 20, bottom: 20, left: 10, right: 10), - hintText: loginType == 1 - ? TranslationBase.of(context).nationalID - : TranslationBase.of(context).fileNo, + prefixIcon: Icon(loginType == 1 ? Icons.chrome_reader_mode : Icons.receipt, color: Color(0xFF40ACC9)), + padding: EdgeInsets.only(top: 20, bottom: 20, left: 10, right: 10), + hintText: loginType == 1 ? TranslationBase.of(context).nationalID : TranslationBase.of(context).fileNo, )) ], ), @@ -121,16 +109,16 @@ class _Login extends State { color: Colors.grey, height: 2, ), - SizedBox(height: 10,), + SizedBox( + height: 10, + ), Row( children: [ Expanded( child: DefaultButton( TranslationBase.of(context).login, () => {this.startLogin()}, - color: isButtonDisabled == true - ? Colors.grey - : Colors.grey[900], + color: isButtonDisabled == true ? Colors.grey : Colors.grey[900], textColor: Colors.white, )) ], @@ -152,8 +140,7 @@ class _Login extends State { void validateForm() { //TODO fix login - if (util.validateIDBox(nationalIDorFile.text, loginType) == - true /*&& + if (util.validateIDBox(nationalIDorFile.text, loginType) == true /*&& mobileNo.length >= 9 */ && util.isSAUDIIDValid(nationalIDorFile.text, loginType) == true) { @@ -208,15 +195,13 @@ class _Login extends State { okText: TranslationBase.of(context).confirm, cancelText: TranslationBase.of(context).cancel_nocaps, okFunction: () => { - ConfirmDialog.closeAlertDialog(context), + ConfirmDialog.closeAlertDialog(context), Navigator.of(context).pushNamed( REGISTER, ), - }, cancelFunction: () => {ConfirmDialog.closeAlertDialog(context)}); dialog.showAlertDialog(context); - }); // SMSOTP.showLoadingDialog(context, false), } @@ -241,10 +226,13 @@ class _Login extends State { } // request.isRegister = false; this.authService.checkActivationCode(request, code).then((result) => { + // Register GeoZones after login + registerGeoZones(), + result = CheckActivationCode.fromJson(result), - result.list.isFamily =false, - this.sharedPref.setObject(USER_PROFILE, result.list), - this.sharedPref.setObject(MAIN_USER, result.list), + result.list.isFamily = false, + this.sharedPref.setObject(USER_PROFILE, result.list), + this.sharedPref.setObject(MAIN_USER, result.list), this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID), this.sharedPref.setString(TOKEN, result.authenticationTokenID), authenticatedUserObject.getUser(), @@ -283,6 +271,10 @@ class _Login extends State { }); } + void registerGeoZones() { + projectViewModel.platformBridge().registerHmgGeofences(); + } + // showLoader(bool isTrue) { // setState(() { // isLoading = isTrue; diff --git a/lib/uitl/PlatformBridge.dart b/lib/uitl/PlatformBridge.dart index ca410435..146ab853 100644 --- a/lib/uitl/PlatformBridge.dart +++ b/lib/uitl/PlatformBridge.dart @@ -90,6 +90,7 @@ class PlatformBridge { static const enable_wifi_if_not = "enableWifiIfNot"; static const show_loading_method = "loading"; static const register_Hmg_Geofences = "registerHmgGeofences"; + static const un_register_Hmg_Geofences = "unRegisterHmgGeofences"; Future connectHMGInternetWifi(String patientId) { print("Invoking platform method: $hmg_internet_wifi_connect_method"); @@ -144,4 +145,8 @@ class PlatformBridge { void registerHmgGeofences() async { final int result = await platform.invokeMethod(register_Hmg_Geofences); } + + void unRegisterHmgGeofences() async { + final int result = await platform.invokeMethod(un_register_Hmg_Geofences); + } } diff --git a/lib/widgets/drawer/app_drawer_widget.dart b/lib/widgets/drawer/app_drawer_widget.dart index c8af1ccb..9c6375e4 100644 --- a/lib/widgets/drawer/app_drawer_widget.dart +++ b/lib/widgets/drawer/app_drawer_widget.dart @@ -39,8 +39,7 @@ class _AppDrawerState extends State { var familyFileProvider = FamilyFilesProvider(); AuthenticatedUser user; AuthenticatedUser mainUser; - AuthenticatedUserObject authenticatedUserObject = - locator(); + AuthenticatedUserObject authenticatedUserObject = locator(); @override Widget build(BuildContext context) { @@ -64,67 +63,45 @@ class _AppDrawerState extends State { child: Column( children: [ Container( - child: - Image.asset('assets/images/DQ/DQ_logo.png'), - margin: EdgeInsets.all( - SizeConfig.imageSizeMultiplier * 4), + child: Image.asset('assets/images/DQ/DQ_logo.png'), + margin: EdgeInsets.all(SizeConfig.imageSizeMultiplier * 4), ), (user != null && projectProvider.isLogin) ? Padding( padding: EdgeInsets.all(15), - child: Column( - mainAxisAlignment: - MainAxisAlignment.start, + child: Column(mainAxisAlignment: MainAxisAlignment.start, children: [ + Row( children: [ - Row( - children: [ - Padding( - padding: EdgeInsets.only( - right: 5), - child: Icon( - Icons.account_circle, - color: Color(0xFF40ACC9), - )), - AppText( - user.firstName + - ' ' + - user.lastName, + Padding( + padding: EdgeInsets.only(right: 5), + child: Icon( + Icons.account_circle, color: Color(0xFF40ACC9), - ) - ], - ), - Row(children: [ - Padding( - padding: EdgeInsets.only( - left: 30, top: 5), - child: Column( - children: [ - AppText( - TranslationBase.of( - context) - .fileno + - ": " + - user.patientID - .toString(), - color: - Color(0xFF40ACC9), - fontSize: SizeConfig - .textMultiplier * - 1.5, - ), - AppText( - user.bloodGroup != null - ? 'Blood Group: ' + - user.bloodGroup - : '', - fontSize: SizeConfig - .textMultiplier * - 1.5, - ), - ], - )) - ]) - ])) + )), + AppText( + user.firstName + ' ' + user.lastName, + color: Color(0xFF40ACC9), + ) + ], + ), + Row(children: [ + Padding( + padding: EdgeInsets.only(left: 30, top: 5), + child: Column( + children: [ + AppText( + TranslationBase.of(context).fileno + ": " + user.patientID.toString(), + color: Color(0xFF40ACC9), + fontSize: SizeConfig.textMultiplier * 1.5, + ), + AppText( + user.bloodGroup != null ? 'Blood Group: ' + user.bloodGroup : '', + fontSize: SizeConfig.textMultiplier * 1.5, + ), + ], + )) + ]) + ])) : SizedBox(), ], ), @@ -135,9 +112,7 @@ class _AppDrawerState extends State { mainAxisAlignment: MainAxisAlignment.start, children: [ InkWell( - child: DrawerItem( - TranslationBase.of(context).arabicChange, - Icons.translate), + child: DrawerItem(TranslationBase.of(context).arabicChange, Icons.translate), onTap: () { // Navigator.of(context).pushNamed( // WELCOME_LOGIN, @@ -170,20 +145,13 @@ class _AppDrawerState extends State { ), FutureBuilder( future: getFamilyFiles(), // async work - builder: (BuildContext context, - AsyncSnapshot< - GetAllSharedRecordsByStatusResponse> - snapshot) { + builder: (BuildContext context, AsyncSnapshot snapshot) { switch (snapshot.connectionState) { case ConnectionState.waiting: - return Padding( - padding: EdgeInsets.all(10), - child: Text('Loading....')); + return Padding(padding: EdgeInsets.all(10), child: Text('Loading....')); default: if (snapshot.hasError) - return Padding( - padding: EdgeInsets.all(10), - child: Text(snapshot.error)); + return Padding(padding: EdgeInsets.all(10), child: Text(snapshot.error)); else return Container( decoration: BoxDecoration( @@ -198,76 +166,49 @@ class _AppDrawerState extends State { children: [ user.isFamily == true ? Container( - padding: - EdgeInsets.only( - bottom: 5), + padding: EdgeInsets.only(bottom: 5), child: InkWell( onTap: () { - switchUser( - mainUser, - context); + switchUser(mainUser, context); }, child: Row( - crossAxisAlignment: - CrossAxisAlignment - .start, - children: < - Widget>[ + crossAxisAlignment: CrossAxisAlignment.start, + children: [ Expanded( - child: Icon( - Icons - .person), + child: Icon(Icons.person), ), Expanded( flex: 7, - child: Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - AppText(mainUser.firstName + ' ' + mainUser.lastName), - AppText(TranslationBase.of(context).fileno + ": " + mainUser.patientID.toString()), - ])), + child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ + AppText(mainUser.firstName + ' ' + mainUser.lastName), + AppText(TranslationBase.of(context).fileno + ": " + mainUser.patientID.toString()), + ])), ], ))) : SizedBox(), Column( - mainAxisAlignment: - MainAxisAlignment - .start, - mainAxisSize: - MainAxisSize.min, - children: snapshot.data - .getAllSharedRecordsByStatusList - .map( - (result) { - return result - .status == - 3 + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: snapshot.data.getAllSharedRecordsByStatusList.map((result) { + return result.status == 3 ? Container( - padding: EdgeInsets - .only( - bottom: - 5), + padding: EdgeInsets.only(bottom: 5), child: InkWell( onTap: () { - switchUser( - result, - context); + switchUser(result, context); }, child: Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: < - Widget>[ + crossAxisAlignment: CrossAxisAlignment.start, + children: [ Expanded( - child: - Icon(Icons.person, color: result.responseID == user.patientID ? Color(0xFF40ACC9) : Colors.black), + child: Icon(Icons.person, color: result.responseID == user.patientID ? Color(0xFF40ACC9) : Colors.black), ), Expanded( flex: 7, child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ AppText(result.patientName, color: result.responseID == user.patientID ? Color(0xFF40ACC9) : Colors.black), - AppText(TranslationBase.of(context).fileno + ": " + result.iD.toString(), color: result.responseID == user.patientID ? Color(0xFF40ACC9) : Colors.black), + AppText(TranslationBase.of(context).fileno + ": " + result.iD.toString(), + color: result.responseID == user.patientID ? Color(0xFF40ACC9) : Colors.black), ])), ], ))) @@ -279,24 +220,15 @@ class _AppDrawerState extends State { }, ), InkWell( - child: DrawerItem( - TranslationBase.of(context) - .notification, - Icons.notifications), + child: DrawerItem(TranslationBase.of(context).notification, Icons.notifications), onTap: () { //NotificationsPage Navigator.of(context).pop(); - Navigator.push( - context, - MaterialPageRoute( - builder: (BuildContext context) => - NotificationsPage())); + Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) => NotificationsPage())); }, ), InkWell( - child: DrawerItem( - TranslationBase.of(context).appsetting, - Icons.settings_input_composite), + child: DrawerItem(TranslationBase.of(context).appsetting, Icons.settings_input_composite), onTap: () { Navigator.of(context).pushNamed( SETTINGS, @@ -304,23 +236,17 @@ class _AppDrawerState extends State { }, ), InkWell( - child: DrawerItem( - TranslationBase.of(context).rateApp, - Icons.star), + child: DrawerItem(TranslationBase.of(context).rateApp, Icons.star), onTap: () { if (Platform.isIOS) { - launch( - "https://apps.apple.com/sa/app/dr-suliaman-alhabib/id733503978"); + launch("https://apps.apple.com/sa/app/dr-suliaman-alhabib/id733503978"); } else { - launch( - "https://play.google.com/store/apps/details?id=com.ejada.hmg&hl=en"); + launch("https://play.google.com/store/apps/details?id=com.ejada.hmg&hl=en"); } }, ), InkWell( - child: DrawerItem( - TranslationBase.of(context).logout, - Icons.lock_open), + child: DrawerItem(TranslationBase.of(context).logout, Icons.lock_open), onTap: () { logout(); }, @@ -328,9 +254,7 @@ class _AppDrawerState extends State { ], ) : InkWell( - child: DrawerItem( - TranslationBase.of(context).loginregister, - Icons.lock_open), + child: DrawerItem(TranslationBase.of(context).loginregister, Icons.lock_open), onTap: () { login(); }, @@ -389,11 +313,9 @@ class _AppDrawerState extends State { checkUserData() async { if (await this.sharedPref.getObject(USER_PROFILE) != null) { - var data = AuthenticatedUser.fromJson( - await this.sharedPref.getObject(USER_PROFILE)); + var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE)); - var data2 = AuthenticatedUser.fromJson( - await this.sharedPref.getObject(MAIN_USER)); + var data2 = AuthenticatedUser.fromJson(await this.sharedPref.getObject(MAIN_USER)); print(data2); setState(() { this.user = data; @@ -409,6 +331,7 @@ class _AppDrawerState extends State { await sharedPref.clear(); this.user = null; Navigator.of(context).pushNamed(HOME); + projectProvider.platformBridge().unRegisterHmgGeofences(); } login() async { @@ -427,8 +350,7 @@ class _AppDrawerState extends State { if (user != null) { if (await sharedPref.getObject(FAMILY_FILE) != null) { // print(await sharedPref.getObject(FAMILY_FILE)); - return Future.value(GetAllSharedRecordsByStatusResponse.fromJson( - await sharedPref.getObject(FAMILY_FILE))); + return Future.value(GetAllSharedRecordsByStatusResponse.fromJson(await sharedPref.getObject(FAMILY_FILE))); } else { return familyFileProvider.getSharedRecordByStatus(); } @@ -437,17 +359,11 @@ class _AppDrawerState extends State { switchUser(user, context) { Utils.showProgressDialog(context); - this - .familyFileProvider - .silentLoggin(user is AuthenticatedUser ? null : user, - mainUser: user is AuthenticatedUser) - .then((value) => loginAfter(value, context)) - .catchError((err) { + this.familyFileProvider.silentLoggin(user is AuthenticatedUser ? null : user, mainUser: user is AuthenticatedUser).then((value) => loginAfter(value, context)).catchError((err) { print(err); AppToast.showErrorToast(message: err); Navigator.of(context).pop(); - }).showProgressBar( - text: "Loading", backgroundColor: Colors.blue.withOpacity(0.6)); + }).showProgressBar(text: "Loading", backgroundColor: Colors.blue.withOpacity(0.6)); } loginAfter(result, context) async {