Esempio n. 1
0
        async Task SetGps()
        {
            this.IsGpsSyncEnabled = await this.syncManager.IsMonitoring(LocationSyncType.GPS);

            this.WhenAnyValue(x => x.IsGeofenceSyncEnabled)
            .Skip(1)
            .Subscribe(async enabled =>
            {
                try
                {
                    if (enabled)
                    {
                        await this.syncManager.StartGpsMonitoring(GpsRequest.Realtime(true));
                    }
                    else
                    {
                        await this.syncManager.StopMonitoring(LocationSyncType.Geofence);
                    }
                }
                catch (Exception ex)
                {
                    await this.dialogs.Alert(ex.ToString());
                }
            })
            .DisposeWith(this.DeactivateWith);
        }
Esempio n. 2
0
        public AccessViewModel(IJobManager jobs,
                               IDialogs dialogs,
                               INotificationManager?notifications = null,
                               ISpeechRecognizer?speech           = null,
                               IGeofenceManager?geofences         = null,
                               IGpsManager?gps = null,
                               IMotionActivityManager?activityManager = null,
                               IBleManager?bluetooth = null,
                               IBeaconRangingManager?beaconRanging       = null,
                               IBeaconMonitoringManager?beaconMonitoring = null,
                               IPushManager?push = null,
                               INfcManager?nfc   = null)
        {
            this.dialogs = dialogs;

            this.Append("Jobs", jobs, () => jobs.RequestAccess());
            this.Append("Notifications", notifications, () => notifications !.RequestAccess());
            this.Append("Speech", speech, () => speech !.RequestAccess());
            this.Append("Motion Activity", activityManager, () => activityManager !.RequestAccess());
            this.Append("GPS (Background)", gps, () => gps !.RequestAccess(GpsRequest.Realtime(true)));
            this.Append("Geofences", geofences, () => geofences !.RequestAccess());
            this.Append("BluetoothLE Central", bluetooth, () => bluetooth !.RequestAccess().ToTask(CancellationToken.None));
            this.Append("iBeacons (Ranging)", beaconRanging, () => beaconRanging !.RequestAccess());
            this.Append("iBeacons (Monitoring)", beaconMonitoring, () => beaconMonitoring !.RequestAccess());
            this.Append("Push", push, async() =>
            {
                var status = await push !.RequestAccess();
                return(status.Status);
            });
Esempio n. 3
0
        public GpsViewModel(IGpsManager gps)
        {
            this.Start = ReactiveCommand.CreateFromTask(
                async() =>
            {
                this.foreground = gps
                                  .WhenReading()
                                  .Subscribe(reading =>
                {
                    this.Latitude  = reading.Position.Latitude;
                    this.Longitude = reading.Position.Longitude;
                });

                await gps.StartListener(GpsRequest.Realtime(true));
            }
                );

            this.Stop = ReactiveCommand.CreateFromTask(async() =>
            {
                await gps.StopListener();
                this.foreground?.Dispose();
            });
        }
Esempio n. 4
0
        public GpsViewModel(IGpsManager manager, IUserDialogs dialogs)
        {
            this.manager    = manager;
            this.IsUpdating = this.manager.IsListening;

            this.WhenAnyValue(x => x.UseBackground)
            .Subscribe(x => this.Access = this.manager.GetCurrentStatus(this.UseBackground).ToString());

            this.WhenAnyValue(x => x.IsUpdating)
            .Select(x => x ? "Stop Listening" : "Start Updating")
            .ToPropertyEx(this, x => x.ListenerText);

            this.GetCurrentPosition = ReactiveCommand.CreateFromTask(async _ =>
            {
                var result = await dialogs.RequestAccess(() => this.manager.RequestAccess(true));
                if (!result)
                {
                    return;
                }

                var reading = await this.manager.GetLastReading();
                if (reading == null)
                {
                    await dialogs.Alert("Could not getting GPS coordinates");
                }
                else
                {
                    this.SetValues(reading);
                }
            });
            this.BindBusyCommand(this.GetCurrentPosition);

            this.SelectPriority = ReactiveCommand.Create(() => dialogs.ActionSheet(
                                                             new ActionSheetConfig()
                                                             .SetTitle("Select Priority/Desired Accuracy")
                                                             .Add("Highest", () => this.Priority = GpsPriority.Highest)
                                                             .Add("Normal", () => this.Priority  = GpsPriority.Normal)
                                                             .Add("Low", () => this.Priority     = GpsPriority.Low)
                                                             .AddCancel()
                                                             ));

            this.ToggleUpdates = ReactiveCommand.CreateFromTask(
                async() =>
            {
                if (this.manager.IsListening)
                {
                    await this.manager.StopListener();
                    this.gpsListener?.Dispose();
                }
                else
                {
                    var result = await dialogs.RequestAccess(() => this.manager.RequestAccess(this.UseBackground));
                    if (!result)
                    {
                        await dialogs.Alert("Insufficient permissions");
                        return;
                    }

                    var request = new GpsRequest
                    {
                        UseBackground = this.UseBackground,
                        Priority      = this.Priority,
                    };
                    if (IsInterval(this.DesiredInterval))
                    {
                        request.Interval = ToInterval(this.DesiredInterval);
                    }

                    if (IsInterval(this.ThrottledInterval))
                    {
                        request.ThrottledInterval = ToInterval(this.ThrottledInterval);
                    }

                    await this.manager.StartListener(request);
                }
                this.IsUpdating = this.manager.IsListening;
            },
                this.WhenAny(
                    x => x.IsUpdating,
                    x => x.DesiredInterval,
                    x => x.ThrottledInterval,
                    (u, i, t) =>
            {
                if (u.GetValue())
                {
                    return(true);
                }

                var isdesired   = IsInterval(i.GetValue());
                var isthrottled = IsInterval(t.GetValue());

                if (isdesired && isthrottled)
                {
                    var desired  = ToInterval(i.GetValue());
                    var throttle = ToInterval(t.GetValue());
                    if (throttle.TotalSeconds >= desired.TotalSeconds)
                    {
                        return(false);
                    }
                }
                return(true);
            }
                    )
                );

            this.UseRealtime = ReactiveCommand.Create(() =>
            {
                var rt = GpsRequest.Realtime(false);
                this.ThrottledInterval = String.Empty;
                this.DesiredInterval   = rt.Interval.TotalSeconds.ToString();
                this.Priority          = rt.Priority;
            });

            this.RequestAccess = ReactiveCommand.CreateFromTask(async() =>
            {
                var access  = await this.manager.RequestAccess(this.UseBackground);
                this.Access = access.ToString();
            });
            this.BindBusyCommand(this.RequestAccess);
        }
Esempio n. 5
0
        public GpsViewModel(IGpsManager manager, IDialogs dialogs)
        {
            this.manager = manager;

            var l = this.manager.CurrentListener;

            this.IsUpdating            = l != null;
            this.UseBackground         = l?.UseBackground ?? true;
            this.Priority              = l?.Priority ?? GpsPriority.Normal;
            this.DesiredInterval       = l?.Interval.TotalSeconds.ToString() ?? String.Empty;
            this.ThrottledInterval     = l?.ThrottledInterval?.TotalSeconds.ToString() ?? String.Empty;
            this.MinimumDistanceMeters = l?.MinimumDistance?.TotalMeters.ToString() ?? String.Empty;

            this.NotificationTitle   = manager.Title;
            this.NotificationMessage = manager.Message;

            this.WhenAnyValue(x => x.IsUpdating)
            .Select(x => x ? "Stop Listening" : "Start Updating")
            .ToPropertyEx(this, x => x.ListenerText);

            this.WhenAnyValue(x => x.NotificationTitle)
            .Skip(1)
            .Subscribe(x => this.manager.Title = x)
            .DisposedBy(this.DestroyWith);

            this.WhenAnyValue(x => x.NotificationMessage)
            .Skip(1)
            .Subscribe(x => this.manager.Message = x)
            .DisposedBy(this.DestroyWith);

            this.GetCurrentPosition = this.CreateOneReading(dialogs, LocationRetrieve.Current);
            this.GetLastReading     = this.CreateOneReading(dialogs, LocationRetrieve.Last);
            this.GetLastOrCurrent   = this.CreateOneReading(dialogs, LocationRetrieve.LastOrCurrent);

            ReactiveCommand.Create(() => dialogs.ActionSheet(
                                       "Select Priority",
                                       false,
                                       ("Highest", () => this.Priority = GpsPriority.Highest),
                                       ("Normal", () => this.Priority = GpsPriority.Normal),
                                       ("Low", () => this.Priority = GpsPriority.Low)
                                       ));

            this.ToggleUpdates = ReactiveCommand.CreateFromTask(
                async() =>
            {
                if (this.manager.CurrentListener != null)
                {
                    await this.manager.StopListener();
                    this.gpsListener?.Dispose();
                }
                else
                {
                    var result = await dialogs.RequestAccess(async() =>
                    {
                        var access = await this.manager.RequestAccess(new GpsRequest
                        {
                            UseBackground = this.UseBackground
                        });
                        this.Access = access.ToString();
                        return(access);
                    });
                    if (!result)
                    {
                        await dialogs.Alert("Insufficient permissions");
                        return;
                    }

                    var request = new GpsRequest
                    {
                        UseBackground = this.UseBackground,
                        Priority      = this.Priority,
                    };
                    if (IsNumeric(this.DesiredInterval))
                    {
                        request.Interval = ToInterval(this.DesiredInterval);
                    }

                    if (IsNumeric(this.ThrottledInterval))
                    {
                        request.ThrottledInterval = ToInterval(this.ThrottledInterval);
                    }

                    if (IsNumeric(this.MinimumDistanceMeters))
                    {
                        request.MinimumDistance = Distance.FromMeters(Int32.Parse(this.MinimumDistanceMeters));
                    }

                    await this.manager.StartListener(request);
                }
                this.IsUpdating = this.manager.CurrentListener != null;
            },
                this.WhenAny(
                    x => x.IsUpdating,
                    x => x.DesiredInterval,
                    x => x.ThrottledInterval,
                    x => x.MinimumDistanceMeters,
                    (u, i, t, d) =>
            {
                if (u.GetValue())
                {
                    return(true);
                }

                var isdesired   = IsNumeric(i.GetValue());
                var isthrottled = IsNumeric(t.GetValue());
                var ismindist   = IsNumeric(d.GetValue());

                if (isdesired && isthrottled)
                {
                    var desired  = ToInterval(i.GetValue());
                    var throttle = ToInterval(t.GetValue());
                    if (throttle.TotalSeconds >= desired.TotalSeconds)
                    {
                        return(false);
                    }
                }
                return(true);
            }
                    )
                );

            this.UseRealtime = ReactiveCommand.Create(() =>
            {
                var rt = GpsRequest.Realtime(false);
                this.ThrottledInterval = String.Empty;
                this.DesiredInterval   = rt.Interval.TotalSeconds.ToString();
                this.Priority          = rt.Priority;
            });

            this.RequestAccess = ReactiveCommand.CreateFromTask(async() =>
            {
                var access = await this.manager.RequestAccess(new GpsRequest {
                    UseBackground = this.UseBackground
                });
                this.Access = access.ToString();
            });
            this.BindBusyCommand(this.RequestAccess);
        }