示例#1
0
        public MainPage()
        {
            //ASYNC AND DEFFERED creation of controls for better start-up time

            createMinimalUiTask = Task.Run(() =>
            {
                ApplyTheme();
                this.BackgroundColor = backgroundColor;

                title              = new Title();
                title.QuitClicked += OnQuit;

                if (ViewModelContainer.NavigationViewModel.IsSimpleUI)
                {
                    simpleUI = new SimpleUI();
                    simpleUI.AdjustToWidth(Width);
                }
                else
                {
                    advancedUI = new AdvancedUI();
                    status     = new Status();
                }
            });

            InitializeComponent();

            On <Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);

            createMinimalUiTask.Wait();

            createRestOfUiTask = Task.Run(() =>
            {
                simpleUIHeader = new SimpleUI();

                simpleUIHeader.SetBinding(IsVisibleProperty, new Binding("IsSimpleUIHeaderVisible", source: ViewModelContainer.NavigationViewModel));
                AbsoluteLayout.SetLayoutFlags(simpleUIHeader, AbsoluteLayoutFlags.None);
                simpleUIHeader.HorizontalOptions = LayoutOptions.CenterAndExpand;

                testInProgress          = new TestInProgress();
                testCompletion          = new TestCompletion();
                testSessionsPlaceholder = new TestSessionsPlaceholder();
                popups   = new Popups();
                onlineDb = new OnlineDb();

                if (ViewModelContainer.NavigationViewModel.IsSimpleUI)
                {
                    advancedUI = new AdvancedUI();
                    status     = new Status();
                }
                else
                {
                    simpleUI = new SimpleUI();
                }
            });

            stackLayout.Children.Add(title);
            if (ViewModelContainer.NavigationViewModel.IsSimpleUI)
            {
                absoluteLayout.Children.Add(simpleUI);
            }
            else
            {
                stackLayout.Children.Add(advancedUI);
                stackLayout.Children.Add(status);
            }

            // DISPLAYING CONTROLS HERE
            SizeChanged += (s, e) =>
            {
                if (alreadyShown)
                {
                    AdaptLayoytToScreenWidth();
                }
                else
                {
                    alreadyShown = true;

                    createRestOfUiTask.Wait();
                    AdaptLayoytToScreenWidth();

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        if (ViewModelContainer.NavigationViewModel.IsSimpleUI)
                        {
                            stackLayout.Children.Add(simpleUIHeader);
                            stackLayout.Children.Add(advancedUI);
                        }
                        else
                        {
                            absoluteLayout.Children.Add(simpleUI);
                            stackLayout.Children.Remove(status);
                            stackLayout.Children.Add(simpleUIHeader);
                        }

                        stackLayout.Children.Add(testInProgress);
                        stackLayout.Children.Add(testSessionsPlaceholder);
                        stackLayout.Children.Add(status);
                        absoluteLayout.Children.Add(popups);
                        absoluteLayout.Children.Add(testCompletion);

                        foreach (var c in onlineDb.Children.ToArray())
                        {
                            absoluteLayout.Children.Add(c);
                        }
                    });
                }
            };
        }
示例#2
0
        public MainPage()
        {
            //ASYNC AND DEFFERED creation of controls for better start-up time

            createMinimalUiTask = Task.Run(() =>
            {
                ApplyTheme();

                if (ViewModelContainer.NavigationViewModel.IsSimpleUI)
                {
                    simpleUI = new SimpleUI();
                }
                else
                {
                    advancedUI = new AdvancedUI();
                    status     = new Status();
                }
            });

            InitializeComponent();
            // Do not touch this page's control until InitilizeComponent is done
            title              = new Title();
            title.QuitClicked += OnQuit;

            On <Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);

            createMinimalUiTask.Wait();

            this.BackgroundColor = backgroundColor;

            createRestOfUiTask = Task.Run(() =>
            {
                simpleUIHeader = new SimpleUI();

                simpleUIHeader.SetBinding(IsVisibleProperty, new Binding("IsSimpleUIHeaderVisible", source: ViewModelContainer.NavigationViewModel));
                AbsoluteLayout.SetLayoutFlags(simpleUIHeader, AbsoluteLayoutFlags.None);
                simpleUIHeader.HorizontalOptions = LayoutOptions.CenterAndExpand;

                testInProgress          = new TestInProgress();
                testCompletion          = new TestCompletion();
                testSessionsPlaceholder = new TestSessionsPlaceholder();
                popups = new Popups();

                onlineDb = new OnlineDb();

                if (ViewModelContainer.NavigationViewModel.IsSimpleUI)
                {
                    advancedUI = new AdvancedUI();
                    status     = new Status();
                }
                else
                {
                    simpleUI = new SimpleUI();
                }
            });

            stackLayout.Children.Add(title);
            if (ViewModelContainer.NavigationViewModel.IsSimpleUI)
            {
                absoluteLayout.Children.Add(simpleUI);
            }
            else
            {
                stackLayout.Children.Add(advancedUI);
                stackLayout.Children.Add(status);
            }

            // DISPLAYING CONTROLS HERE
            SizeChanged += (s, e) =>
            {
                if (alreadyShown)
                {
                    AdaptLayoytToScreenWidth();
                }
                else
                {
                    alreadyShown = true;

                    createRestOfUiTask.Wait();
                    AdaptLayoytToScreenWidth();

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        if (ViewModelContainer.NavigationViewModel.IsSimpleUI)
                        {
                            stackLayout.Children.Add(simpleUIHeader);
                            stackLayout.Children.Add(advancedUI);
                        }
                        else
                        {
                            absoluteLayout.Children.Add(simpleUI);
                            stackLayout.Children.Remove(status);
                            stackLayout.Children.Add(simpleUIHeader);
                        }

                        stackLayout.Children.Add(testInProgress);
                        stackLayout.Children.Add(testSessionsPlaceholder);
                        stackLayout.Children.Add(status);
                        absoluteLayout.Children.Add(popups);
                        absoluteLayout.Children.Add(testCompletion);

                        // From time to time devices don't have webview installed or properly configured, this may lead to app crash
                        try
                        {
                            foreach (var c in onlineDb.Children.ToArray())
                            {
                                absoluteLayout.Children.Add(c);
                            }
                        }
                        catch { advancedUI.MakeDbButtonRedirecting(); };

                        var now = DateTime.Now;
                        if ((now.Month == 12 && now.Day >= 20) || (now.Month == 1 && now.Day <= 10))
                        {
                            var lbl = new Label()
                            {
                                Text = "🎄", FontSize = 26
                            };
                            lbl.SetBinding(IsVisibleProperty, new Binding("IsSimpleUIStartPageVisible", source: ViewModelContainer.NavigationViewModel));
                            AbsoluteLayout.SetLayoutBounds(lbl, new Rectangle(0.5, 0.75, 40, 40));
                            AbsoluteLayout.SetLayoutFlags(lbl, AbsoluteLayoutFlags.PositionProportional);
                            absoluteLayout.Children.Add(lbl);
                        }
                    });
                }
            };
        }