private async void ConnectDisconnectDevice(object sender, EventArgs e)
        {
            HttpResponseMessage result;

            if (isConnectedDeviceSelected)
            {
                result = await Services.WithingsService.DisconnectDeviceAsync(selectedDevice.Identifier.System, selectedDevice.Identifier.Value);
            }
            else
            {
                result = await Services.WithingsService.ConnectDeviceAsync(selectedDevice.Identifier.System, selectedDevice.Identifier.Value);
            }

            if (result.IsSuccessStatusCode)
            {
                List <object> connectedDevices    = new List <object>();
                List <object> disconnectedDevices = new List <object>();

                var res = await Services.WithingsService.GetDevices(connectedDevices, disconnectedDevices);

                if (res == System.Net.HttpStatusCode.OK)
                {
                    ConnectedDevices.Clear();
                    DisconnectedDevices.Clear();
                    ConnectedDevices    = new ObservableCollection <object>(connectedDevices);
                    DisconnectedDevices = new ObservableCollection <object>(disconnectedDevices);
                }
                else if (res == System.Net.HttpStatusCode.Conflict)
                {
                    await DisplayAlert("Conflict", "Previous user delete operation is in progress. Please try again later", "Ok");
                }
                else
                {
                    await DisplayAlert("Error", "Something went wrong. Please try again", "Ok");
                }
            }
            else
            {
                await DisplayAlert("Withing auth failed", "Something went wrong. Please try again", "Ok");
            }

            OnAppearing();

            if (result.IsSuccessStatusCode)
            {
                actionButton.IsEnabled      = false;
                actionButton.Text           = "Select Device";
                selectedDevice.IsSelected   = false;
                selectedDevice              = null;
                deviceContentView.IsVisible = false;
            }

            if (Device.Idiom == TargetIdiom.Tablet)
            {
                actionButton.IsVisible = false;
            }
        }
예제 #2
0
        private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
        {
            Controls.ContentPresenter contentPresenter = (Controls.ContentPresenter)sender;
            Models.Device             device           = (Models.Device)contentPresenter.BindingContext;

            if (selectedDevice != null)
            {
                string selectedModelId = (from c in selectedDevice.Identifier.Type.Coding
                                          where c.System.AbsoluteUri == $"{selectedDevice.Identifier.System}/device/model_id"
                                          select c.Code).FirstOrDefault();
                string currentModelId = (from c in device.Identifier.Type.Coding
                                         where c.System.AbsoluteUri == $"{device.Identifier.System}/device/model_id"
                                         select c.Code).FirstOrDefault();

                if (selectedModelId != currentModelId)
                {
                    selectedDevice.IsSelected = false;
                }
            }

            device.IsSelected = !device.IsSelected;

            selectedDevice = device.IsSelected ? device : null;

            authenticateWithManufacturer.IsEnabled = (selectedDevice != null) ? true : false;

            if (selectedDevice != null && Device.Idiom == TargetIdiom.Tablet)
            {
                DeviceInfo = new Models.Device()
                {
                    Display       = selectedDevice.Display,
                    Identifier    = selectedDevice.Identifier,
                    ShowExtraInfo = true,
                    IsConnected   = false,
                    IsSelected    = false,
                };

                authenticateWithManufacturer.IsVisible = true;
            }
            else
            {
                DeviceInfo = null;

                if (Device.Idiom == TargetIdiom.Tablet)
                {
                    authenticateWithManufacturer.IsVisible = false;
                }
            }

            deviceDetails.BindingContext = DeviceInfo;
            deviceContentView.IsVisible  = (selectedDevice == null) ? false : true;
        }
        private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
        {
            Controls.ContentPresenter contentPresenter = (Controls.ContentPresenter)sender;
            Models.Device             device           = (Models.Device)contentPresenter.BindingContext;
            isConnectedDeviceSelected = device.IsConnected;

            if (selectedDevice != null && selectedDevice.Identifier.Value != device.Identifier.Value)
            {
                selectedDevice.IsSelected = false;
            }

            device.IsSelected = !device.IsSelected;

            selectedDevice = device.IsSelected ? device : null;

            actionButton.Text      = isConnectedDeviceSelected ? "Disconnect Device" : "Connect Device";
            actionButton.IsEnabled = (selectedDevice != null) ? true : false;

            if (!actionButton.IsEnabled)
            {
                actionButton.Text = "Select Device";
            }

            if (selectedDevice != null && Device.Idiom == TargetIdiom.Tablet)
            {
                DeviceInfo = new Models.Device()
                {
                    Display       = selectedDevice.Display,
                    Identifier    = selectedDevice.Identifier,
                    ShowExtraInfo = true,
                    IsConnected   = false,
                    IsSelected    = false,
                };

                actionButton.IsVisible = true;
            }
            else
            {
                DeviceInfo = null;

                if (Device.Idiom == TargetIdiom.Tablet)
                {
                    actionButton.IsVisible = false;
                }
            }

            deviceDetails.BindingContext = DeviceInfo;
            deviceContentView.IsVisible  = (selectedDevice == null) ? false : true;
        }
        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();

            tapGestureRecognizer.Tapped += TapGestureRecognizer_Tapped;
            contentPresenter.GestureRecognizers.Add(tapGestureRecognizer);
            return(contentPresenter);
        }
예제 #5
0
        // 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);
        }
예제 #6
0
        private Controls.ContentPresenter BuildContentPresenter(DataTemplate template, Models.Device supportedDevice)
        {
            Controls.ContentPresenter contentPresenter = new Controls.ContentPresenter()
            {
                BindingContext = supportedDevice,
            };
            contentPresenter.ItemTemplate = template;
            contentPresenter.WidthRequest = 160;
            TapGestureRecognizer tapGestureRecognizer = new TapGestureRecognizer();

            tapGestureRecognizer.Tapped += TapGestureRecognizer_Tapped;
            contentPresenter.GestureRecognizers.Add(tapGestureRecognizer);
            return(contentPresenter);
        }
예제 #7
0
        private async void AuthenticateWithManufacturer_Clicked(object sender, EventArgs e)
        {
            if (selectedDevice.Identifier.System.ToLower() == Constants.Manufacturers.Withings.Value)
            {
                var res = await GetWithingsAuthCode();

                if (res.Length > 0)
                {
                    HttpClient httpClient = new HttpClient();
                    var        request    = new HttpRequestMessage(HttpMethod.Post, Constants.H3BaseEndpoint + Constants.WithingsAuthEndpoint)
                    {
                        Content = new StringContent(JsonConvert.SerializeObject(new
                        {
                            withingsAccessCode  = res,
                            withingsRedirectUri = Constants.WithingsRedirectUri,
                        })),
                    };
                    request.Headers.Authorization       = new AuthenticationHeaderValue("Bearer", App.B2cAccessToken);
                    request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                    var result = await httpClient.SendAsync(request);

                    if (result.IsSuccessStatusCode)
                    {
                        List <object> connectedDevices    = new List <object>();
                        List <object> disconnectedDevices = new List <object>();

                        var r = await Services.WithingsService.GetDevices(connectedDevices, disconnectedDevices);

                        if (r == System.Net.HttpStatusCode.OK)
                        {
                            App.Current.MainPage = new NavigationPage(new DeviceManagementPage(connectedDevices, disconnectedDevices, true));
                        }
                        else if (r == System.Net.HttpStatusCode.Conflict)
                        {
                            await DisplayAlert("Conflict", "PApp.Current.MainPage = new NavigationPagerevious user delete operation is in progress. Please try again later", "Ok");
                        }
                        else
                        {
                            await DisplayAlert("Withing auth failed", "Something went wrong. Please try again", "Ok");
                        }
                    }
                    else if (result.StatusCode == System.Net.HttpStatusCode.Conflict)
                    {
                        await DisplayAlert("Conflict", "Previous user delete operation is in progress. Please try again later", "Ok");
                    }
                    else
                    {
                        await DisplayAlert("Ingestion failed", "Something went wrong. Please try again", "Ok");
                    }
                }
                else
                {
                    await DisplayAlert("Withing auth failed", "Something went wrong. Please try again", "Ok");
                }
            }
            else
            {
                await DisplayAlert("Coming soon", "Selected device is not supported yet", "Ok");
            }

            authenticateWithManufacturer.IsEnabled = false;
            selectedDevice.IsSelected   = false;
            selectedDevice              = null;
            deviceContentView.IsVisible = false;

            if (Device.Idiom == TargetIdiom.Tablet)
            {
                authenticateWithManufacturer.IsVisible = false;
            }
        }
예제 #8
0
        private void GenerateSupportedDevicesCollection(ObservableCollection <object> supportedDevices)
        {
            Models.Device device = new Models.Device()
            {
                Display    = "BPM Connect (Blood Pressure Monitor)",
                Identifier = new Models.Identifier()
                {
                    System = "http://withings.com",
                    Type   = new Models.Type()
                    {
                        Coding = new List <Models.Coding>()
                        {
                            new Models.Coding()
                            {
                                System = new Uri("http://withings.com/device/model_id"),
                                Code   = "45",
                            },
                            new Models.Coding()
                            {
                                System = new Uri("http://withings.com/device/type"),
                                Code   = "Blood Pressure Monitor",
                            },
                        },
                    },
                },
                IsConnected   = false,
                IsSelected    = false,
                ShowExtraInfo = true,
            };
            supportedDevices.Add(device);

            device = new Models.Device()
            {
                Display    = "Body (Scale)",
                Identifier = new Models.Identifier()
                {
                    System = "http://withings.com",
                    Type   = new Models.Type()
                    {
                        Coding = new List <Models.Coding>()
                        {
                            new Models.Coding()
                            {
                                System = new Uri("http://withings.com/device/model_id"),
                                Code   = "7",
                            },
                            new Models.Coding()
                            {
                                System = new Uri("http://withings.com/device/type"),
                                Code   = "Scale",
                            },
                        },
                    },
                },
                IsConnected   = false,
                IsSelected    = false,
                ShowExtraInfo = true,
            };
            supportedDevices.Add(device);

            device = new Models.Device()
            {
                Display    = "Thermo Smart Temporal",
                Identifier = new Models.Identifier()
                {
                    System = "http://withings.com",
                    Type   = new Models.Type()
                    {
                        Coding = new List <Models.Coding>()
                        {
                            new Models.Coding()
                            {
                                System = new Uri("http://withings.com/device/model_id"),
                                Code   = "123",
                            },
                            new Models.Coding()
                            {
                                System = new Uri("http://withings.com/device/type"),
                                Code   = "Thremo",
                            },
                        },
                    },
                },
                IsConnected   = false,
                IsSelected    = false,
                ShowExtraInfo = true,
            };
            supportedDevices.Add(device);
        }