コード例 #1
0
        private void HandleSelectedDevice(DeviceListItemViewModel device)
        {
            var config = new ActionSheetConfig();

            if (device.IsConnected)
            {
                config.Add("Details", () =>
                {
                    ShowViewModel <ServiceListViewModel>(new MvxBundle(new Dictionary <string, string> {
                        { DeviceIdKey, device.Device.Id.ToString() }
                    }));
                });
                config.Add("Update RSSI", async() =>
                {
                    try
                    {
                        _userDialogs.ShowLoading();

                        await device.Device.UpdateRssiAsync();
                        device.RaisePropertyChanged(nameof(device.Rssi));

                        _userDialogs.HideLoading();

                        _userDialogs.Toast($"RSSI updated {device.Rssi}", TimeSpan.FromSeconds(1000));
                    }
                    catch (Exception ex)
                    {
                        _userDialogs.HideLoading();
                        await _userDialogs.AlertAsync($"Failed to update rssi. Exception: {ex.Message}");
                    }
                });

                config.Destructive = new ActionSheetOption("Disconnect", () => DisconnectCommand.Execute(device));
            }
            else
            {
                config.Add("Connect", async() =>
                {
                    if (await ConnectDeviceAsync(device))
                    {
                        var navigation = Mvx.Resolve <IMvxNavigationService>();
                        await navigation.Navigate <ServiceListViewModel, MvxBundle>(new MvxBundle(new Dictionary <string, string> {
                            { DeviceIdKey, device.Device.Id.ToString() }
                        }));
                    }
                });

                config.Add("Connect & Dispose", () => ConnectDisposeCommand.Execute(device));
            }

            config.Add("Copy GUID", () => CopyGuidCommand.Execute(device));
            config.Cancel = new ActionSheetOption("Cancel");
            config.SetTitle("Device Options");
            _userDialogs.ActionSheet(config);
        }
コード例 #2
0
        private void HandleSelectedDevice(DeviceListItemViewModel device)
        {
            var config = new ActionSheetConfig();

            if (device.IsConnected)
            {
                config.Add("Update RSSI", async() =>
                {
                    try
                    {
                        _userDialogs.ShowLoading();

                        await device.Device.UpdateRssiAsync();
                        device.RaisePropertyChanged(nameof(device.Rssi));

                        _userDialogs.HideLoading();

                        _userDialogs.ShowSuccess($"RSSI updated {device.Rssi}", 1000);
                    }
                    catch (Exception ex)
                    {
                        _userDialogs.HideLoading();
                        _userDialogs.ShowError($"Failed to update rssi. Exception: {ex.Message}");
                    }
                });

                config.Destructive = new ActionSheetOption("Disconnect", () => DisconnectCommand.Execute(device));
            }
            else
            {
                config.Add("Connect", async() =>
                {
                    if (await ConnectDeviceAsync(device))
                    {
                        ShowViewModel <ServiceListViewModel>(new MvxBundle(new Dictionary <string, string> {
                            { DeviceIdKey, device.Device.Id.ToString() }
                        }));
                    }
                });

                //config.Add("Connect & Dispose", () => ConnectDisposeCommand.Execute(device));
                config.Add("Save Advertised Data", () =>
                {
                    if (device.Device.AdvertisementRecords == null || device.Device.AdvertisementRecords.Count == 0)
                    {
                        _userDialogs.Alert("No Data Found");
                        return;
                    }

                    var advModel = new AdvertisementData()
                    {
                        Id       = Guid.NewGuid(),
                        DeviceId = device.Id.ToString(),
                        Name     = device.Name,
                        Data     = device.Device.AdvertisementRecords[0].Data
                    };
                    _advertisementDataRepository.InsertDevice(advModel);
                });
            }

            config.Add("Copy ID", () => CopyGuidCommand.Execute(device));
            config.Cancel = new ActionSheetOption("Cancel");
            config.SetTitle("Device Options");
            _userDialogs.ActionSheet(config);
        }