public override void OnResume()
        {
            base.OnResume();
            // contentView.RemoveAllViews();
            vm = new GoalsVM();

            Task.Run(() =>
            {
                Task.Delay(70).Wait();
                Platform.RunSafeOnUIThread("GoalViewFragment.OnResume", () =>
                {
                    var contentPanel = view.FindViewById <Android.Widget.LinearLayout>(Resource.Id.contentpanel);
                    contentPanel.RequestFocus();
                    var binding = DataContext <GoalsVM> .FromView(contentPanel);
                    binding.VM  = vm;

                    binding.Add(Resource.Id.editText_description, x => x.Description);
                    binding.Add(Resource.Id.editDate, x => x.Date);

                    var editDate    = view.FindViewById <Android.Widget.EditText>(Resource.Id.editDate);
                    editDate.Click += (sender, e) =>
                    {
                        DateTime goal;
                        if (!DateTime.TryParse(vm.Date, out goal))
                        {
                            goal = DateTime.Now.Date;
                        }
                        Android.App.DatePickerDialog dpd = new Android.App.DatePickerDialog(Activity,
                                                                                            (c, d) =>
                        {
                            editDate.Text = d.Date.ToShortDateString();
                            vm.Date       = d.Date.ToShortDateString();
                        },
                                                                                            goal.Year,
                                                                                            goal.Month,
                                                                                            goal.Day);
                        dpd.Show();
                    };

                    var adapter = new VMListAdapter <GoalLineVM>(Activity, vm.Goals, Resource.Layout.item_goalline, null,
                                                                 (b, gvm) =>
                    {
                        b.Add(Resource.Id.text, x => x.Text);
                        b.Add(Resource.Id.value, x => x.Value);
                        b.Add(Resource.Id.image_remove, (a) =>
                        {
                            vm.DeleteGoal(a);
                        });
                    }
                                                                 );

                    contentView = view.FindViewById <Android.Widget.LinearLayout>(Resource.Id.contentView);
                    contentView.RemoveAllViews();
                    for (int i = 0; i < adapter.Count; i++)
                    {
                        contentView.AddView(adapter.GetView(i, null, contentView));
                    }

                    vm.Goals.CollectionChanged += (sender, e) =>
                    {
                        contentView.RemoveAllViews();
                        for (int i = 0; i < adapter.Count; i++)
                        {
                            contentView.AddView(adapter.GetView(i, null, contentView));
                        }
                    };

                    var text_button    = view.FindViewById <Android.Widget.TextView>(Resource.Id.text_button);
                    text_button.Click += (sender, e) =>
                    {
                        List <String> options = vm.NewPropertyOptions;

                        AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                        builder.SetTitle(Resource.String.add_target)
                        .SetItems(options.ToArray(), (s, e2) =>
                        {
                            Property result = StandardProperty.none;
                            String clicked  = options[e2.Which];
                            foreach (var value in Property.All())
                            {
                                if (value.FullCapitalizedText == clicked)
                                {
                                    result = value;
                                }
                            }

                            if (result == StandardProperty.none)
                            {
                                return;
                            }
                            vm.AddGoal(result);
                        });

                        builder.Create();
                        builder.Show();
                    };

                    SessionLog.EndPerformance("Navigate");
                });
            });
            GrabAd();
        }
Exemple #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();


//			FoodJournal.SettingsVM vm = new SettingsVM();

//			FDSettingsDataSource ds = new FDSettingsDataSource ();
//
//			tableview1.Source = ds;
//			tableview2.Source = ds;
//			tableviewMeals.Source = ds;
//			tableviewReminders.Source = ds;
//			tableview1.ReloadData ();
//			tableview2.ReloadData ();
//			tableviewMeals.ReloadData ();
//			tableviewReminders.ReloadData ();
            _gvm = new GoalsVM();
            _vm  = new SettingsVM();
            var binding = DataContext <SettingsVM> .FromView(View);

            binding.VM = _vm;

            SettingsCellDelegate celldelegate = new SettingsCellDelegate(DeleteAction, tableView);

            FDSettingsDataSource fdDS = new FDSettingsDataSource(_gvm, _vm, celldelegate);

            fdDS._addNutritionDelegate += AddNutrition;
            fdDS._addMealDelegate      += AddMeal;
            fdDS._showTotalDelegate    += ShowTotalNutrition;
            fdDS._addReminderDelegate  += AddReminder;
            tableView.Source            = fdDS;


            UIToolbar toolbar = new UIToolbar(new CGRect((nfloat)0.0f, (nfloat)0.0f, (nfloat)this.View.Frame.Size.Width, (nfloat)44.0f));

            toolbar.TintColor = UIColor.White;
            toolbar.BarStyle  = UIBarStyle.Black;

            toolbar.Translucent = true;


            toolbar.Items = new UIBarButtonItem[] {
                new UIBarButtonItem("Cancel",
                                    UIBarButtonItemStyle.Plain, delegate {
                    showTotalPicker.Hidden = true;
                    showTotalPicker.SetNeedsDisplay();
                }),
                new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
                new UIBarButtonItem(UIBarButtonSystemItem.Done, delegate {
                    showTotalPicker.Hidden = true;
                    showTotalPicker.ResignFirstResponder();
                    showTotalPicker.SetNeedsDisplay();
                })
            };


            showTotalPicker = new UIPickerView(new CoreGraphics.CGRect(0, this.View.Frame.Height - 250f, this.View.Frame.Width, 250f)
                                               )
            {
                AutoresizingMask       = UIViewAutoresizing.FlexibleWidth,
                ShowSelectionIndicator = true,
                Model           = new ShowTotalModel(_vm.TotalOptions),
                BackgroundColor = UIColor.White,
                Hidden          = true
            };
            showTotalPicker.AddSubview(toolbar);
//			showTotalPicker.InputAccessoryView = toolbar;
            // Now update it:
//			showTotalPicker.Frame = PickerFrameWithSize (showTotalPicker.SizeThatFits (CGSize.Empty));
            View.AddSubview(showTotalPicker);
        }
Exemple #3
0
 public GoalsView(IEventAggregator eventAggregator, IMyMessageDialog myMessageDialog)
 {
     InitializeComponent();
     _viewModel  = new GoalsVM(eventAggregator, myMessageDialog);
     DataContext = _viewModel;
 }
 public FDSettingsDataSource(GoalsVM gvm, SettingsVM vm, FoodDiary2.iOS.Controller.FDSettingsVC.SettingsCellDelegate cellDelegate)
 {
     _gvm          = gvm;
     _vm           = vm;
     _cellDelegate = cellDelegate;
 }