示例#1
0
        private async Task ExecuteSaveCommand()
        {
            MyContact contactToBeAdded = new MyContact
            {
                Name        = Name.Value,
                Mobile      = Mobile.Value,
                Landline    = Landline.Value,
                ProfilePic  = ProfilePic.Value,
                IsFavourite = IsFavorite.Value.Equals(UIConstants.UnFavorite),
            };

            int addResult;

            try
            {
                addResult = await dataService.AddContact(contactToBeAdded);
            }
            catch (Exception ex)
            {
                await RootPage.DisplayAlert("Error adding contact", ex.Message, "Hmmmm");

                addResult = -1;
            }

            if (addResult == 1)
            {
                await GoToContactList();
            }
            else if (addResult != -1)
            {
                await RootPage.DisplayAlert("Contacts", "Error adding contact", "Hmmmm");
            }
        }
        private async Task ExecuteFavoriteCommand()
        {
            contactToUpdate.IsFavourite = IsFavorite.Value.Equals(UIConstants.UnFavorite);

            int favoriteToggleResult;

            try
            {
                favoriteToggleResult = await dataService.UpdateContact(contactToUpdate);
            }
            catch (Exception ex)
            {
                await RootPage.DisplayAlert("Error updating favorite.", ex.Message, "Hmmmm");

                IsFavorite.Value     = IsFavorite.Value.Equals(UIConstants.Favorite) ? UIConstants.UnFavorite : UIConstants.Favorite;
                favoriteToggleResult = -1;
            }

            if (Math.Abs(favoriteToggleResult) != 1)
            {
                await RootPage.DisplayAlert("Contacts", "Error updating favorite.", "Hmmmm");

                IsFavorite.Value = IsFavorite.Value.Equals(UIConstants.Favorite) ? UIConstants.UnFavorite : UIConstants.Favorite;
            }
        }
        private async Task ExecuteUpdateCommand()
        {
            contactToUpdate.Name        = Name.Value;
            contactToUpdate.Mobile      = Mobile.Value;
            contactToUpdate.Landline    = Landline.Value;
            contactToUpdate.ProfilePic  = ProfilePic.Value;
            contactToUpdate.IsFavourite = IsFavorite.Value.Equals(UIConstants.UnFavorite);

            int updateResult;

            try
            {
                updateResult = await dataService.UpdateContact(contactToUpdate);
            }
            catch (Exception ex)
            {
                await RootPage.DisplayAlert("Error updating contact.", ex.Message, "Hmmmm");

                updateResult = -1;
            }

            if (updateResult == 1)
            {
                await RootPage.DisplayAlert("Update Contact", $"Contact '{Name.Value}' updated!", "Hmmmm");
                await NavigateSuccess();
            }
            else if (updateResult != -1)
            {
                await RootPage.DisplayAlert("Contacts", "Error updating contact.", "Hmmmm");
            }
        }
        private async Task ExecuteDeleteCommand()
        {
            bool confirmDelete = await RootPage.DisplayAlert("Delete Contact", $"Do you want to delete {contactToUpdate.Name}?", "Hmmm", "No");

            if (!confirmDelete)
            {
                return;
            }

            int deleteResult;

            try
            {
                deleteResult = await dataService.DeleteContact(contactToUpdate);
            }
            catch (Exception ex)
            {
                await RootPage.DisplayAlert("Error deleting contact.", ex.Message, "Hmmmm");

                deleteResult = -1;
            }

            if (deleteResult == 1)
            {
                await RootPage.DisplayAlert("Update Contact", $"Contact '{contactToUpdate.Name}' deleted!", "Hmmmm");
                await NavigateSuccess();
            }
            else if (deleteResult != -1)
            {
                await RootPage.DisplayAlert("Contacts", "Error deleting contact.", "Hmmmm");
            }
        }
        private async Task TakePhoto()
        {
            if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
            {
                await RootPage.DisplayAlert("Take Photo", "Operation not supported.", "Hmmmm");

                return;
            }

            try
            {
                await ClickPhoto();
            }
            catch
            {
                bool permitted = await RequestForRequiredPermissions();

                if (permitted)
                {
                    await TakePhoto();
                }
                else
                {
                    await RootPage.DisplayAlert("Take Photo", "Permission not granted!", "Hmmmm");
                }
            }
        }
示例#6
0
        private async Task <bool> RequestForRequiredPermissions()
        {
            bool choose = await RootPage.DisplayAlert("Update Photo", "Grant Permission to take photo.", "Hmmmm", "No");

            if (choose)
            {
                choose = await CheckCameraAndStoragePermissions();
            }
            return(choose);
        }
示例#7
0
        private async void DisplayAlert()
        {
            RootPage Root = (RootPage)(Xamarin.Forms.Application.Current.MainPage);

            if (await Root.DisplayAlert(
                    StringResources.dialog_notconfigured_title,
                    String.Format(StringResources.dialog_notconfigured_message, serviceName),
                    StringResources.button_showdocs_caption,
                    StringResources.button_close_caption))
            {
                Root.MoveTo(serviceDocPage);
            }
        }
示例#8
0
        public void ShowPopup(PopupExtended popup)
        {
            try
            {
                if (CurrentPopup != null)
                {
                    return;
                }

                if (popup.IsVisible == false)
                {
                    CurrentPopup = popup;
                    BackgroundLayout.BackgroundColor = popup.BackgroundLayerColor;



                    PopupControls.Add(popup.Content);



                    PopupContentLayout = popup.Content;

                    popup.Content = null;
                    grid.Children.Add(PopupControls[0]);



                    if (popup.CloseOnBackGroundClicked)
                    {
                        TapGestureRecognizer tapGestureRecognizer = new TapGestureRecognizer();
                        tapGestureRecognizer.Tapped += TapGestureRecognizer_Tapped;

                        boxView.GestureRecognizers.Add(tapGestureRecognizer);
                    }



                    popup.IsVisible            = true;
                    BackgroundLayout.IsVisible = true;
                    ShowEnterAnimation();

                    CurrentPopup.IsOpen = true;
                }
            }
            catch (Exception ex)
            {
                RootPage.DisplayAlert("Exception", ex.Message, "OK");
            }
        }
示例#9
0
        private async Task GoToContactList()
        {
            await RootPage.DisplayAlert("Add Contact", $"Contact '{Name.Value}' saved", "Hmmmm");

            if (null == contactListMenuItem)
            {
                contactListMenuItem = new HomeMenuItem()
                {
                    Id    = MenuItemType.ContactList,
                    Title = UIConstants.ContactList
                };
            }
            ResetForm();
            await RootPage.NavigateFromMenu(contactListMenuItem);
        }
示例#10
0
        public async Task ClosePopup(PopupExtended popup)
        {
            try
            {
                if (CurrentPopup == null)
                {
                    return;
                }

                if (CurrentPopup.ExitAnimation != AnimationEnum.None)
                {
                    await ShowExitAnimation();
                }
            }
            catch (Exception ex)
            {
                await RootPage.DisplayAlert("Exception", ex.Message, "OK");
            }
        }
示例#11
0
        public static async Task <bool> LoadReferenceData()
        {
            bool IsSuccessful = false;

            try
            {
                var referenceDataservice = DependencyResolver.Resolve <IReferenceDataService>();
                IsSuccessful = await referenceDataservice.LoadLocations();

                if (!IsSuccessful)
                {
                    await RootPage.DisplayAlert(ErrorMessages.ErrorType.Error.ToString(), ErrorMessages.ErrorLoadingReferenceData, ErrorMessages.MesssageButton.Ok.ToString());
                }
            }
            catch (Exception ex)
            {
                Insights.Report(new Exception("Error Loading reference data", ex));
            }
            return(IsSuccessful);
        }
示例#12
0
        private async Task ChoosePhoto()
        {
            await CrossMedia.Current.Initialize();

            try
            {
                await ChoosePhotoInner();
            }
            catch
            {
                bool permitted = await RequestForRequiredPermissions();

                if (permitted)
                {
                    await ChoosePhoto();
                }
                else
                {
                    await RootPage.DisplayAlert("Choose Photo", "Permission not granted", "Hmmmm");
                }
            }
        }
示例#13
0
        private static void InitNavigation()
        {
            var navigation = RootPage.Navigation;

            RootPage.Subscribe <NavigateBackMessage>(async delegate { await navigation.PopAsync(); });

            RootPage.Subscribe <NavigateToPageMessage>(
                message =>
            {
                navigation.PushAsync(message.Page, true);
            });

            RootPage.Subscribe <LoginSuccess>(async message =>
            {
                var pageToNaviagte = message.FirstTimeLogin ?
                                     ViewFactory <PreferencesPage, PreferencesViewModel> .CreatePage() as Page
                            : ViewFactory <HomePage, HomeViewModel> .CreatePage();

                await navigation.PopToRootAsync();
                await navigation.PushAsync(pageToNaviagte, true);
            });

            RootPage.Subscribe <LoginCanceled>(async message =>
            {
                await navigation.PushAsync(new WelcomePage());
            });

            RootPage.Subscribe <LoginFailed>(
                async(x) =>
            {
                await RootPage.DisplayAlert("Login failed", "Login failed !", "Ok");
            });
            RootPage.Subscribe <LogoutSuccess>(message =>
            {
                navigation.PopToRootAsync(true);
            });
        }
示例#14
0
        private static void InitNavigation()
        {
            var navigation = RootPage.Navigation;

            RootPage.Subscribe <NavigateBackMessage>(async delegate
            {
                await navigation.PopAsync();
            });

            RootPage.Subscribe <NavigateToPageMessage>(
                async message =>
            {
                if (message.IsModal)
                {
                    await navigation.PushModalAsync(message.Page, true);
                    return;
                }
                await navigation.PushAsync(message.Page, true);
            });

            RootPage.Subscribe <NavigateToSettingsPage>(async message => await navigation.PushAsync(message.Page, true));

            RootPage.Subscribe <LoginSuccess>(async message =>
            {
                if (CurrentUserProfile == null)
                {
                    await navigation.PopToRootAsync();

                    RootPage.Publish(new NavigateToSettingsPage());
                    return;
                }

                await navigation.NavigateToPage <HomePage, HomeViewModel>();
            });

            RootPage.Subscribe <LoginCanceled>(async message =>
            {
                await navigation.PushAsync(new WelcomePage());
            });

            RootPage.Subscribe <LoginFailed>(
                async(x) =>
            {
                await RootPage.DisplayAlert("Login failed", "Login failed !", "Ok");
            });
            RootPage.Subscribe <LogoutSuccess>(async message =>
            {
                await navigation.NavigateToPage <WelcomePage, WelcomeViewModel>();
            });

            RootPage.Subscribe <CloseModal>(async message =>
            {
                await navigation.PopModalAsync(true);
            });
            RootPage.Subscribe <NavigateToHomePage>(async message =>
            {
                await navigation.NavigateToPage <HomePage, HomeViewModel>();
            });

            RootPage.Subscribe <ShowLoading>(async message =>
            {
                var loadingPage = new Loading();
                await navigation.PushModalAsync(loadingPage, true);
            });

            RootPage.Subscribe <HideLoading>(async message =>
            {
                await navigation.PopToRootAsync(true);
            });
        }
示例#15
0
 public static Task DisplayAlertAsync(string title, string message, string cancel)
 {
     return(RootPage.DisplayAlert(title, message, cancel));
 }