Exemplo n.º 1
0
        private void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            SensusDetailPageItem selectedDetailPageItem = e.SelectedItem as SensusDetailPageItem;

            if (selectedDetailPageItem != null)
            {
                Detail = new NavigationPage((Page)Activator.CreateInstance(selectedDetailPageItem.TargetType));
                _masterPage.MasterPageItemsListView.SelectedItem = null;
                IsPresented = false;
            }
        }
Exemplo n.º 2
0
        public SensusMasterDetailPage()
        {
            _masterPage = new SensusMasterPage();

            _masterPage.MasterPageItemsListView.ItemSelected += (sender, e) =>
            {
                try
                {
                    SensusDetailPageItem selectedDetailPageItem = e.SelectedItem as SensusDetailPageItem;

                    if (selectedDetailPageItem != null)
                    {
                        if (selectedDetailPageItem.TargetType == null)
                        {
                            selectedDetailPageItem.Action?.Invoke();
                        }
                        else
                        {
                            Detail      = new NavigationPage((Page)Activator.CreateInstance(selectedDetailPageItem.TargetType));
                            IsPresented = false;
                        }

                        _masterPage.MasterPageItemsListView.SelectedItem = null;
                    }
                }
                catch (Exception ex)
                {
                    SensusException.Report("Exception while handling master-detail menu selection:  " + ex.Message, ex);
                }
            };

            Master = _masterPage;

            // the SensusServiceHelper is not yet loaded when this page is constructed. as a result, we cannot assign the
            // ProtocolsPage to the Detail property. instead, just assign a blank content page and show the user the master
            // detail list. by the time the user selects from the list, the service helper will be available and the protocols
            // page will be ready to go.
            Detail = new NavigationPage(new ContentPage
            {
                Content = new Label
                {
                    Text                    = "Welcome to Sensus." + Environment.NewLine + "Please select from the menu above.",
                    FontSize                = 30,
                    HorizontalOptions       = LayoutOptions.CenterAndExpand,
                    VerticalOptions         = LayoutOptions.CenterAndExpand,
                    VerticalTextAlignment   = TextAlignment.Center,
                    HorizontalTextAlignment = TextAlignment.Center
                }
            });

            IsPresented = true;
        }
Exemplo n.º 3
0
        public SensusMasterPage()
        {
            List <SensusDetailPageItem> detailPageItems = new List <SensusDetailPageItem>();

            detailPageItems.Add(new SensusDetailPageItem
            {
                Title      = "Studies",
                IconSource = "studies.png",
                TargetType = typeof(ProtocolsPage)
            });

            detailPageItems.Add(new SensusDetailPageItem
            {
                Title      = "Surveys",
                IconSource = "surveys.png",
                TargetType = typeof(PendingScriptsPage)
            });

            detailPageItems.Add(new SensusDetailPageItem
            {
                Title      = "Privacy Policy",
                IconSource = "privacy.png",
                TargetType = typeof(PrivacyPolicyPage)
            });

            SensusDetailPageItem accountItem = new SensusDetailPageItem
            {
                Title      = "Log In",
                IconSource = "account.png"
            };

            accountItem.Action = () =>
            {
                if (accountItem.Title == "Log Out")
                {
                    SensusContext.Current.IamRegion          = null;
                    SensusContext.Current.IamAccessKey       = null;
                    SensusContext.Current.IamAccessKeySecret = null;
                    accountItem.Title = "Log In";
                }
                else
                {
                    SensusContext.Current.MainThreadSynchronizer.ExecuteThreadSafe(async() =>
                    {
                        Input input = await SensusServiceHelper.Get().PromptForInputAsync("Log In", new QrCodeInput(QrCodePrefix.IAM_CREDENTIALS, "Account:  ", true, "Please scan your account barcode."), null, true, null, null, null, null, false);

                        if (input == null)
                        {
                            return;
                        }

                        string error = null;

                        string credentials = input.Value?.ToString();
                        if (string.IsNullOrWhiteSpace(credentials))
                        {
                            error = "Empty credentials barcode.";
                        }
                        else
                        {
                            string[] parts = credentials.Split(':');
                            if (parts.Length == 3)
                            {
                                SensusContext.Current.IamRegion          = parts[0];
                                SensusContext.Current.IamAccessKey       = parts[1];
                                SensusContext.Current.IamAccessKeySecret = parts[2];
                            }
                            else
                            {
                                error = "Invalid credentials barcode.";
                            }
                        }

                        if (error == null)
                        {
                            accountItem.Title = "Log Out";
                            await SensusServiceHelper.Get().FlashNotificationAsync("Logged in.");
                        }
                        else
                        {
                            await SensusServiceHelper.Get().FlashNotificationAsync(error);
                        }
                    });
                }
            };

            detailPageItems.Add(accountItem);

            _masterPageItemsListView = new ListView(ListViewCachingStrategy.RecycleElement)
            {
                ItemsSource  = detailPageItems,
                ItemTemplate = new DataTemplate(() =>
                {
                    Grid grid = new Grid {
                        Padding = new Thickness(5, 10)
                    };
                    grid.ColumnDefinitions.Add(new ColumnDefinition {
                        Width = new GridLength(30)
                    });
                    grid.ColumnDefinitions.Add(new ColumnDefinition {
                        Width = GridLength.Star
                    });

                    Image image = new Image();
                    image.SetBinding(Image.SourceProperty, nameof(SensusDetailPageItem.IconSource));

                    Label label = new Label {
                        VerticalOptions = LayoutOptions.FillAndExpand
                    };
                    label.SetBinding(Label.TextProperty, nameof(SensusDetailPageItem.Title));

                    grid.Children.Add(image);
                    grid.Children.Add(label, 1, 0);

                    return(new ViewCell {
                        View = grid
                    });
                }),

                SeparatorVisibility = SeparatorVisibility.None
            };

            Icon  = "hamburger.png";
            Title = "Sensus";

            Content = new StackLayout
            {
                Children = { _masterPageItemsListView }
            };
        }