Android Wifi Attendance Completed...

mohemm-wifi-feature
Zohaib Iqbal Kambrani 5 years ago
parent 5af213dcf8
commit 316ce130fc

@ -24,8 +24,8 @@ export class ConnectorService {
public static timeOut = 120 * 1000;
// public static host = 'http://10.50.100.113:6060/'; // development service
public static host = 'https://uat.hmgwebservices.com/';
// public static host = 'https://hmgwebservices.com/';
// public static host = 'https://uat.hmgwebservices.com/';
public static host = 'https://hmgwebservices.com/';
// public static host = 'http://10.50.100.198:6060/';
// public static host = 'http://10.50.100.113:6060/'; // development service
/* public static host = 'http://10.50.100.198:6060/';

@ -1,4 +1,4 @@
import { Component, OnInit, NgZone } from "@angular/core";
import { Component, OnInit, NgZone, VERSION } from "@angular/core";
import { NFC } from "@ionic-native/nfc/ngx";
import { CommonService } from "src/app/hmg-common/services/common/common.service";
import { Platform } from "@ionic/angular";
@ -13,6 +13,9 @@ import { attendanceSwipeScannerRequest } from "src/app/home/models/attendanceSwi
import { Device } from "@ionic-native/device/ngx";
import { AttendanceService } from "src/app/home/services/attendance.services";
import { Response } from "src/app/hmg-common/services/models/response";
import { WifiWizard2 } from "@ionic-native/wifi-wizard-2/ngx";
import { OpenNativeSettings } from '@ionic-native/open-native-settings/ngx';
import { DevicePermissionsService } from 'src/app/hmg-common/services/device-permissions/device-permissions.service';
@ -41,7 +44,10 @@ export class AttendanceOptionsComponent implements OnInit {
public modalController: ModalController,
private device: Device,
private attendance_service: AttendanceService,
public ngZone: NgZone
public ngZone: NgZone,
private wifiWizard2: WifiWizard2,
private openNativeSettings: OpenNativeSettings,
private devicePermissionsService:DevicePermissionsService
) {}
ngOnInit() {
@ -173,21 +179,51 @@ export class AttendanceOptionsComponent implements OnInit {
// Wifi Attendance
public async startWifi() {
const isAndroid = this.platform.is("android");
const isIOS = this.platform.is("ios");
const isWifiEnabled = await this.wifiWizard2.isWifiEnabled();
if(isIOS){
if(!isWifiEnabled){
this.showWifiNotEnabled();
return;
}
}else if(isAndroid){
let locationPermission = await this.devicePermissionsService.requestLocationAutherization();
if(!locationPermission){
return;
}
if(!isWifiEnabled){
this.wifiWizard2.setWifiEnabled(true).then(()=>{
this.startWifi();
}).catch((err) => {
console.debug(err);
this.showWifiNotEnabled();
});
return;
}
}
// opening wifi dailog if all above conditions are passed (isWifiEnabled == true)
let modal = await this.modalController.create({
component: WifiModalComponent,
showBackdrop: true,
backdropDismiss: true,
backdropDismiss: false,
});
modal.cssClass = "wifi-modal";
await modal.present();
}
// modal = await this.modalController.create({
// component: NfcModalComponent,
// showBackdrop: true,
// backdropDismiss: true,
// });
// modal.cssClass = "nfc-modal";
// await modal.present();
showWifiNotEnabled(){
this.common.showErrorMessageDialog(()=>{
// this.openNativeSettings.open('wifi').then(()=>{});
},
this.ts.trPK("general", "ok"),
this.ts.trPK("general","wifi-not-enable-text"));
}
}

@ -3,13 +3,13 @@
<p class="heading-text"></p>
</div>
<div *ngIf="!gifStatus" class="ripple-div">
<div *ngIf="!gifStatus" class="wifi-div">
<img src="../assets/imgs/wifiConnect.gif" />
<ion-label class="ion-text-wrap">{{ "general, wifi-connect-message" | translate }}</ion-label>
<p>{{ "general, wifi-connect-message" | translate }}</p>
</div>
<div *ngIf="gifStatus" class="checked-img">
<img src="../assets/imgs/check_padding.png" />
<ion-label class="ion-text-wrap">{{ "general, success-attendance" | translate }}</ion-label>
<img src="../assets/imgs/check_padding.png" />
<p>{{ "general, success-attendance" | translate }}</p>
</div>
</ion-content>

@ -32,9 +32,14 @@
width: 270px;
}
}
.wifi-div {
display: block;
text-align: center;
margin-top: 0%;
}
.checked-img {
display: block;
text-align: center;
margin-top: 25%;
margin-top: 10%;
}

@ -51,56 +51,87 @@ export class WifiModalComponent implements OnInit {
const isIOS = this.platform.is("ios");
if (isAndroid) {
this.wifiWizard2.connect(this.ssid, true, this.password, this.algo).then(async (value) =>{
let isWifiAvailable = await this.isWifiAvailable(this.ssid);
console.debug("isWifiAvailable: " + isWifiAvailable);
if(isWifiAvailable){
console.debug("Wifi Credientials: " + this.ssid + " | " + this.password);
this.wifiWizard2.connect(this.ssid, true, this.password, this.algo).then(async (value) =>{
let ssid_ = await this.wifiWizard2.getConnectedSSID();
if(ssid_ == this.ssid){
console.debug("Wifi Connected: Verified Access | " + value + " | " + ssid_);
setTimeout(() => {
this.swipeAttendanceWifi(ssid_);
},2000);
}else{
this.showErrorInvalidWorkspace();
}
})
.catch((err) => {
console.debug(err);
this.showErrorForgetWifiConfiguration();
});
}else{
console.debug("Wifi is not available considered your device is not in range");
this.showErrorInvalidWorkspace();
}
} else if (isIOS) {
this.wifiWizard2.iOSConnectNetwork(this.ssid,this.password).then(async (value) => {
let ssid_ = await this.wifiWizard2.getConnectedSSID();
let bssid = await this.wifiWizard2.getConnectedBSSID();
console.log("Wifi Connected: Verified Access | " + value + " | " + ssid_ + " | " + bssid);
setTimeout(() => {
this.swipeAttendanceWifi(bssid);
},2000);
if(ssid_ == this.ssid){
console.debug("Wifi Connected: Verified Access | " + value + " | " + ssid_);
setTimeout(() => {
this.swipeAttendanceWifi(ssid_);
},2000);
}else{
this.showErrorInvalidWorkspace();
}
})
.catch((err) => {
console.debug(err);
this.showErrorInvalidWorkspace();
});
} else if (isIOS) {
if(this.wifiWizard2.isWifiEnabled){
this.wifiWizard2.iOSConnectNetwork(this.ssid,this.password).then((value) => {
let bssid = this.wifiWizard2.getConnectedBSSID();
console.log("Wifi Connected: Verified Access | " + value + " | " + bssid);
setTimeout(() => {
this.swipeAttendanceWifi(this.ssid);
},1000);
})
.catch((err) => {
this.showErrorInvalidWorkspace();
});
} else{
this.common.showErrorMessageDialog(()=>{
this.openNativeSettings.open('wifi').then(()=>{});
},
this.ts.trPK("general", "ok"),
this.ts.trPK("general","wifi-not-enable-text"));
this.showWifiNotEnabled();
}
}
}
showWifiNotEnabled(){
this.common.showErrorMessageDialog(()=>{
this.openNativeSettings.open('wifi').then(()=>{});
},
this.ts.trPK("general", "ok"),
this.ts.trPK("general","wifi-not-enable-text"));
}
showErrorInvalidWorkspace() {
this.closeModal();
this.common.showErrorMessageDialog(()=>{
},
this.ts.trPK("general", "ok"),
this.ts.trPK("general","wifi-not-enable-text"));
this.ts.trPK("general","wifi-connection-failed-text"));
this.disconnectWifi();
}
showErrorForgetWifiConfiguration() {
this.closeModal();
this.common.confirmAlertDialog(() => {
this.openNativeSettings.open('wifi').then(()=>{});
}, this.ts.trPK('general', 'settings'), () => {
}, this.ts.trPK('general', 'cancel'), this.ts.trPK('vacation-rule', 'confirmation'), this.ts.trPK("general","forget-wifi-connection-text"));
this.disconnectWifi();
}
disconnectWifi(){
async disconnectWifi() {
const isAndroid = this.platform.is("android");
const isIOS = this.platform.is("ios");
if(isAndroid){
this.wifiWizard2.disconnect(this.ssid);
this.wifiWizard2.remove(this.ssid);
console.log("Wifi Removed");
await this.wifiWizard2.disconnect(this.ssid).catch((error)=>{ console.error(error) });
await this.wifiWizard2.remove(this.ssid).catch((error)=>{ console.error(error) });
console.debug("Wifi Removed");
}
}
@ -117,7 +148,9 @@ export class WifiModalComponent implements OnInit {
this.attendance_service
.attendanceSwipeScanner(request, () => {
console.log("Error inside in swipe attendance");
console.debug("Error inside in swipe attendance");
this.closeModal();
this.disconnectWifi();
})
.subscribe((result: Response) => {
this.disconnectWifi();
@ -127,10 +160,10 @@ export class WifiModalComponent implements OnInit {
});
setTimeout(() => {
this.closeModal();
this.common.openHome();
}, 6000);
// this.common.openAttenTrackingpage();
}, 4000);
}else{
console.log(result);
console.debug(result);
this.closeModal();
}
});
@ -140,4 +173,14 @@ export class WifiModalComponent implements OnInit {
this.modalController.dismiss();
}
async isWifiAvailable(ssid:string){
let avaialble_wifi = await this.wifiWizard2.scan();
let find_ = avaialble_wifi.find(element => {
return element.SSID == ssid;
});
console.log("find: " + find_.SSID);
return find_.SSID == ssid;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 262 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

@ -899,6 +899,10 @@
"en": "Failed to validate, please visit the nearest receptions in the branch",
"ar": "فشل التحقق ، يرجى زيارة أقرب مكتب استقبال في الفرع"
},
"forget-wifi-connection-text": {
"en": "Invalid Wi-Fi configuration exists with 'HMG-MOHEMM', please forget the Wi-Fi from settings.",
"ar": "فشل الاتصال بشبكة 'HMG-MOHEMM' الرجاء اختيار نسيت الاتصال من اعدادت الشبكة"
},
"qr-text": {
"en": "QR Code",
"ar": "الشفرة QR"

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save