public void SetWeight(WeightData h, int pos) { LabelDate.Text = h.Date.ToString("dd/MM/yy HH:mm"); WeightLabel.Text = h.Value.ToString("0.0") + " " + h.Unit; if (pos == 0) { line1.Hidden = false; } else { line1.Hidden = true; } }
public override void ViewDidLoad() { base.ViewDidLoad(); addButton.TouchUpInside += delegate { if (Weight == null) { WeightData data = new WeightData(); String v = WeightField.Text; try { data.Value = Double.Parse(v); data.Unit = "kg"; data.Date = Date; OnAddWeight?.Invoke(this, new WeightEventArgs(data)); DismissViewController(false, null); } catch { } } else { OnDeleteWeight?.Invoke(this, new WeightEventArgs(Weight)); DismissViewController(false, null); } }; CancelButton.TouchUpInside += delegate { DismissViewController(false, null); }; DateButton.TouchUpInside += (sender, e) => { WeightField.ResignFirstResponder(); OpenDatePicker(); }; if (Weight != null) { Date = Weight.Date; WeightField.Text = Weight.Value.ToString("F"); addButton.SetTitle("Borrar", UIControlState.Normal); } else { Date = DateTime.Now; } DateButton.SetTitle(Date.ToShortDateString() + " " + Date.ToShortTimeString(), UIControlState.Normal); }
public Task <bool> SaveWeightIntoHealthStore(WeightData weight) { var weightQuantity = HKQuantity.FromQuantity(HKUnit.Gram, weight.Value * 1000); var weightType = HKQuantityType.Create(HKQuantityTypeIdentifier.BodyMass); var weightSample = HKQuantitySample.FromType(weightType, weightQuantity, DateUtil.DateTimeToNSDate(weight.Date), DateUtil.DateTimeToNSDate(weight.Date), new NSDictionary()); var completionSource = new TaskCompletionSource <bool>(); HealthStore.SaveObject(weightSample, (success, error) => { if (!success) { completionSource.SetResult(false); } else { completionSource.SetResult(true); } }); return(completionSource.Task); }
public Task <List <WeightData> > GetWeigths() { var weightType = HKQuantityType.Create(HKQuantityTypeIdentifier.BodyMass); if (HealthStore.GetAuthorizationStatus(weightType) == HKAuthorizationStatus.SharingAuthorized) { var completionSource = new TaskCompletionSource <List <WeightData> >(); FetchMostRecentData(weightType, (QuantityResults, error) => { if (error != null) { //Console.WriteLine("An error occured fetching the user's age information. " + //"In your app, try to handle this gracefully. The error was: {0}", error.LocalizedDescription); completionSource.SetResult(null); } data = new List <WeightData>(); if (QuantityResults != null) { results = QuantityResults; for (int i = 0; i < QuantityResults.Count; i++) { WeightData h = new WeightData(); var weightUnit = HKUnit.Gram; h.Value = ((HKQuantitySample)QuantityResults[i]).Quantity.GetDoubleValue(weightUnit) / 1000f; h.Unit = "kg"; h.Date = DateUtil.NSDateToDateTime(((HKQuantitySample)QuantityResults[i]).StartDate); data.Add(h); } } completionSource.SetResult(data); }, 365 * 2 ); return(completionSource.Task); } else { return(null); } }
public WeightEventArgs(WeightData w) { this.Weight = w; }