コード例 #1
0
        protected void OnAddPublisherClicked(object sender)
        {
            Catalogue catalogue = Catalogue.GetCatalogue();
            var       config    = new ActionSheetConfig();

            config.SetTitle(Localization.AddPublisher);
            config.SetDestructive(Localization.NewPublisher, async() =>
            {
                OnRemovePublisherClicked(null);
                await Navigation.PushModalAsync(new AddPublisherPage(Book, true));
            });
            config.SetCancel(Localization.Cancel);
            foreach (var publisher in catalogue.PublishersList)
            {
                if (Book.Publisher != publisher)
                {
                    config.Add(publisher.Name, () =>
                    {
                        OnRemovePublisherClicked(null);
                        publisher.AddBook(Book);
                        Book.Publisher = publisher;
                    });
                }
            }
            UserDialogs.Instance.ActionSheet(config);
        }
コード例 #2
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);
        }
コード例 #3
0
        public void ShowActionSheetAsync(string title, string CancelbuttonLabel, string[] items)
        {
            ActionSheetConfig cfg = new ActionSheetConfig();

            foreach (string item in items)
            {
                cfg.Add(item);
            }
            cfg.SetTitle(title);
            UserDialogs.Instance.ActionSheet(cfg);
        }
コード例 #4
0
        protected void OnRemoveBookClicked(object sender)
        {
            var config = new ActionSheetConfig();

            config.SetTitle(Localization.BookToRemove);
            config.SetCancel(Localization.Cancel);
            foreach (var book in Publisher)
            {
                config.Add(book.Title, () =>
                {
                    Catalogue.GetCatalogue().RemoveBook(book);
                });
            }
            UserDialogs.Instance.ActionSheet(config);
        }
コード例 #5
0
        public IDisposable ShowActionSheet(
            string title,
            string cancel,
            string destructive,
            List <ActionSheetButtonModel> actionSheetButtons)
        {
            var config = new ActionSheetConfig();

            config.SetTitle(title);
            config.SetCancel(cancel);
            config.Destructive = string.IsNullOrEmpty(destructive) ? null : new ActionSheetOption(destructive);

            foreach (var button in actionSheetButtons)
            {
                config.Add(button.Text, button.Action, button.IconName);
            }

            return(_dialogs.ActionSheet(config));
        }
コード例 #6
0
        protected void OnRemoveAuthorClicked(object sender)
        {
            var config = new ActionSheetConfig();

            config.SetTitle(Localization.AuthorToRemove);
            config.SetCancel(Localization.Cancel);
            foreach (var author in Book)
            {
                config.Add(author.FullName, () =>
                {
                    Book.RemoveAuthor(author);
                    author.RemoveBook(Book);
                    if (author.IsEmpty())
                    {
                        Catalogue.GetCatalogue().RemoveAuthor(author);
                    }
                });
            }
            UserDialogs.Instance.ActionSheet(config);
        }
コード例 #7
0
        protected void OnAddBookClicked(object sender)
        {
            Catalogue catalogue = Catalogue.GetCatalogue();
            var       config    = new ActionSheetConfig();

            config.SetTitle(Localization.AddBook);
            config.SetDestructive(Localization.NewBook, async() => { await App.Current.MainPage.Navigation.PushModalAsync(new AddBookPage(Publisher, true)); });
            config.SetCancel(Localization.Cancel);
            foreach (var book in catalogue.BooksList)
            {
                if (book.Publisher == null && !Publisher.ContainsBook(book))
                {
                    config.Add(book.Title, () =>
                    {
                        book.Publisher = Publisher;
                        Publisher.AddBook(book);
                    });
                }
            }
            UserDialogs.Instance.ActionSheet(config);
        }
コード例 #8
0
        protected void OnAddAuthorClicked(object sender)
        {
            Catalogue catalogue = Catalogue.GetCatalogue();
            var       config    = new ActionSheetConfig();

            config.SetTitle(Localization.AddAuthor);
            config.SetDestructive(Localization.NewAuthor, async() => { await Navigation.PushModalAsync(new AddAuthorPage(Book, true)); });
            config.SetCancel(Localization.Cancel);
            foreach (var author in catalogue.AuthorsList)
            {
                if (!Book.ContainsAuthor(author))
                {
                    config.Add(author.FullName, () =>
                    {
                        author.AddBook(Book);
                        Book.AddAuthor(author);
                    });
                }
            }
            UserDialogs.Instance.ActionSheet(config);
        }
コード例 #9
0
ファイル: DeviceListViewModel.cs プロジェクト: jpark318/BLE
        private void HandleSelectedDevice(DeviceListItemViewModel device, int type)
        {
            //type = 1 if slave, type = 2 if master.
            var config = new ActionSheetConfig();

            if (device.IsConnected)
            {
                config.Destructive = new ActionSheetOption("Disconnect", () => DisconnectCommand.Execute(device));
            }
            else
            {
                config.Add("Connect", async() => {
                    if (await ConnectDeviceAsync(device))
                    {
                        switch (type)
                        {
                        case 1:
                            device.IsSlave = true;
                            GraphViewModel.SlaveDeviceId = device.Device.Id;
                            var ServiceSlave             = await device.Device.GetServiceAsync(Guid.Parse("0000180d-0000-1000-8000-00805f9b34fb"));
                            var CharacteristicSlave      = await ServiceSlave.GetCharacteristicAsync(Guid.Parse("00002a37-0000-1000-8000-00805f9b34fb"));

                            await CharacteristicSlave.StartUpdatesAsync();
                            break;

                        case 2:
                            device.IsMaster = true;
                            GraphViewModel.MasterDeviceId = device.Device.Id;
                            var ServiceMaster             = await device.Device.GetServiceAsync(Guid.Parse("0000180d-0000-1000-8000-00805f9b34fb"));
                            var CharacteristicMaster      = await ServiceMaster.GetCharacteristicAsync(Guid.Parse("00002a37-0000-1000-8000-00805f9b34fb"));
                            await CharacteristicMaster.StartUpdatesAsync();
                            break;
                        }
                    }
                });
            }
            config.Cancel = new ActionSheetOption("Cancel");
            config.SetTitle("Device Options");
            _userDialogs.ActionSheet(config);
        }
コード例 #10
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);
        }
コード例 #11
0
        private void HandleSelectedDevice(IDevice device)
        {
            var config = new ActionSheetConfig();

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

                        await device.UpdateRssiAsync();

                        _userDialogs.HideLoading();

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

                config.Destructive = new ActionSheetOption("Disconnect", () => DisconnectDevice(device));
            }
            else
            {
                config.Add("Connect", async() =>
                {
                    if (await ConnectDeviceAsync(device))
                    {
                        // Connected

                        //var services = await device.GetServicesAsync();
                        //var service = await device.GetServiceAsync(Guid.Parse("ffe0ecd2-3d16-4f8d-90de-e89e7fc396a5"));

                        //// Get characteristics
                        //var characteristics = await service.GetCharacteristicsAsync();
                        //var characteristic = await service.GetCharacteristicAsync(Guid.Parse("d8de624e-140f-4a22-8594-e2216b84a5f2"));
                        //// Read characteristic
                        //var bytes = await characteristic.ReadAsync();

                        //// Write characteristic
                        //await characteristic.WriteAsync(bytes);

                        //// Characteristic notifications
                        //characteristic.ValueUpdated += (o, args) =>
                        //{
                        //    var bytes = args.Characteristic.Value;
                        //};

                        //await characteristic.StartUpdatesAsync();
                    }
                });
            }
            config.Cancel = new ActionSheetOption("Cancel");
            config.SetTitle("Device Options");
            _userDialogs.ActionSheet(config);
        }