private void populateFields()
 {
     Task.Run(async() => {
         List <FoodItem> f = await GlobalVariables.foodItemsDatabase.QueryById(mID);
         food             = f.First();
         dict             = GlobalVariables.DeserializeDictionary(food.ANSWERS);
         imageView.Source = ImageSource.FromStream(() => new MemoryStream(GlobalVariables.DeserializeStringToByteArray(food.IMGBYTES)));
         if (EntryType == GlobalVariables.EntryType.UPDATE_ENTRY)
         {
             mName.Text = food.NAME;
             foreach (var question in dict)
             {
                 CustomRadioGroup group = null;
                 if (radioGroups.TryGetValue(question.Key, out group))
                 {
                     group.SelectedIndex = question.Value;
                 }
             }
         }
         Update();
     });
 }
Exemplo n.º 2
0
        public ImageViewer(FoodItem food)
        {
            NavigationPage.SetHasNavigationBar(this, false);
            int index = 0;

            CurrentIndex = index;
            bool            indexSet  = false;
            List <FoodItem> FoodItems = GlobalVariables.getFoodItems();

            list = new Dictionary <int, byte[]>();
            foreach (var i in FoodItems)
            {
                list.Add(i.ID, GlobalVariables.DeserializeStringToByteArray(i.IMGBYTES));
                if (i == food && !indexSet)
                {
                    index    = list.Count - 1;
                    indexSet = true;
                }
            }

            InitializeComponent();
            PanCardView.CarouselView carouselView = new PanCardView.CarouselView
            {
                ItemTemplate    = new DataTemplate(() => CardFactory.Creator.Invoke()),
                BackgroundColor = Color.Black
            };

            carouselView.SetBinding(CardsView.CurrentContextProperty, nameof(ImageViewerModel.CurrentContext));
            carouselView.SetBinding(CardsView.NextContextProperty, nameof(ImageViewerModel.NextContext));
            carouselView.SetBinding(CardsView.PrevContextProperty, nameof(ImageViewerModel.PrevContext));
            this.SetBinding(ImageViewer.CurrentIndexProperty, nameof(ImageViewerModel.CurrentIndex));
            carouselView.SetBinding(CardsView.PanStartedCommandProperty, nameof(ImageViewerModel.PanStartedCommand));
            carouselView.SetBinding(CardsView.PositionChangedCommandProperty, nameof(ImageViewerModel.PanPositionChangedCommand));

            //ToolbarItem deleteOption = new ToolbarItem("Delete", "", new Action(() => { DeleteSelectedImage(); }), ToolbarItemOrder.Primary, 0);
            ToolbarItem editOption = new ToolbarItem("Edit", "", new Action(() => { Navigation.PushAsync(new EditDetailsPage(getCurrentID(), GlobalVariables.EntryType.UPDATE_ENTRY)); }), ToolbarItemOrder.Primary, 0);

            AbsoluteLayout UserPrefs = new AbsoluteLayout
            {
                Margin = 10
            };

            AbsoluteLayout.SetLayoutFlags(UserPrefs, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(UserPrefs, new Rectangle(1, 1, 1, 0.11));
            StackLayout prefsView = new StackLayout();

            AbsoluteLayout.SetLayoutFlags(prefsView, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(prefsView, new Rectangle(1, 1, 1, 1));
            Grid grid = new Grid
            {
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.Start,
                RowDefinitions    =
                {
                    new RowDefinition {
                        Height = new GridLength(25, GridUnitType.Absolute)
                    },
                    new RowDefinition {
                        Height = new GridLength(25, GridUnitType.Absolute)
                    }
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Auto)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Auto)
                    }
                }
            };

            Image healthIcon = new Image
            {
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.Start,
                WidthRequest      = 25,
                HeightRequest     = 25,
                Source            = ImageSource.FromResource("SelfControl.Resources.health_icon.png")
            };
            Image frequencyIcon = new Image
            {
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.Start,
                WidthRequest      = 25,
                HeightRequest     = 25,
                Source            = ImageSource.FromResource("SelfControl.Resources.frequency_icon.png")
            };

            healthRating = new Label
            {
                Text     = "",
                FontSize = 15,
                VerticalTextAlignment = TextAlignment.Center,
                TextColor             = Color.White
            };
            frequencyRating = new Label
            {
                Text     = "",
                FontSize = 15,
                VerticalTextAlignment = TextAlignment.Center,
                TextColor             = Color.White
            };
            grid.Children.Add(healthIcon, 0, 0);
            grid.Children.Add(healthRating, 1, 0);
            grid.Children.Add(frequencyIcon, 0, 1);
            grid.Children.Add(frequencyRating, 1, 1);

            prefsView.Children.Add(grid);
            UserPrefs.Children.Add(prefsView);
            carouselView.Children.Add(UserPrefs);

            Content = carouselView;
            ToolbarItems.Add(editOption);
            //ToolbarItems.Add(deleteOption);
            BindingContext = new ImageViewerModel(list, index);
        }