Exemple #1
0
 void RemoveToolbarItem(CustomToolbarItem oldItem)
 {
     if (oldItem.Parent is StackLayout stackLayout)
     {
         stackLayout.Children.Remove(oldItem);
     }
 }
        public BoardPage(OWBoard board) : base()
        {
            Board = board;

            //board.StartLogging();
            InitializeComponent();
            BindingContext = board;

            AppVersionLabel.Text = $"{AppInfo.VersionString} (build {AppInfo.BuildString})";

            ImperialSwitch.IsToggled = !App.Current.MetricDisplay;


            Board.Init();
            // I really don't like this.
            _ = Board.SubscribeToBLE();

            App.Current.OWBLE.BoardDisconnected += OWBLE_BoardDisconnected;
            App.Current.OWBLE.BoardReconnecting += OWBLE_BoardReconnecting;
            App.Current.OWBLE.BoardReconnected  += OWBLE_BoardReconnected;

            // Shift title to the right.
            var titleLabel = GetTitleLabel();

            titleLabel.HorizontalOptions = LayoutOptions.End;
            titleLabel.Padding           = new Thickness(0, 0, 16, 0);


            var settingsToolbarItem = new CustomToolbarItem()
            {
                Position        = CustomToolbarItemPosition.Left,
                IconImageSource = "burger_menu",
                Command         = new Command(() =>
                {
                    PopupNavigation.Instance.PushAsync(SettingsPopupPage);
                }),
            };

            CustomToolbarItems.Add(settingsToolbarItem);
        }
Exemple #3
0
        void AddToolbarItem(CustomToolbarItem newItem)
        {
            if (newItem.Parent != null)
            {
                return;
            }

            if (newItem.Position == CustomToolbarItemPosition.Left)
            {
                SetupLeftNavStackLayout();

                if (_leftNavStackLayout.Children.Count == 0)
                {
                    _leftNavStackLayout.Children.Add(newItem);
                }
                else
                {
                    for (int i = 0; i < _leftNavStackLayout.Children.Count; ++i)
                    {
                        if (_leftNavStackLayout.Children[i] is CustomToolbarItem customToolbarItem)
                        {
                            if (newItem.Priority > customToolbarItem.Priority)
                            {
                                _leftNavStackLayout.Children.Insert(i, newItem);
                                break;
                            }
                        }
                    }

                    if (newItem.Parent != null)
                    {
                        _leftNavStackLayout.Children.Add(newItem);
                    }
                }
            }
            else if (newItem.Position == CustomToolbarItemPosition.Right)
            {
                SetupRightNavStackLayout();

                if (_rightNavStackLayout.Children.Count == 0)
                {
                    _rightNavStackLayout.Children.Add(newItem);
                }
                else
                {
                    for (int i = _rightNavStackLayout.Children.Count - 1; i >= 0; --i)
                    {
                        if (_rightNavStackLayout.Children[i] is CustomToolbarItem customToolbarItem)
                        {
                            if (newItem.Priority > customToolbarItem.Priority)
                            {
                                _rightNavStackLayout.Children.Insert(i + 1, newItem);
                                break;
                            }
                        }
                    }

                    if (newItem.Parent != null)
                    {
                        _rightNavStackLayout.Children.Add(newItem);
                    }
                }
            }
        }
        public BoardListPage() : base()
        {
            InitializeComponent();
            BindingContext = this;

            _scanningView = new Grid()
            {
                HorizontalOptions = LayoutOptions.End,
                ColumnDefinitions = new ColumnDefinitionCollection()
                {
                    new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Auto)
                    },
                    new ColumnDefinition()
                    {
                        Width = new GridLength(26, GridUnitType.Absolute)
                    },
                },
                ColumnSpacing = 18,
            };
            _scanningView.BindingContext = App.Current.OWBLE;
            _scanningView.SetBinding(Grid.IsVisibleProperty, "IsScanning");

            var scanningLabel = new Label()
            {
                Text              = "Scanning...",
                TextColor         = Color.Black,
                FontFamily        = "SairaExtraCondensed-SemiBold",
                FontSize          = 24,
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.End,
            };

            var scanningActivityIndicator = new ActivityIndicator()
            {
                WidthRequest      = 26,
                HeightRequest     = 26,
                Color             = Color.Black,
                IsRunning         = true,
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.End,
            };

            Grid.SetColumn(scanningLabel, 0);
            Grid.SetColumn(scanningActivityIndicator, 1);

            _scanningView.Children.Add(scanningLabel);
            _scanningView.Children.Add(scanningActivityIndicator);

            var scanningToolbarItem = new CustomToolbarItem();

            scanningToolbarItem.Content = _scanningView;
            CustomToolbarItems.Add(scanningToolbarItem);

#if DEBUG
            var popupPage = new Rg.Plugins.Popup.Pages.PopupPage();

            // Secret debug menu.
            var debugToolbarItem = new CustomToolbarItem()
            {
                Position        = CustomToolbarItemPosition.Left,
                IconImageSource = "burger_menu",
                Command         = new Command(() =>
                {
                    var debugMenu = new Popup.DebugBoardListPageSettingPopup();

                    PopupNavigation.Instance.PushAsync(debugMenu);
                }),
            };
            CustomToolbarItems.Add(debugToolbarItem);
#endif

            /*
             #if DEBUG
             * var rand = new Random();
             * Boards.Add(new MockOWBoard($"ow{rand.Next(111111, 999999)}", OWBoardType.V1));
             * Boards.Add(new MockOWBoard($"ow{rand.Next(111111, 999999)}", OWBoardType.Plus));
             * Boards.Add(new MockOWBoard($"ow{rand.Next(111111, 999999)}", OWBoardType.XR));
             * Boards.Add(new MockOWBoard($"ow{rand.Next(111111, 999999)}", OWBoardType.Pint));
             * Boards.Add(new MockOWBoard($"ow{rand.Next(111111, 999999)}", OWBoardType.Unknown));
             #endif
             */
        }