예제 #1
0
        public TagsViewModel(IPushManager pushManager, IDialogs dialogs)
        {
            var tags = pushManager as IPushTagSupport;

            this.Add = ReactiveCommand.CreateFromTask(async() =>
            {
                var result = await dialogs.Input("Name of tag?");
                if (!result.IsEmpty())
                {
                    await tags.AddTag(result);
                    this.Load.Execute(null);
                }
            });

            this.Clear = ReactiveCommand.CreateFromTask(async() =>
            {
                var result = await dialogs.Confirm("Are you sure you wish to clear all tags?");
                if (result)
                {
                    await tags.ClearTags();
                    this.Load.Execute(null);
                }
            });

            this.Load = ReactiveCommand.Create(() =>
            {
                this.Tags = tags
                            .RegisteredTags
                            .Select(tag => new CommandItem
                {
                    Text           = tag,
                    PrimaryCommand = ReactiveCommand.CreateFromTask(async() =>
                    {
                        var result = await dialogs.Confirm($"Are you sure you wish to remove tag '{tag}'?");
                        if (result)
                        {
                            await tags.RemoveTag(tag);
                            this.Load.Execute(null);
                        }
                    })
                })
                            .ToList();

                this.RaisePropertyChanged(nameof(this.Tags));
            });
        }
예제 #2
0
        public PeripheralViewModel(IDialogs dialogs)
        {
            this.dialogs = dialogs;

            this.SelectCharacteristic = ReactiveCommand.Create <GattCharacteristicViewModel>(x => x.Select());

            this.ConnectionToggle = ReactiveCommand.Create(() =>
            {
                // don't cleanup connection - force user to d/c
                if (this.peripheral.Status == ConnectionState.Connected || this.peripheral.Status == ConnectionState.Connecting)
                {
                    this.peripheral.CancelConnection();
                }
                else
                {
                    this.peripheral.Connect();
                }
            });

            this.PairToDevice = ReactiveCommand.CreateFromTask(async() =>
            {
                var pair = this.peripheral as ICanPairPeripherals;

                if (pair == null)
                {
                    await dialogs.Alert("Pairing is not supported on this platform");
                }
                else if (pair.PairingStatus == PairingState.Paired)
                {
                    await dialogs.Snackbar("Peripheral is already paired");
                }
                else
                {
                    var pin    = await this.dialogs.Input("Use PIN?  Cancel to not use one");
                    var result = await pair.PairingRequest(pin);
                    await dialogs.Snackbar(result ? "Peripheral Paired Successfully" : "Peripheral Pairing Failed");
                    this.RaisePropertyChanged(nameof(this.PairingText));
                }
            });

            this.RequestMtu = ReactiveCommand.CreateFromTask(
                async x =>
            {
                var mtu = this.peripheral as ICanRequestMtu;
                if (mtu == null)
                {
                    await dialogs.Alert("MTU requests are not supported on this platform");
                }
                else
                {
                    var result = await dialogs.Input("MTU Request", "Range 20-512");
                    if (!result.IsEmpty())
                    {
                        var actual = await mtu.RequestMtu(Int32.Parse(result));
                        await dialogs.Snackbar("MTU Changed to " + actual);
                    }
                }
            },
                this.WhenAny(
                    x => x.ConnectText,
                    x => x.GetValue().Equals("Disconnect")
                    )
                );
        }
예제 #3
0
        public TagsViewModel(IDialogs dialogs, IPushManager?pushManager = null)
        {
            this.push    = pushManager;
            this.dialogs = dialogs;

            var tags        = pushManager as IPushTagSupport;
            var requirement = this.WhenAny(
                x => x.IsSupported,
                x => x.GetValue()
                );

            this.Add = ReactiveCommand.CreateFromTask(
                async() =>
            {
                var result = await dialogs.Input("Name of tag?");
                if (!result.IsEmpty())
                {
                    await tags.AddTag(result);
                    this.Load.Execute(null);
                }
            },
                requirement
                );

            this.Clear = ReactiveCommand.CreateFromTask(
                async() =>
            {
                var result = await dialogs.Confirm("Are you sure you wish to clear all tags?");
                if (result)
                {
                    await tags !.ClearTags();
                    this.Load.Execute(null);
                }
            },
                requirement
                );

            this.Load = ReactiveCommand.Create(
                () =>
            {
                var regTags = tags !.RegisteredTags ?? new string[0];

                this.Tags = regTags
                            .Select(tag => new CommandItem
                {
                    Text           = tag,
                    PrimaryCommand = ReactiveCommand.CreateFromTask(async() =>
                    {
                        var result = await dialogs.Confirm($"Are you sure you wish to remove tag '{tag}'?");
                        if (result)
                        {
                            await tags.RemoveTag(tag);
                            this.Load.Execute(null);
                        }
                    })
                })
                            .ToList();

                this.RaisePropertyChanged(nameof(this.Tags));
            },
                this.WhenAny(
                    x => x.IsSupported,
                    x => x.GetValue()
                    )
                );
        }