예제 #1
0
        public CalendarioPage(CalendarioPageVM vm)
        {
            VM             = vm ?? new CalendarioPageVM();
            VM.UIPage      = this;
            BindingContext = VM;

            var calendar = new SfSchedule {
                ShowAppointmentsInline = true,
                ScheduleView           = ScheduleView.WeekView
            };

            #region Customization
            var headerStyle = new HeaderStyle();
            //headerStyle.TextSize = 15;
            //headerStyle.TextStyle
            headerStyle.TextColor = Color.Black;
            calendar.HeaderStyle  = headerStyle;
            #endregion

            ScheduleAppointmentMapping dataMapping = new ScheduleAppointmentMapping();
            dataMapping.SubjectMapping   = nameof(GoogleEventVM.Title);
            dataMapping.StartTimeMapping = nameof(GoogleEventVM.StartDate);
            dataMapping.EndTimeMapping   = nameof(GoogleEventVM.EndDate);
            dataMapping.ColorMapping     = nameof(GoogleEventVM.BackgroundColor);
            calendar.AppointmentMapping  = dataMapping;

            calendar.ScheduleCellTapped += async(object sender, ScheduleTappedEventArgs args) =>
            {
                var data   = args;
                var fine   = args.datetime.Add(TimeSpan.FromMinutes(calendar.TimeInterval));
                var events = VM.GetEventsFromDateTime(args.datetime, TimeSpan.FromMinutes(calendar.TimeInterval));
                if (events != null && events.Count > 0)
                {
                    var IsNuovoEvento       = false;
                    var stringaCrea         = "Crea evento";
                    var eventiListaStringhe = events.Select(x => x.Name).ToList();
                    eventiListaStringhe.Add(stringaCrea);

                    var stringaScelta = await DisplayActionSheet("Quale evento?", "Nessuno", null, eventiListaStringhe.ToArray());

                    if (stringaScelta == stringaCrea)
                    {
                        IsNuovoEvento = true;
                        await DoCrea(args.datetime, fine);

                        return;
                    }


                    var eventoScelto = VM.EventsObj.FirstOrDefault(x => x.Name == stringaScelta);
                    if (eventoScelto != null)
                    {
                        if (App.VM.user != null)
                        {
                            //se è modificabile, aprilo in edit
                            var eventoInterno = VM.EventiInterniObj.FirstOrDefault(x => x.data.RelatedGoogleEventID == eventoScelto.ID);
                            if (IsNuovoEvento || (eventoInterno != null && eventoInterno.data.RelatedOwnerGuid == App.VM.user.Guid))
                            {
                                var pageEditVM = new EventDetailEditVM {
                                    CalendarioVM = VM, ObjEvent = eventoScelto, ObjInternalEvent = eventoInterno,
                                    ObjAllEvents = VM.EventsObj
                                };
                                pageEditVM.DownloadData(false).ContinueWith(delegate {
                                    pageEditVM.UpdateVM();
                                });
                                await Navigation.PushAsync(new EventDetailViewEdit(pageEditVM));
                            }
                            else
                            {                              //altrimenti, aprilo in read only
                                var pageViewVM = new EventDetailViewModel {
                                    ObjEvent = eventoScelto
                                };
                                pageViewVM.DownloadData().ContinueWith(delegate
                                {
                                    pageViewVM.UpdateVM();
                                });
                                await Navigation.PushAsync(new EventDetailView(pageViewVM));
                            }
                        }
                        else
                        {                          //altrimenti, aprilo in read only
                            var pageViewVM = new EventDetailViewModel {
                                ObjEvent = eventoScelto
                            };
                            pageViewVM.UpdateVM();                             //non c'è bisogno qui di fare il download data perchè già ho gli oggetti interi che sto passando
                            await Navigation.PushAsync(new EventDetailView(pageViewVM));
                        }
                    }
                    else
                    {
                        //se non ho scelto nessun evento torna indietro
                        return;
                    }
                }
                else if (events == null || events.Count == 0)
                {
                    //se non ci sono già eventi in questa fascia oraria, permettine la creazione
                    await DoCrea(args.datetime, fine);
                }
            };
            //var listaVacanze = new List<DateTime> { };
            //listaVacanze.Add(DateTime.Now);
            //calendar.BlackoutDates = listaVacanze;

            calendar.SetBinding(SfSchedule.DataSourceProperty, new Binding(nameof(CalendarioPageVM.Items)));


            var loadingText = new Label {
                Text = "Caricamento in corso", HorizontalTextAlignment = TextAlignment.Center
            };
            loadingText.SetBinding(View.IsVisibleProperty, nameof(ViewModelBase.IsLoadingData));

            var grid = new Grid {
                RowDefinitions = new RowDefinitionCollection {
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Star
                    },
                }
            };
            grid.AddChild(loadingText, 0, 0);
            grid.AddChild(calendar, 1, 0);
            this.Content = grid;
        }
예제 #2
0
        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,
                }
            };
        }