You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
5.0 KiB
Dart
149 lines
5.0 KiB
Dart
import 'dart:developer';
|
|
import 'dart:io';
|
|
|
|
import 'package:hmg_patient_app/config/config.dart';
|
|
import 'package:hmg_patient_app/config/shared_pref_kay.dart';
|
|
import 'package:hmg_patient_app/core/service/client/base_app_client.dart';
|
|
import 'package:hmg_patient_app/locator.dart';
|
|
import 'package:hmg_patient_app/models/Authentication/authenticated_user.dart';
|
|
import 'package:hmg_patient_app/uitl/PlatformBridge.dart';
|
|
import 'package:hmg_patient_app/uitl/app_shared_preferences.dart';
|
|
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
|
|
import 'package:hmg_patient_app/widgets/dialogs/alert_dialog.dart';
|
|
import 'package:hmg_patient_app/widgets/dialogs/confirm_dialog.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
// import 'package:wifi/wifi.dart';
|
|
|
|
import 'gif_loader_dialog_utils.dart';
|
|
|
|
class HMGNetworkConnectivity {
|
|
final _platformBridge = PlatformBridge.shared();
|
|
final BuildContext context;
|
|
late Function callBack;
|
|
|
|
final String GUEST_SSID = "HMG-MobileApp";
|
|
final String PATIENT_SSID = "GUEST-POC";
|
|
|
|
HMGNetworkConnectivity(this.context);
|
|
|
|
late AuthenticatedUser userData;
|
|
|
|
start() {
|
|
// getUserData().then((value) {
|
|
// userData = value;
|
|
// checkAndConnectIfNoInternet();
|
|
// });
|
|
}
|
|
|
|
void checkAndConnectIfNoInternet() async {
|
|
// getMyWifiCredentials((username, password){
|
|
// print("");
|
|
// });
|
|
//
|
|
// return;
|
|
|
|
String pingUrl = "$BASE_URL$PING_SERVICE";
|
|
// pingUrl = "https://captive.apple.com";
|
|
|
|
// String ssid = await Wifi.ssid.catchError((error) {
|
|
// log(error.toString());
|
|
// });
|
|
|
|
// bool alreadyConnected = ssid == GUEST_SSID;
|
|
|
|
// BaseAppClient().simpleGet(pingUrl, onSuccess: (dynamic response, int statusCode) {
|
|
// log("Having internet with status code: $statusCode");
|
|
// }, onFailure: (String error, int statusCode) {
|
|
// if (alreadyConnected)
|
|
// showFailDailog(TranslationBase.of(context).failedToAccessHmgServices);
|
|
// else {
|
|
// confirmFromUser(connectForLocalAccess);
|
|
// }
|
|
// });
|
|
// }
|
|
|
|
void confirmFromUser(VoidCallback confirmCallback) {
|
|
TranslationBase translator = TranslationBase.of(context);
|
|
|
|
void doIt() {
|
|
ConfirmDialog(
|
|
context: context,
|
|
confirmMessage: translator.wantToConnectWithHmgNetwork,
|
|
okText: translator.yes,
|
|
okFunction: () {
|
|
// ConfirmDialog.closeAlertDialog(context);
|
|
confirmCallback();
|
|
},
|
|
cancelText: translator.no,
|
|
cancelFunction: () {
|
|
ConfirmDialog.closeAlertDialog(context);
|
|
}).showAlertDialog(context);
|
|
}
|
|
|
|
// if (Platform.isAndroid)
|
|
// Wifi.list(GUEST_SSID).then((value) {
|
|
// if (!value.indexWhere((element) => element.ssid == GUEST_SSID).isNegative) doIt();
|
|
// });
|
|
// else
|
|
// doIt();
|
|
}
|
|
|
|
void showFailDailog(String message) {
|
|
TranslationBase translator = TranslationBase.of(context);
|
|
AlertDialogBox(
|
|
context: context,
|
|
okText: translator.ok,
|
|
confirmMessage: message,
|
|
okFunction: () {
|
|
AlertDialogBox.closeAlertDialog(context);
|
|
}).showAlertDialog(context);
|
|
}
|
|
|
|
Future<AuthenticatedUser> getUserData() async {
|
|
var userData = AuthenticatedUser.fromJson(
|
|
await AppSharedPreferences().getObject(MAIN_USER));
|
|
return userData;
|
|
}
|
|
|
|
connectForLocalAccess() {
|
|
String patientID = userData.patientID.toString();
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
_platformBridge.connectHMGGuestWifi(GUEST_SSID).then((value) async {
|
|
if (value == 0) {
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
} else {
|
|
// getPatientWifiCredentials(patientID, (username, password) async {
|
|
// final result = await _platformBridge.connectHMGInternetWifi(PATIENT_SSID, username, password).catchError((err) => print(err.toString()));
|
|
// GifLoaderDialogUtils.hideDialog(context);
|
|
// if (result == 1) {
|
|
// // Success
|
|
// }
|
|
// });
|
|
}
|
|
});
|
|
}
|
|
//
|
|
// getPatientWifiCredentials(String patientID, Function(String username, String password) successCallback) {
|
|
// final body = <String, dynamic>{"PatientID": patientID};
|
|
// locator<BaseAppClient>().post(WIFI_CREDENTIALS, body: body, onSuccess: (dynamic response, int statusCode) {
|
|
// print(response);
|
|
// var data = response["Hmg_SMS_Get_By_ProjectID_And_PatientIDList"];
|
|
// if (data is List && data.first != null) {
|
|
// final username = data.first['UserName'];
|
|
// final password = data.first['Password'];
|
|
// if (username != null && password != null && username.isNotEmpty && password.isNotEmpty) {
|
|
// successCallback(username, password);
|
|
// }
|
|
// }
|
|
// }, onFailure: (String error, int statusCode) {
|
|
// print(error);
|
|
// }, bypassConnectionCheck: true);
|
|
// }
|
|
//
|
|
|
|
|
|
}
|
|
///Commeneted code need to reimplement
|
|
}
|