Beispiel #1
0
        public App()
        {
            InitializeComponent();
            //Register Syncfusion license
            Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("NjQxN0AzMTM2MmUzMjJlMzBPKzU1STRkNDA1Y29rWlhzSnQ4bHl2N0FJLzNFWFFnaFcxamswdHQ1cHFFPQ==");

            userDataDbService = new UserDataDbService();
            webApiRestClient  = new WebApiRestClient();
            var density = DeviceDisplay.MainDisplayInfo.Density;

            ShimmerLayout.Init(density);

            Material.Init(this);


            //L10n.SetLocale();



            //var netLanguage = DependencyService.Get<ILocale>().GetCurrent();
            //AppResource.Culture = new CultureInfo(netLanguage);

            if (Application.Current.Properties.ContainsKey("IsAppAlreadyInstalled") && Convert.ToBoolean(Application.Current.Properties["IsAppAlreadyInstalled"]))
            {
                if (Application.Current.Properties.ContainsKey("AppLocale") && !string.IsNullOrEmpty(Application.Current.Properties["AppLocale"].ToString()))
                {
                    var languageculture = Application.Current.Properties["AppLocale"].ToString();
                    Setlanguage(languageculture);
                }
                if (userDataDbService.IsUserDbPresentInDB())
                {
                    userData = userDataDbService.ReadAllItems().FirstOrDefault();
                    Application.Current.Properties["CurrentUserId"]   = userData.UserId;
                    Application.Current.Properties["CurrentUserType"] = userData.UserType.Value;
                    App.Current.MainPage = new NavigationPage(new HomeTabPage());
                    UpdateDeviceInfo();
                }
                else
                {
                    MainPage = new NavigationPage(new LoginPage());
                }
            }
            else
            {
                Setlanguage("en-US");
                MainPage = new NavigationPage(new ChangeLanguagePage(false));
            }

            //if (userDataDbService.IsUserDbPresentInDB())
            //{
            //    userData = userDataDbService.ReadAllItems().FirstOrDefault();
            //    Application.Current.Properties["CurrentUserId"] = userData.UserId;
            //    Application.Current.Properties["CurrentUserType"] = userData.UserType.Value;
            //    App.Current.MainPage = new NavigationPage(new HomeTabPage());
            //}
            //else
            //{
            //    MainPage = new NavigationPage(new LoginPage());
            //}
        }
Beispiel #2
0
        public App()
        {
            InitializeComponent();
            userDataDbService = new UserDataDbService();
            webApiRestClient  = new WebApiRestClient();
            var density = DeviceDisplay.MainDisplayInfo.Density;

            ShimmerLayout.Init(density);

            Material.Init(this);
            //L10n.SetLocale();



            //var netLanguage = DependencyService.Get<ILocale>().GetCurrent();
            //AppResource.Culture = new CultureInfo(netLanguage);

            if (Application.Current.Properties.ContainsKey("IsAppAlreadyInstalled") && Convert.ToBoolean(Application.Current.Properties["IsAppAlreadyInstalled"]))
            {
                if (Application.Current.Properties.ContainsKey("AppLocale") && !string.IsNullOrEmpty(Application.Current.Properties["AppLocale"].ToString()))
                {
                    var languageculture = Application.Current.Properties["AppLocale"].ToString();
                    Setlanguage(languageculture);
                }
                if (userDataDbService.IsUserDbPresentInDB())
                {
                    userData = userDataDbService.ReadAllItems().FirstOrDefault();
                    Application.Current.Properties["CurrentUserId"]   = userData.UserId;
                    Application.Current.Properties["CurrentUserType"] = userData.UserType.Value;
                    BaseViewModel.userTypeEnum = userData.UserType.Value;
                    if (userData.UserType == Convert.ToInt32(UserTypeEnum.ServiceProvider))
                    {
                        App.Current.MainPage = new NavigationPage(new Pages.ServiceProviderFlow.HomeTabbedPage());
                    }
                    else
                    {
                        App.Current.MainPage = new NavigationPage(new Pages.WorkerFlow.HomeTabbedPage());
                    }
                    UpdateDeviceInfo();
                }
                else
                {
                    MainPage = new NavigationPage(new LoginPage());
                }
            }
            else
            {
                Setlanguage("en-US");
                MainPage = new NavigationPage(new ChangeLanguagePage(false));
            }

            //if (userDataDbService.IsUserDbPresentInDB())
            //{
            //    userData = userDataDbService.ReadAllItems().FirstOrDefault();
            //    Application.Current.Properties["CurrentUserId"] = userData.UserId;
            //    Application.Current.Properties["CurrentUserType"] = userData.UserType.Value;
            //    BaseViewModel.userTypeEnum = userData.UserType.Value;
            //    if (userData.UserType == Convert.ToInt32(UserTypeEnum.ServiceProvider))
            //    {
            //        App.Current.MainPage = new NavigationPage(new Pages.ServiceProviderFlow.HomeTabbedPage());
            //    }
            //    else
            //    {
            //        App.Current.MainPage = new NavigationPage(new Pages.WorkerFlow.HomeTabbedPage());
            //    }
            //}
            //else
            //{
            //    MainPage = new NavigationPage(new LoginPage());
            //}
        }
        protected override async void OnInitialized()
        {
            InitializeComponent();
            _webApiRestClient = new WebApiRestClient();
            XF.Material.Forms.Material.Init(this);
            userDataDbService = new UserDataDbService();

            //Xamarin.Essentials.Connectivity.ConnectivityChanged += Connectivity_ConnectivityChanged;

            try
            {
                if (Application.Current.Properties.ContainsKey("AppLocale") && !string.IsNullOrEmpty(Application.Current.Properties["AppLocale"].ToString()))
                {
                    var languageculture = Application.Current.Properties["AppLocale"].ToString();
                    Setlanguage(languageculture);
                    Application.Current.Properties["IsAppAlreadyInstalled"] = true;
                    Application.Current.SavePropertiesAsync();
                }
                else
                {
                    Application.Current.Properties["AppLocale"] = "ar-AE";
                    Setlanguage("ar-AE");
                    Application.Current.Properties["IsAppAlreadyInstalled"] = true;
                    Application.Current.SavePropertiesAsync();
                }
            }
            catch (Exception ex)
            {

            }


            //await NavigationService.NavigateAsync("NavigationPage/LoginPage");

            //if (Application.Current.Properties.ContainsKey("CountryList"))
            //{
            //    BaseViewModel.countryDataModels = JsonConvert.DeserializeObject<List<CountryDataModel>>(Application.Current.Properties["CountryList"].ToString());
            //}
            //if (Application.Current.Properties.ContainsKey("ProvinceList"))
            //{
            //    BaseViewModel.provienceDataModels = JsonConvert.DeserializeObject<List<ProvienceDataModel>>(Application.Current.Properties["ProvinceList"].ToString());
            //}

            if (userDataDbService.IsUserDbPresentInDB())
            {
                userdataindb = userDataDbService.ReadAllItems().FirstOrDefault();
                BaseViewModel.user_id = userdataindb.user_id;
                BaseViewModel.province_id = userdataindb.province.Value;
                BaseViewModel.user_name = userdataindb.name;
                BaseViewModel.user_pic = Common.IsImagesValid(userdataindb.profile_pic, ApiUrl.BaseUrl);
                BaseViewModel.email_verified = userdataindb.email_verified.HasValue ? userdataindb.email_verified.Value : false;

                Device.BeginInvokeOnMainThread(async() =>
                {
                    await NavigationService.NavigateAsync(new Uri("/MasterPage/NavigationPage/HomePage", UriKind.Absolute));
                });
            }
            else
            {
                await NavigationService.NavigateAsync("NavigationPage/LoginPage");
            }

            //GetCountriesApi();


            BaseViewModel.app = this;

            if (Application.Current.Properties.ContainsKey("CountryList"))
            {
                BaseViewModel.countryDataModels = JsonConvert.DeserializeObject<List<CountryDataModel>>(Application.Current.Properties["CountryList"].ToString());
            }
            if (Application.Current.Properties.ContainsKey("ProvinceList"))
            {
                BaseViewModel.provienceDataModels = JsonConvert.DeserializeObject<List<ProvienceDataModel>>(Application.Current.Properties["ProvinceList"].ToString());
            }

            if (Device.RuntimePlatform == Device.Android || Device.RuntimePlatform == Device.iOS)
            {

                await CrossFirebasePushNotification.Current.RegisterForPushNotifications();

                CrossFirebasePushNotification.Current.Subscribe("general");
                CrossFirebasePushNotification.Current.OnTokenRefresh += (s, p) =>
                {
                    System.Diagnostics.Debug.WriteLine($"TOKEN REC: {p.Token}");
                    Application.Current.Properties["AppFirebaseToken"] = p.Token;
                    Application.Current.SavePropertiesAsync();

                };
                System.Diagnostics.Debug.WriteLine($"TOKEN: {CrossFirebasePushNotification.Current.Token}");

                CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
                {
                    try
                    {
                        if (Device.RuntimePlatform == Device.iOS)
                        {
                            if (p.Data.ContainsKey("aps.alert"))
                            {
                                Device.BeginInvokeOnMainThread(async () =>
                                {
                                    var data = $"{p.Data["aps.alert"]}";
                                    if (data.Contains("Your password has been reset by the admin, In order to continue please contact administrator.") || data.Contains("تمت إعادة تعيين كلمة المرور الخاصة بك من قبل المشرف ، للمتابعة ، يرجى الاتصال بالمسؤول") || data.Contains("Your account has been de-activated by the admin, in order to continue please contact administrator") || data.Contains("تم إلغاء تنشيط حسابك من قبل المشرف ، للمتابعة ، يرجى الاتصال بالمسؤول"))
                                    {
                                        if (userDataDbService.IsUserDbPresentInDB())
                                        {
                                            var item = userDataDbService.ReadAllItems().FirstOrDefault();
                                            BsonValue id = item.ID;
                                            userDataDbService.DeleteItemFromDB(id, item);

                                            //App.Current.MainPage = new NavigationPage(new LoginPage());
                                            await NavigationService.NavigateAsync(new Uri("/NavigationPage/LoginPage", UriKind.Absolute));
                                        }
                                    }
                                });

                            }
                        }
                        else if (Device.RuntimePlatform == Device.Android)
                        {
                            if (p.Data.ContainsKey("body"))
                            {
                                Device.BeginInvokeOnMainThread(async () =>
                                {
                                    var data = $"{p.Data["body"]}";

                                    if (data.Contains("Your password has been reset by the admin, In order to continue please contact administrator.") || data.Contains("تمت إعادة تعيين كلمة المرور الخاصة بك من قبل المشرف ، للمتابعة ، يرجى الاتصال بالمسؤول") || data.Contains("Your account has been de-activated by the admin, in order to continue please contact administrator") || data.Contains("تم إلغاء تنشيط حسابك من قبل المشرف ، للمتابعة ، يرجى الاتصال بالمسؤول"))
                                    {
                                        if (userDataDbService.IsUserDbPresentInDB())
                                        {
                                            var item = userDataDbService.ReadAllItems().FirstOrDefault();
                                            BsonValue id = item.ID;
                                            userDataDbService.DeleteItemFromDB(id, item);

                                            //App.Current.MainPage = new NavigationPage(new LoginPage());
                                            await NavigationService.NavigateAsync(new Uri("/NavigationPage/LoginPage", UriKind.Absolute));
                                        }
                                    }
                                });

                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        // Some other exception occurred
                    }

                };

                CrossFirebasePushNotification.Current.OnNotificationOpened += async (s, p) =>
                {
                    //System.Diagnostics.Debug.WriteLine(p.Identifier);

                    try
                    {
                        if (Device.RuntimePlatform == Device.iOS)
                        {
                            if (p.Data.ContainsKey("aps.alert"))
                            {
                                Device.BeginInvokeOnMainThread(async () =>
                                {
                                    var data = $"{p.Data["aps.alert"]}";
                                    if (data.Contains("You have new message regarding your job request") || data.Contains("لديك رسالة جديدة بخصوص طلب عملك.") || data.Contains("You have new message") || data.Contains("لديك رسالة جديدة"))
                                    {
                                        await NavigationService.NavigateAsync(new Uri("/MasterPage/NavigationPage/HomePage", UriKind.Absolute));
                                        await NavigationService.NavigateAsync(nameof(ChatListPage));
                                        //App.Current.MainPage = new NavigationPage(new MasterPage());
                                        //App.Current.MainPage.Navigation.PushAsync(new ChatListPage());
                                    }
                                    else if (data.Contains("You have new message from support team") || data.Contains("لديك رسالة جديدة من فريق الدعم"))
                                    {
                                        await NavigationService.NavigateAsync(new Uri("/MasterPage/NavigationPage/HomePage", UriKind.Absolute));
                                        await NavigationService.NavigateAsync(nameof(SupportPage));
                                    }
                                    else if (data.Contains("Your password has been reset by the admin, In order to continue please contact administrator.") || data.Contains("تمت إعادة تعيين كلمة المرور الخاصة بك من قبل المشرف ، للمتابعة ، يرجى الاتصال بالمسؤول") || data.Contains("Your account has been de-activated by the admin, in order to continue please contact administrator") || data.Contains("تم إلغاء تنشيط حسابك من قبل المشرف ، للمتابعة ، يرجى الاتصال بالمسؤول"))
                                    {
                                        if (userDataDbService.IsUserDbPresentInDB())
                                        {
                                            var item = userDataDbService.ReadAllItems().FirstOrDefault();
                                            BsonValue id = item.ID;
                                            userDataDbService.DeleteItemFromDB(id, item);

                                            //App.Current.MainPage = new NavigationPage(new LoginPage());
                                            await NavigationService.NavigateAsync(new Uri("/NavigationPage/LoginPage", UriKind.Absolute));
                                        }
                                    }
                                    else
                                    {
                                        await NavigationService.NavigateAsync(new Uri("/MasterPage/NavigationPage/HomePage", UriKind.Absolute));
                                        await NavigationService.NavigateAsync(nameof(NotificationPage));
                                        //if (Application.Current.Properties.ContainsKey("AppStatus"))
                                        //{
                                        //if (Convert.ToInt32(Application.Current.Properties["AppStatus"]) == Convert.ToInt32(AppStatus.Foreground))
                                        //{
                                        //    App.Current.MainPage.Navigation.PushAsync(new NotificationPage());
                                        //}
                                        //else if (Convert.ToInt32(Application.Current.Properties["AppStatus"]) == Convert.ToInt32(AppStatus.Background))
                                        //{
                                        //    App.Current.MainPage = new NavigationPage(new MasterPage());
                                        //    App.Current.MainPage.Navigation.PushAsync(new NotificationPage());
                                        //}
                                        //}
                                    }
                                });

                            }
                        }
                        else if (Device.RuntimePlatform == Device.Android)
                        {
                            if (p.Data.ContainsKey("body"))
                            {
                                Device.BeginInvokeOnMainThread(async () =>
                                {
                                    var data = $"{p.Data["body"]}";

                                    if (data.Contains("You have new message regarding your job request") || data.Contains("لديك رسالة جديدة بخصوص طلب عملك.") || data.Contains("You have new message") || data.Contains("لديك رسالة جديدة"))
                                    {
                                        await NavigationService.NavigateAsync(new Uri("/MasterPage/NavigationPage/HomePage", UriKind.Absolute));
                                        await NavigationService.NavigateAsync(nameof(ChatListPage));
                                        //App.Current.MainPage = new NavigationPage(new MasterPage());
                                        //App.Current.MainPage.Navigation.PushAsync(new ChatListPage());
                                    }
                                    else if (data.Contains("You have new message from support team") || data.Contains("لديك رسالة جديدة من فريق الدعم"))
                                    {
                                        await NavigationService.NavigateAsync(new Uri("/MasterPage/NavigationPage/HomePage", UriKind.Absolute));
                                        await NavigationService.NavigateAsync(nameof(SupportPage));
                                    }
                                    else if (data.Contains("Your password has been reset by the admin, In order to continue please contact administrator.") || data.Contains("تمت إعادة تعيين كلمة المرور الخاصة بك من قبل المشرف ، للمتابعة ، يرجى الاتصال بالمسؤول") || data.Contains("Your account has been de-activated by the admin, in order to continue please contact administrator") || data.Contains("تم إلغاء تنشيط حسابك من قبل المشرف ، للمتابعة ، يرجى الاتصال بالمسؤول"))
                                    {
                                        if (userDataDbService.IsUserDbPresentInDB())
                                        {
                                            var item = userDataDbService.ReadAllItems().FirstOrDefault();
                                            BsonValue id = item.ID;
                                            userDataDbService.DeleteItemFromDB(id, item);

                                            //App.Current.MainPage = new NavigationPage(new LoginPage());
                                            await NavigationService.NavigateAsync(new Uri("/NavigationPage/LoginPage", UriKind.Absolute));
                                        }
                                    }
                                    else
                                    {
                                        await NavigationService.NavigateAsync(new Uri("/MasterPage/NavigationPage/HomePage", UriKind.Absolute));
                                        await NavigationService.NavigateAsync(nameof(NotificationPage));
                                        //if (Application.Current.Properties.ContainsKey("AppStatus"))
                                        //{
                                        //if (Convert.ToInt32(Application.Current.Properties["AppStatus"]) == Convert.ToInt32(AppStatus.Foreground))
                                        //{
                                        //    App.Current.MainPage.Navigation.PushAsync(new NotificationPage());
                                        //}
                                        //else if (Convert.ToInt32(Application.Current.Properties["AppStatus"]) == Convert.ToInt32(AppStatus.Background))
                                        //{
                                        //    App.Current.MainPage = new NavigationPage(new MasterPage());
                                        //    App.Current.MainPage.Navigation.PushAsync(new NotificationPage());
                                        //}
                                        //}
                                    }
                                });

                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        // Some other exception occurred
                    }
                };

                CrossFirebasePushNotification.Current.OnNotificationAction += (s, p) =>
                {
                    System.Diagnostics.Debug.WriteLine("Action");

                    if (!string.IsNullOrEmpty(p.Identifier))
                    {
                        System.Diagnostics.Debug.WriteLine($"ActionId: {p.Identifier}");
                        foreach (var data in p.Data)
                        {
                            System.Diagnostics.Debug.WriteLine($"{data.Key} : {data.Value}");
                        }

                    }

                };

                CrossFirebasePushNotification.Current.OnNotificationDeleted += (s, p) =>
                {
                    System.Diagnostics.Debug.WriteLine("Dismissed");
                };
            }
        }