protected override async void OnAppearing() { await FetchDevices(); if (ConnectedDevices.Count > 0) { await FetchObservations(); } BindingContext = this; DataTemplate template = (DataTemplate)this.Resources["withingsDeviceDataTemplate"]; connectedDevicesWrapLayout.Children.Clear(); foreach (var connectedItem in ConnectedDevices) { Controls.ContentPresenter contentPresenter = BuildContentPresenter(template, connectedItem, false, true); connectedDevicesWrapLayout.Children.Add(contentPresenter); } template = (DataTemplate)this.Resources["withingsObservationDataTemplate"]; observationListWrapLayout.Children.Clear(); foreach (var observation in observationCategories) { Controls.ContentPresenter observationPresenter = BuildObservationPresenter(template, observation.Value); observationListWrapLayout.Children.Add(observationPresenter); } ManageDevicesButton devicesButton = new ManageDevicesButton(); TapGestureRecognizer tapGestureRecognizer = new TapGestureRecognizer(); tapGestureRecognizer.Tapped += async(s, e) => { await Navigation.PushAsync(new DeviceManagementPage(ConnectedDevices.ToList(), DisconnectedDevices.ToList())); }; devicesButton.GestureRecognizers.Add(tapGestureRecognizer); connectedDevicesWrapLayout.Children.Add(devicesButton); base.OnAppearing(); }
// TODO: Combine this with code from DeviceManagementPage.cs private Controls.ContentPresenter BuildContentPresenter(DataTemplate template, object connectedItem, bool isConnected, bool showExtraInfo = false) { Models.Device device = JsonConvert.DeserializeObject <Models.Device>(connectedItem.ToString()); device.IsConnected = isConnected; device.ShowExtraInfo = showExtraInfo; Controls.ContentPresenter contentPresenter = new Controls.ContentPresenter() { BindingContext = device, }; contentPresenter.ItemTemplate = template; TapGestureRecognizer tapGestureRecognizer = new TapGestureRecognizer(); // TODO: Change device tapped to go somewhere else? tapGestureRecognizer.Tapped += async(s, e) => { await Navigation.PushAsync(new DeviceManagementPage(ConnectedDevices.ToList(), DisconnectedDevices.ToList())); }; contentPresenter.GestureRecognizers.Add(tapGestureRecognizer); return(contentPresenter); }