public MasterPage(MasterPageVM vm) { VM = vm ?? new MasterPageVM(); BindingContext = VM; Title = "Menu"; Icon = "menu"; var buttLogin = new Button { Command = new Command(async() => { if (VM.IsLogged == false) { var pageVM = new LoginPageVM(); pageVM.DownloadData().ContinueWith((arg) => { pageVM.UpdateVM(); }); pageVM.Completed += async(object sender, User e) => { //detail = profilePage GoToEventsPage(); }; VM.Navigation = new NavigationPage(new LoginPageView(pageVM)); } else { //doing logout App.VM.user = null; await App.VM.Settings.Save(); } }) }; //buttLogin.SetBinding(View.IsVisibleProperty, new Binding(nameof(MasterPageVM.IsLogged), BindingMode.Default, new NegateBooleanConverter())); buttLogin.SetBinding(Button.TextProperty, new Binding(nameof(MasterPageVM.IsLoggedString))); var userImg = new Image { HeightRequest = 64, WidthRequest = 64 }; userImg.Bind(nameof(MasterPageVM.UserImg)); var userName = new Label { HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.Center }; userName.Bind(nameof(MasterPageVM.UserName), true); var buttonCalendario = new Button { Text = "Prenotazione" }; buttonCalendario.Clicked += delegate { var pageVM = new CalendarioPageVM(); pageVM.DownloadData().ContinueWith(delegate { pageVM.UpdateVM(); }); VM.Navigation = new NavigationPage(new CalendarioPage(pageVM)); }; var buttonAbout = new Button { Text = "About" }; buttonAbout.Clicked += (sender, e) => { var pageVM = new AboutPageVM(); pageVM.DownloadData().ContinueWith(delegate { pageVM.UpdateVM(); }); VM.Navigation = new NavigationPage(new AboutPage(pageVM)); }; Content = new StackLayout { Children = { new BoxView { HeightRequest = 20, Color = Color.Transparent, BackgroundColor = Color.Transparent }, userImg, userName, buttLogin, new Button { Text = "Eventi", Command = new Command(() =>{ GoToEventsPage(); }) }, buttonCalendario, buttonAbout, } }; }
public LoginPageView(LoginPageVM vm) { VM = vm ?? new LoginPageVM(); BindingContext = VM; var user = new EntryWithLabelV2 { LabelText = "Email" }; user.Element.Keyboard = Keyboard.Email; user.Bind(nameof(LoginPageVM.Username)); var pass = new EntryWithLabelV2 { LabelText = "Password" }; pass.Element.IsPassword = true; pass.Bind(nameof(LoginPageVM.Password)); var loadingText = new Label { Text = "Caricamento in corso", HorizontalTextAlignment = TextAlignment.Center }; loadingText.SetBinding(View.IsVisibleProperty, nameof(ViewModelBase.IsLoadingData)); //var loadingIndicator = new ActivityIndicator { Color=Color.Black }; //loadingIndicator.Bind(nameof(LoginPageVM.IsLoadingData)); var buttLogin = new Button { Text = "Login" }; buttLogin.Clicked += async delegate { VM.IsLoadingData = true; try { var data = await VM.GetDataFromMoodle(VM.Username, VM.Password); if (data == null) { await App.Current.MainPage.DisplayAlert("Error", "Wrong login", "Retry"); return; } var loginResult = await VM.DoLogin(data); if (loginResult.state != WebServiceV2.WebRequestState.Ok) { await App.Current.MainPage.DisplayAlert("Error", loginResult.errorMessage, "back"); } else { //già ci pensa DoLogin a salvare VM.OnCompleted(App.VM.user); } } finally { VM.IsLoadingData = false; } }; Content = new StackLayout { Spacing = 35, Children = { loadingText, new BoxView { HeightRequest = 50 }, user, pass, buttLogin } }; }