Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, ViewChild } from '@angular/core';
- import { NavController, MenuController, AlertController, Platform } from 'ionic-angular';
- import { Storage } from '@ionic/storage';
- import { Start } from '../start/start';
- import { Home } from '../home/home';
- import { Slides } from 'ionic-angular';
- import { Http } from '@angular/http';
- import { Network } from '@ionic-native/network';
- import { InAppBrowser } from '@ionic-native/in-app-browser';
- import { AppAvailability } from '@ionic-native/app-availability';
- import { Device } from '@ionic-native/device';
- import { Sim } from '@ionic-native/sim';
- @Component({
- selector: 'page-intro',
- templateUrl: 'intro.html',
- providers: [Network, AppAvailability, Device, InAppBrowser]
- })
- export class Intro {
- sliderOptions: any;
- @ViewChild('introSlider') slider: Slides;
- constructor(public navCtrl: NavController, public menu: MenuController, public alertCtrl: AlertController, public platform: Platform,
- public storage: Storage, public device: Device, public network: Network, public http: Http, public sim: Sim,
- public appAvailability: AppAvailability, public iab: InAppBrowser) {
- menu.swipeEnable(false);
- this.sliderOptions = {
- pager: true
- };
- this.platform.ready().then(() => {
- sim.requestReadPermission().then(() => {
- sim.getSimInfo().then((info) => {
- if (this.network.type !== "none" && this.network.type !== "unknown") {
- if (info.SIMTELCO1 != "60502" || info.SIMSTATE1 != 5) {
- let alert = this.alertCtrl.create({
- title: "Vérification SIM TT",
- enableBackdropDismiss: false,
- message: "Pour accéder aux applications :\nVotre SIM Tunisie Telecom doit être dans le 1er emplacement du téléphone.",
- buttons: [
- {
- text: "OK",
- handler: data => {
- this.platform.exitApp();
- }
- }
- ]
- });
- alert.present();
- } else {
- this.http.get("https://us-central1-nur-store.cloudfunctions.net/checkabo?app=com.youvas.sujood&IMEI1=" + info.IMEI1 + "&IMSI1=" + info.IMSI1 + "&SIMTELCONAME1=" + info.SIMTELCONAME1 + "&Field1&Field2")
- .map(res => res.json())
- .subscribe(data => {
- if (data.reponseabo == "000") {
- this.storage.remove('validite')
- let alert = this.alertCtrl.create({
- title: "NUR",
- enableBackdropDismiss: false,
- message: data.textFR,
- buttons: [
- {
- text: "Télécharger",
- handler: data => {
- appAvailability.check("com.youvas.nurstore").then(() => {
- // success callback
- window.open("nur-store://", "_system");
- this.platform.exitApp();
- }, () => {
- // error callback
- iab.create("market://details?id=com.youvas.nurstore", "_system", "hidden=true");
- this.platform.exitApp();
- });
- }
- },
- {
- text: "Cancel",
- handler: data => {
- this.platform.exitApp();
- }
- }
- ]
- });
- alert.present();
- }
- if (data.reponseabo == "100") {
- this.storage.remove('validite')
- let alert = this.alertCtrl.create({
- title: "NUR",
- enableBackdropDismiss: false,
- message: data.textFR,
- buttons: [
- {
- text: "OK",
- handler: data => {
- this.platform.exitApp();
- }
- },
- {
- text: "Cancel",
- handler: data => {
- this.platform.exitApp();
- }
- }
- ]
- });
- alert.present();
- }
- if (data.reponseabo == "101") {
- this.storage.set("validite",
- JSON.stringify({
- timeStamp: data.dateFin
- })
- );
- }
- }, (error) => {
- let alert = this.alertCtrl.create({
- title: "Vérification abonnement indisponible",
- enableBackdropDismiss: false,
- message: "Réessayez plus tard.",
- buttons: [
- {
- text: "OK",
- handler: data => {
- this.platform.exitApp();
- }
- }
- ]
- });
- alert.present();
- });
- }
- } else {
- this.storage.get("validite").then(result => {
- if (result !== null) {
- let validite = JSON.parse(result);
- if (new Date().getTime() > new Date(validite.timeStamp).getTime()) {
- let alert = this.alertCtrl.create({
- title: "Vérification abonnement indisponible",
- enableBackdropDismiss: false,
- message: "Merci de vous connecter à internet.",
- buttons: [
- {
- text: "OK",
- handler: data => {
- this.platform.exitApp();
- }
- }
- ]
- });
- alert.present();
- }
- } else {
- let alert = this.alertCtrl.create({
- title: "Vérification abonnement indisponible",
- enableBackdropDismiss: false,
- message: "Merci de vous connecter à internet.",
- buttons: [
- {
- text: "OK",
- handler: data => {
- this.platform.exitApp();
- }
- }
- ]
- });
- alert.present();
- }
- });
- }
- })
- .catch(err => {
- console.log(err);
- });
- })
- .catch(error => {
- console.log(error)
- // we don't have permission to read phone state
- let alert = this.alertCtrl.create({
- title: "NUR",
- enableBackdropDismiss: false,
- message: "Merci de nous donner la permission de vérifier que votre carte sim est TT.",
- buttons: [
- {
- text: "OK",
- handler: data => {
- this.platform.exitApp();
- }
- }
- ]
- });
- alert.present();
- });
- })
- }
- ionViewDidEnter() {
- this.slider.lockSwipeToPrev(true);
- }
- slideChanged() {
- if (this.slider != undefined) {
- if (this.slider.isBeginning()) {
- this.slider.lockSwipeToPrev(true);
- }
- if (!this.slider.isBeginning()) {
- this.slider.lockSwipeToPrev(false);
- }
- if (this.slider.isEnd()) {
- this.slider.lockSwipeToNext(true);
- }
- if (!this.slider.isEnd()) {
- this.slider.lockSwipeToNext(false);
- }
- }
- }
- goToHome() {
- this.menu.swipeEnable(true);
- this.storage.ready().then(() => {
- this.storage.get('gender').then((val) => {
- if (val) {
- this.navCtrl.setRoot(Home);
- } else {
- this.navCtrl.setRoot(Start);
- }
- });
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement