public ModalAssignMemberWorkoutPage(SimpleTemplate template) { this.template = template; Label textLabel = new Label { Text = template.TemplateName, FontSize = 45 }; Label editorLabel = new Label { Text = template.TemplateDescription, FontSize = 35 }; Label addMemberLabel = new Label { Text = "Add Member" }; addMemberEntry = new CustomEntry { Placeholder = "Search Member", HeightRequest = 35, HorizontalOptions = LayoutOptions.FillAndExpand }; StackLayout addMemberEntryLayout = new StackLayout { Children = { addMemberEntry }, }; ListView listView = new ListView { ItemTemplate = new DataTemplate(typeof(CustomViewThreeTextCell)), IsVisible = false }; listView.ItemSelected += listView_ItemSelected; submitButton = new Button { Image = "assign_green_button.png", HeightRequest = 35, WidthRequest = 100 }; cancel2Button = new Button { Image = "cancel_button.png", HeightRequest = 35, WidthRequest = 100 }; activityIndicator = new ActivityIndicator { IsRunning = false, Color = Color.Red }; cancel2Button.Clicked += async (sender2, args2) => { submitButton.IsEnabled = true; activityIndicator.IsRunning = false; await Navigation.PopModalAsync(); }; submitButton.Clicked += async (sender2, args2) => { if ((addMemberEntry.Text != null && addMemberEntry.Text != "") && selectedUser == null) { await this.DisplayAlert("Validation", "Select another member. This member is not recognized.", "OK"); } else { if (selectedUser != null) { String[] nameArray = addMemberEntry.Text.Split(' '); if (nameArray.Count() > 0) { if (!(selectedUser.FirstName == nameArray[0] && selectedUser.LastName == nameArray[1])) { await this.DisplayAlert("Validation", "Select another member or delete the member entirely.", "OK"); } else { await WriteToRepository(); } } } else { await this.DisplayAlert("Validation", "Select another member. This member is not recognized.", "OK"); } } }; StackLayout buttonStack = new StackLayout { Children = { submitButton, cancel2Button }, Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, Padding = new Thickness(20) }; StackLayout modalStack = new StackLayout { Children = { // pageTitle, textLabel, editorLabel, addMemberLabel, addMemberEntryLayout, listView, buttonStack }, Orientation = StackOrientation.Vertical, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, Padding = new Thickness(20) }; addMemberEntry.TextChanged += async (sender, args) => { var searchResults = await Manager.Instance.User.UserSeach(addMemberEntry.Text, App.WorkoutCreatorContext.StaffMember.GymID); listView.ItemsSource = searchResults; var rowHeight = 40; listView.RowHeight = rowHeight; listView.HeightRequest = (rowHeight * searchResults.Count()); modalStack.WidthRequest = this.Width * .7; listView.VerticalOptions = LayoutOptions.StartAndExpand; listView.HorizontalOptions = LayoutOptions.StartAndExpand; listView.IsVisible = true; }; //this.BackgroundColor = Color.FromRgb(135, 206, 250); this.Content = modalStack; }
public LoginPage() { this.Title = "MobileFiT Coach"; _viewModel = new SimpleLogin (Manager.Instance.StaffMember, ExerciseService.ServiceAPI, Manager.Instance.ErrorLog); Image logoImage = new Image { Source = ImageSource.FromResource("WorkoutCreator.Images.mainpagelogo.png"), HorizontalOptions = LayoutOptions.FillAndExpand, Aspect = Aspect.AspectFill, HeightRequest = 167, WidthRequest = 225 }; AbsoluteLayout simpleLayout = new AbsoluteLayout { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, }; // PositionProportional flag maps the range (0.0, 1.0) to // the range "flush [left|top]" to "flush [right|bottom]" AbsoluteLayout.SetLayoutFlags(logoImage, AbsoluteLayoutFlags.PositionProportional); Rectangle imageRectangle = new Rectangle(0.5, 0.5, logoImage.Height, logoImage.Width); AbsoluteLayout.SetLayoutBounds(logoImage, imageRectangle); simpleLayout.Children.Add(logoImage); Label pageTitle = new Label { Text = "Facility Login", FontSize = 40 }; Label usernameLabel = new Label { Text = "Username:"******"Enter Username", HeightRequest = 35 }; Label passwordLabel = new Label { Text = "Password:"******"Enter Password", IsPassword = true, HeightRequest = 35 }; Button loginButton = new Button { Text = "Login", }; ActivityIndicator activityIndicator = new ActivityIndicator { Color = Color.Red, IsRunning = false }; loginButton.Clicked += async (sender2, args2) => { activityIndicator.IsRunning = true; loginButton.IsEnabled = false; if (string.IsNullOrEmpty(usernameEntry.Text)) { activityIndicator.IsRunning = false; await this.DisplayAlert("Validation", "Input a username.", "OK"); } else { if (string.IsNullOrEmpty(passwordEntry.Text)) { activityIndicator.IsRunning = false; await this.DisplayAlert("Validation", "Input a password.", "OK"); } else { String loginResponse = await _viewModel.Login(usernameEntry.Text, passwordEntry.Text); if(!string.IsNullOrEmpty(loginResponse) || loginResponse == StringConstants._ConnectivityFailedValidationPrompt || loginResponse == StringConstants._AuthenticationFailedValidationPrompt ) { if(loginResponse == StringConstants._ConnectivityFailedValidationPrompt) { await this.DisplayAlert("Validation", StringConstants._ConnectivityFailedValidationPrompt, "OK"); }else { if(loginResponse == StringConstants._AuthenticationFailedValidationPrompt) { await this.DisplayAlert("Validation", StringConstants._AuthenticationFailedValidationPrompt, "OK"); } else { await this.DisplayAlert("Validation", "Unable to authenticate. Please try again.", "OK"); } } } else { usernameEntry.Text = ""; passwordEntry.Text = ""; Task task = _viewModel.SetLogginInUserContext(); Action<Task> action = (actionResult) => Device.BeginInvokeOnMainThread (async() => { Task<bool> taskResponder = null; if(App.WorkoutCreatorContext.StaffMember != null && App.WorkoutCreatorContext.StaffMember.GymID != 0) { taskResponder = App.RunBackroundSync(); } loginButton.IsEnabled = true; await Navigation.PushAsync(new PrimaryOptionsPage(taskResponder)); }); task.ContinueWith(action).ConfigureAwait(false); } activityIndicator.IsRunning = false; } } }; StackLayout nestedStack = new StackLayout { Children = { pageTitle, usernameLabel, usernameEntry, passwordLabel, passwordEntry, activityIndicator, loginButton }, Orientation = StackOrientation.Vertical, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.FillAndExpand, WidthRequest = 400, Padding = new Thickness(10), Spacing = 10 }; AbsoluteLayout.SetLayoutFlags(nestedStack, AbsoluteLayoutFlags.PositionProportional); AbsoluteLayout.SetLayoutBounds(nestedStack, new Rectangle(0.5, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize)); StackLayout modalStack = new StackLayout { Children = { simpleLayout, nestedStack }, Orientation = StackOrientation.Vertical, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, Padding = new Thickness(10) }; this.BackgroundColor = Color.FromRgb(135, 206, 250); this.Content = modalStack; }