Example #1
0
 public RecipeDetailVM(Recipe Recipe)
 {
     this.recipe = Recipe;
     //PicturesVM = new PicturesVM(item);
     AmountCollectionVM = new AmountCollectionVM(this);
     PopulateIngredients();
     PopulateProperties();
 }
Example #2
0
        public EntryDetailVM(Entry entry)
        {
            if (!Cache.AllItemsLoaded)
            {
                FoodJournalNoSQL.LoadItems(false, null);
            }

            this.entry = entry;
            this.item  = entry.Item;
                        #if WINDOWS_PHONE
            PicturesVM = new PicturesVM(item);
                        #endif
            AmountCollectionVM = new AmountCollectionVM(this);
            PopulateProperties();
        }
Example #3
0
        public ServingSizeAdapter(Context context, AmountCollectionVM collection)
            : base()
        {
            _context = context;
            var temp = collection.Amounts.OrderByDescending(x => x.IsChecked).ToList();

            collection.Amounts.Clear();
            foreach (var item in temp)
            {
                collection.Amounts.Add(item);
            }
            _collection = collection;
            _collection.PropertyChanged += (sender, e) => { if (e.PropertyName == "Amounts")
                                                            {
                                                                this.NotifyDataSetChanged();
                                                            }
            };
        }
Example #4
0
        //public void DeleteFromDB()
        //{
        //    recipe.DeleteFromDB();
        //    Navigate.Back();
        //}

        public void AddServingSize()
        {
            AmountCollectionVM.AddServingSize();
        }
Example #5
0
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_entrydetail);
            OverridePendingTransition(Resource.Animation.zoom_enter, Resource.Animation.zoom_exit);
            var toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar_addItem);

            SetSupportActionBar(toolbar);
            this.SupportActionBar.Title = AppResources.PageTitleItemDetail;
            this.SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            listEntryEdit = FindViewById <Android.Widget.LinearLayout>(Resource.Id.contentView);
            var e = Navigate.selectedEntry;

            vm = new EntryDetailVM(e);
            var view = listEntryEdit;

#if SCREENSHOT
            Navigate.screenshotScreen = this;
#endif

            var binding = DataContext <EntryDetailVM> .FromView(view);

            binding.VM = vm;
            listEntryEdit.AddView(View.Inflate(this, Resource.Layout.item_edit_entry_top, null));
            AmountCollectionVM avm = vm.AmountCollectionVM;
            ServingSizeAdapter a   = new ServingSizeAdapter(this, avm);

            // serving sizes
            listEntryEdit.AddView(View.Inflate(this, Resource.Layout.item_serving, null));
            var ServingExtraMenu = FindViewById(Resource.Id.addItemDialog);
            ServingExtraMenu.Click += (object sender, EventArgs e2) =>
            {
                ShowServingsExtraMenu();
            };

            var servingsizes = FindViewById <Android.Widget.LinearLayout>(Resource.Id.servingSizes);
            int cnt          = Math.Min(a.Count, MAXSERVINGSFIRST);
            for (int i = 0; i < cnt; i++)
            {
                servingsizes.AddView(a.GetView2(i, null, servingsizes));
            }

            View showmore = null;
            if (a.Count > MAXSERVINGSFIRST)
            {
                showmore = View.Inflate(this, Resource.Layout.item_servings_show_more, null);
                listEntryEdit.AddView(showmore);
                var button = FindViewById <TextView>(Resource.Id.button_showmoreoptions);
                button.Click += (sender, e2) =>
                {
                    servingsizes.RemoveAllViews();
                    for (int i = 0; i < a.Count; i++)
                    {
                        servingsizes.AddView(a.GetView2(i, null, servingsizes));
                    }
                    showmore.Visibility = ViewStates.Invisible;
                };
            }

            // add serving szie
            avm.Amounts.CollectionChanged += (sender, e3) =>
            {
                if (showmore != null)
                {
                    showmore.Visibility = ViewStates.Invisible;
                }
                servingsizes.RemoveAllViews();
                for (int i = 0; i < a.Count; i++)
                {
                    servingsizes.AddView(a.GetView2(i, null, servingsizes));
                }
            };

            PropertyAdapter p = new PropertyAdapter(this, vm);

            // properties
            listEntryEdit.AddView(View.Inflate(this, Resource.Layout.item_nutrition, null));
            var properties = FindViewById <Android.Widget.LinearLayout>(Resource.Id.properties);
            for (int i = 0; i < p.Count; i++)
            {
                properties.AddView(p.GetView2(i, null, properties));
            }

            Action action = () =>
            {
                servingsizes.RemoveAllViewsInLayout();
                for (int i = 0; i < a.Count; i++)
                {
                    servingsizes.AddView(a.GetView(i, null, servingsizes));
                }
            };

            a.RegisterDataSetObserver(new DSO(action));

            if (binding.Bindings.Count == 0)
            {
                binding.Add(Resource.Id.addInputDialog, x => x.Text);
                binding.Add(Resource.Id.opt_pergrams, x => x.Is100Gram);
                binding.Add(Resource.Id.opt_percup, x => x.IsNot100Gram);
                binding.Add(Resource.Id.opt_percup, x => x.SelectedServingText);
            }
            addInputDialog = listEntryEdit.FindViewById <EditText>(Resource.Id.addInputDialog);
            if (Navigate.selectedEntry.Item.IsNewItem)
            {
                addInputDialog.TextChanged += AddInputDialogTextChanged;
            }
            else
            {
                EditMode = true;
            }
            OriginalText = Navigate.selectedItem.Text;
#if DEBUG
            AndroidDebug.SetViewBorders(listEntryEdit);
#endif
        }
Example #6
0
 public IngredientVM(Ingredient ingredient)
 {
     this.ingredient    = ingredient;
     AmountCollectionVM = new AmountCollectionVM(ingredient);
 }