public AccessViewModel(IJobManager jobs, INotificationManager notifications = null, ISpeechRecognizer speech = null, IGeofenceManager geofences = null, IGpsManager gps = null, ICentralManager bluetooth = null, IBeaconManager beacons = null) { this.Append("Jobs", AccessState.Unknown, () => jobs.RequestAccess()); if (notifications != null) this.Append("Notifications", AccessState.Unknown, () => notifications.RequestAccess()); if (speech != null) this.Append("Speech", AccessState.Unknown, () => speech.RequestAccess().ToTask(CancellationToken.None)); if (gps != null) this.Append("GPS", gps.Status, () => gps.RequestAccess(true)); if (geofences != null) this.Append("Geofences", geofences.Status, () => geofences.RequestAccess()); if (bluetooth != null) this.Append("BluetoothLE Central", bluetooth.Status, () => bluetooth.RequestAccess().ToTask(CancellationToken.None)); if (beacons != null) this.Append("iBeacons", beacons.Status, () => beacons.RequestAccess(true)); }
public TodoService(IDataService dataService, INotificationManager notificationManager, IGeofenceManager geofenceManager) { this.dataService = dataService; this.notificationManager = notificationManager; this.geofenceManager = geofenceManager; }
public GeofenceProcessor(IRepository repository, IGeofenceManager geofenceManager, IGeofenceDelegate geofenceDelegate) { this.repository = repository.Wrap(); this.geofenceManager = geofenceManager; this.geofenceDelegate = geofenceDelegate; }
public TestViewModel(IBleManager bleManager, IGeofenceManager geofenceManager, IDialogs dialogs) { this.bleManager = bleManager; this.geofenceManager = geofenceManager; this.dialogs = dialogs; this.Start = ReactiveCommand.CreateFromTask <string>( async arg => { this.disp = new CompositeDisposable(); this.cancelSrc = new CancellationTokenSource(); this.Logs = String.Empty; switch (arg) { case "managedbleperipheral": await this.DoManagedPeripheral(); break; case "managedblescan": await this.DoManagedScan(); break; case "locationpermission": await this.DoLocationPermissionTest(); break; case "blepairing": await this.PairingTest(); break; case "bledeviceinfo": await this.BleDeviceInfo(); break; default: await dialogs.Snackbar("Invalid Test - " + arg); break; } } ); this.BindBusyCommand(this.Start); this.Stop = ReactiveCommand.Create( () => { this.disp?.Dispose(); this.cancelSrc?.Cancel(); this.peripheral?.CancelConnection(); this.Append("Stopped"); this.IsBusy = false; }, this.WhenAny(x => x.IsBusy, x => x.GetValue()) ); }
public AccessViewModel(IJobManager jobs, INotificationManager notifications = null, ISpeechRecognizer speech = null, IGeofenceManager geofences = null, IGpsManager gps = null, ICentralManager bluetooth = null, IBeaconManager beacons = null, IPushManager push = null, INfcManager nfc = null) { this.Append("Jobs", AccessState.Unknown, () => jobs.RequestAccess()); if (notifications != null) { this.Append("Notifications", AccessState.Unknown, () => notifications.RequestAccess()); } if (speech != null) { this.Append("Speech", AccessState.Unknown, () => speech.RequestAccess()); } if (gps != null) { this.Append("GPS (Background)", gps.GetCurrentStatus(true), () => gps.RequestAccess(true)); } if (geofences != null) { this.Append("Geofences", geofences.Status, () => geofences.RequestAccess()); } if (bluetooth != null) { this.Append("BluetoothLE Central", bluetooth.Status, () => bluetooth.RequestAccess().ToTask(CancellationToken.None)); } if (beacons != null) { this.Append("iBeacons (Monitoring)", beacons.GetCurrentStatus(true), () => beacons.RequestAccess(true)); } if (push != null) { this.Append("Push", AccessState.Unknown, async() => { var status = await push.RequestAccess(); return(status.Status); }); } if (nfc != null) { this.Append("NFC", AccessState.Unknown, () => nfc.RequestAccess().ToTask(CancellationToken.None)); } }
public AlarmsManager(IDatabaseManager databaseManager, IGeofenceManager geofenceManager, ILogService logService) { _logService = logService; _databaseManager = databaseManager; _geofenceManager = geofenceManager; _databaseManager.CreateTable<AlarmItem>(); }
public AlarmsManager(IDatabaseManager databaseManager, IGeofenceManager geofenceManager, ILogService logService) { _logService = logService; _databaseManager = databaseManager; _geofenceManager = geofenceManager; _databaseManager.CreateTable <AlarmItem>(); }
public AddGeofenceViewModel(IGeofenceManager geofences, IUserDialogs dialogs, IViewModelManager viewModelMgr, IGeolocator geolocator) { this.Add = ReactiveCommand.CreateAsyncTask( this.WhenAny( x => x.RadiusMeters, x => x.Latitude, x => x.Longitude, x => x.Identifer, (radius, lat, lng, id) => { if (radius.Value < 100) return false; if (lat.Value < -90 || lat.Value > 90) return false; if (lng.Value < -180 || lng.Value > 180) return false; if (id.Value.IsEmpty()) return false; return true; } ), async x => { geofences.StartMonitoring(new GeofenceRegion { Identifier = this.Identifer, Center = new Position(this.Latitude, this.Longitude), Radius = Distance.FromMeters(this.RadiusMeters) }); await viewModelMgr.PopNav(); } ); this.UseCurrentLocation = ReactiveCommand.CreateAsyncTask(async x => { try { var current = await geolocator.GetPositionAsync(5000); this.Latitude = current.Latitude; this.Longitude = current.Longitude; } catch { } }); }
public ListViewModel(INavigationService navigator, IGeofenceManager geofenceManager, IDialogs dialogs) { this.geofenceManager = geofenceManager; this.dialogs = dialogs; this.Create = navigator.NavigateCommand("CreateGeofence"); this.DropAllFences = ReactiveCommand.CreateFromTask( async _ => { var confirm = await this.dialogs.Confirm("Are you sure you wish to drop all geofences?"); if (confirm) { await this.geofenceManager.StopAllMonitoring(); await this.LoadRegions(); } } ); }
public ListViewModel(IGeofenceManager geofenceManager, IUserDialogs dialogs) { this.geofenceManager = geofenceManager; this.dialogs = dialogs; this.DropAllFences = ReactiveCommand.CreateFromTask( async _ => { var confirm = await this.dialogs.ConfirmAsync("Are you sure you wish to drop all geofences?"); if (confirm) { await this.geofenceManager.StopAllMonitoring(); await this.LoadRegions(); } }, this.WhenAny( x => x.HasGeofences, x => x.GetValue() ) ); }
public HistoryViewModel(SampleDbConnection conn, IGeofenceManager geofences, IUserDialogs dialogs, IMessaging messaging) { this.conn = conn; this.geofences = geofences; this.Reload = new Command(this.Load); this.Clear = ReactiveCommand.CreateAsyncTask(async x => { var result = await dialogs.ConfirmAsync(new ConfirmConfig() .UseYesNo() .SetMessage("Are you sure you want to delete all of your history?")); if (result) { this.conn.DeleteAll<GeofenceEvent>(); this.Load(); } }); this.SendDatabase = new Command(() => { var backupLocation = conn.CreateDatabaseBackup(conn.Platform); var mail = new EmailMessageBuilder() .Subject("Geofence Database") //.WithAttachment(conn.DatabasePath, "application/octet-stream") .WithAttachment(backupLocation, "application/octet-stream") .Body("--") .Build(); messaging.EmailMessenger.SendEmail(mail); }); }
public CreateViewModel(INavigationService navigator, IGeofenceManager geofenceManager, IGpsManager gpsManager, IDialogs dialogs) { this.navigator = navigator; this.geofenceManager = geofenceManager; this.gpsManager = gpsManager; this.dialogs = dialogs; var isValid = this.WhenAny( x => x.NotifyOnEntry, x => x.NotifyOnExit, x => x.RadiusMeters, (entry, exit, rad) => ( entry.GetValue() || exit.GetValue() ) && ( rad.GetValue() >= 100 && rad.GetValue() < 5000 ) ); this.SetCurrentLocation = ReactiveCommand.CreateFromTask(async ct => { var loc = await this.gpsManager.GetLastReading().ToTask(ct); this.CenterLatitude = loc?.Position?.Latitude ?? 0; this.CenterLongitude = loc?.Position?.Longitude ?? 0; }); this.BindBusyCommand(this.SetCurrentLocation); this.RequestAccess = ReactiveCommand.CreateFromTask( async() => { this.AccessStatus = await geofenceManager.RequestAccess(); } ); this.AddCnTower = ReactiveCommand.CreateFromTask( _ => this.AddGeofence( "CNTowerToronto", 43.6425662, -79.3892508, this.RadiusMeters ), isValid ); this.AddAppleHQ = ReactiveCommand.CreateFromTask( _ => this.AddGeofence( "AppleHQ", 37.3320045, -122.0329699, this.RadiusMeters ), isValid ); this.CreateGeofence = ReactiveCommand.CreateFromTask( _ => this.AddGeofence ( this.Identifier, this.CenterLatitude.Value, this.CenterLongitude.Value, this.RadiusMeters ), this.WhenAny( x => x.AccessStatus, x => x.Identifier, x => x.RadiusMeters, x => x.CenterLatitude, x => x.CenterLongitude, x => x.NotifyOnEntry, x => x.NotifyOnExit, (access, id, rad, lat, lng, entry, exit) => { if (access.GetValue() != AccessState.Available) { return(false); } if (id.GetValue().IsEmpty()) { return(false); } var radius = rad.GetValue(); if (radius < 100 || radius > 5000) { return(false); } var latv = lat.GetValue(); if (latv != null && (latv >= 89.9 || latv <= -89.9)) { return(false); } var lngv = lng.GetValue(); if (lngv != null && (lngv >= 179.9 || lngv <= -179.9)) { return(false); } if (!entry.GetValue() && !exit.GetValue()) { return(false); } return(true); } ) ); }
public NotificationTask(IGeofenceManager geofences, INotifications notifications) { this.geofences = geofences; this.notifications = notifications; }
public GpsGeofenceDelegate(IGeofenceManager geofenceManager, IGeofenceDelegate geofenceDelegate) { this.CurrentStates = new Dictionary <string, GeofenceState>(); this.geofenceManager = geofenceManager; this.geofenceDelegate = geofenceDelegate; }
public EditViewModel(INavigationService navigator, IMaterialDialog dialogs, IGeofenceManager geofences, INotificationManager notifications, ITodoService todoService) { this.WhenAnyValue( x => x.Date, x => x.Time ) .Select(x => new DateTime( x.Item1.Year, x.Item1.Month, x.Item1.Day, x.Item2.Hours, x.Item2.Minutes, 0 )) .ToPropertyEx(this, x => x.AlarmDate); this.WhenAnyValue( x => x.RemindOnLocation, x => x.Latitude, x => x.Longitude ) .Select(x => { if (!x.Item1) { return(String.Empty); } return($"({x.Item2} - {x.Item3})"); }) .ToPropertyEx(this, x => x.Location); this.Date = DateTime.Now.AddDays(1); this.Time = this.Date.TimeOfDay; this.WhenAnyValue(x => x.RemindOnDay) .Skip(1) .Where(x => x) .SubscribeAsync(async(_) => { var access = await notifications.RequestAccess(); if (access != AccessState.Available) { this.RemindOnDay = false; await dialogs.AlertAsync("Permission denied for notifications"); } }); this.WhenAnyValue(x => x.RemindOnLocation) .Skip(1) .Where(x => x) .SubscribeAsync(async(_) => { var access = await geofences.RequestAccess(); if (access != AccessState.Available) { this.RemindOnDay = false; await dialogs.AlertAsync("Permission denied for geofences"); } }); this.SetLocation = navigator.NavigateCommand("LocationPage"); this.Save = ReactiveCommand.CreateFromTask( async() => { var item = this.existingItem ?? new TodoItem(); item.Title = this.ReminderTitle; item.Notes = this.Notes; if (this.RemindOnDay) { item.DueDateUtc = this.AlarmDate; } if (this.RemindOnLocation) { item.GpsLatitude = this.Latitude; item.GpsLongitude = this.Longitude; } await todoService.Save(item); await navigator.GoBack(); }, this.WhenAny( x => x.ReminderTitle, x => !x.GetValue().IsEmpty() ) ); this.BindBusy(this.Save); }
public EditViewModel(INavigationService navigator, IDataService data, IUserDialogs dialogs, INotificationManager notifications, IGeofenceManager geofences) { this.WhenAnyValue( x => x.Date, x => x.Time ) .Select(x => new DateTime( x.Item1.Year, x.Item1.Month, x.Item1.Day, x.Item2.Hours, x.Item2.Minutes, 0 )) .ToPropertyEx(this, x => x.AlarmDate); this.WhenAnyValue(x => x.RemindOnDay) .Skip(1) .Where(x => x) .SubscribeAsync(async() => { var access = await notifications.RequestAccess(); if (access != AccessState.Available) { this.RemindOnDay = false; await dialogs.Alert("Permission denied for notifications"); } }); this.WhenAnyValue(x => x.RemindOnLocation) .Skip(1) .Where(x => x) .SubscribeAsync(async() => { var access = await geofences.RequestAccess(); if (access != AccessState.Available) { this.RemindOnDay = false; await dialogs.Alert("Permission denied for geofences"); } }); this.WhenAnyValue( x => x.RemindOnLocation, x => x.Latitude, x => x.Longitude ) .Select(x => { if (!x.Item1) { return(String.Empty); } return($"({x.Item2} - {x.Item3})"); }) .ToPropertyEx(this, x => x.Location); this.Date = DateTime.Now.AddDays(1); this.Time = this.Date.TimeOfDay; this.SetLocation = navigator.NavigateCommand("LocationPage"); this.Save = ReactiveCommand.CreateFromTask( async() => { // TODO: if existing, I may have to create geofences and notifications // if new var todo = await data.Create(newItem => { newItem.Title = this.ReminderTitle; newItem.Notes = this.Notes; if (this.RemindOnDay) { newItem.DueDateUtc = this.AlarmDate; } }); if (this.RemindOnDay) { await notifications.Send(new Notification { Title = this.ReminderTitle, Message = this.Notes ?? String.Empty, ScheduleDate = this.AlarmDate }); } if (this.RemindOnLocation) { await geofences.StartMonitoring(new GeofenceRegion( todo.Id.ToString(), new Position(1, 1), Distance.FromMeters(200) ) { NotifyOnEntry = true, NotifyOnExit = false }); } await navigator.GoBack(); }, this.WhenAny( x => x.ReminderTitle, x => !x.GetValue().IsEmpty() ) ); this.BindBusy(this.Save); }
public GpsGeofenceDelegate(IGeofenceManager geofenceManager, IGeofenceDelegate geofenceDelegate) { this.geofenceManager = geofenceManager; this.geofenceDelegate = geofenceDelegate; }
public SettingsViewModel(IPermissions permissions, IGeofenceManager geofences, IUserDialogs dialogs, IViewModelManager viewModelMgr) { this.permissions = permissions; this.geofences = geofences; this.dialogs = dialogs; this.Menu = new Command(() => dialogs.ActionSheet(new ActionSheetConfig() .SetCancel() .Add("Add Geofence", async () => await viewModelMgr.PushNav<AddGeofenceViewModel>() ) .Add("Use Default Geofences", async () => { var result = await dialogs.ConfirmAsync(new ConfirmConfig() .UseYesNo() .SetMessage("This will stop monitoring all existing geofences and set the defaults. Are you sure you want to do this?")); if (result) { geofences.StopAllMonitoring(); await Task.Delay(500); geofences.StartMonitoring(new GeofenceRegion { Identifier = "FC HQ", Center = new Position(43.6411314, -79.3808415), // 88 Queen's Quay - Home Radius = Distance.FromKilometers(1) }); geofences.StartMonitoring(new GeofenceRegion { Identifier = "Close to HQ", Center = new Position(43.6411314, -79.3808415), // 88 Queen's Quay Radius = Distance.FromKilometers(3) }); geofences.StartMonitoring(new GeofenceRegion { Identifier = "Ajax GO Station", Center = new Position(43.8477697, -79.0435461), Radius = Distance.FromMeters(500) }); await Task.Delay(500); // ios needs a second to breathe when registering like this this.RaisePropertyChanged("CurrentRegions"); } }) .Add("Stop All Geofences", async () => { var result = await dialogs.ConfirmAsync(new ConfirmConfig() .UseYesNo() .SetMessage("Are you sure wish to stop monitoring all geofences?")); if (result) { this.geofences.StopAllMonitoring(); this.RaisePropertyChanged("CurrentRegions"); } }) )); this.Remove = new Command<GeofenceRegion>(x => { this.geofences.StopMonitoring(x); this.RaisePropertyChanged("CurrentRegions"); }); }
public CreateViewModel(INavigationService navigator, IGeofenceManager geofenceManager, IGpsManager gpsManager, IUserDialogs dialogs) { this.navigator = navigator; this.geofenceManager = geofenceManager; this.gpsManager = gpsManager; this.dialogs = dialogs; var hasEventType = this.WhenAny( x => x.NotifyOnEntry, x => x.NotifyOnExit, (entry, exit) => entry.GetValue() || exit.GetValue() ); geofenceManager .WhenAccessStatusChanged() .ToPropertyEx(this, x => x.AccessStatus); this.SetCurrentLocation = ReactiveCommand.CreateFromTask(async ct => { var loc = await this.gpsManager.GetLastReading().ToTask(ct); this.CenterLatitude = loc?.Position?.Latitude ?? 0; this.CenterLongitude = loc?.Position?.Longitude ?? 0; }); this.BindBusyCommand(this.SetCurrentLocation); //this.RequestAccess = ReactiveCommand.CreateFromTask( // async () => await geofenceManager.RequestAccess() //); this.AddCnTower = ReactiveCommand.CreateFromTask( _ => this.AddGeofence( "CNTowerToronto", 43.6425662, -79.3892508, DEFAULT_DISTANCE_METERS ), hasEventType ); this.AddAppleHQ = ReactiveCommand.CreateFromTask( _ => this.AddGeofence( "AppleHQ", 37.3320045, -122.0329699, DEFAULT_DISTANCE_METERS ), hasEventType ); this.CreateGeofence = ReactiveCommand.CreateFromTask( _ => this.AddGeofence ( this.Identifier, this.CenterLatitude, this.CenterLongitude, this.RadiusMeters ), this.WhenAny( //x => x.AccessStatus, x => x.Identifier, x => x.RadiusMeters, x => x.CenterLatitude, x => x.CenterLongitude, x => x.NotifyOnEntry, x => x.NotifyOnExit, //(access, id, rad, lat, lng, entry, exit) => (id, rad, lat, lng, entry, exit) => { //if (access.GetValue() != AccessState.Available) // return false; if (id.GetValue().IsEmpty()) { return(false); } var radius = rad.GetValue(); if (radius < 200 || radius > 5000) { return(false); } var latv = lat.GetValue(); if (latv >= 89.9 || latv <= -89.9) { return(false); } var lngv = lng.GetValue(); if (lngv >= 179.9 || lngv <= -179.9) { return(false); } if (!entry.GetValue() && !exit.GetValue()) { return(false); } return(true); } ) ); }
public CreateViewModel(IGeofenceManager geofenceManager, IGpsManager gpsManager, IUserDialogs dialogs) { this.geofenceManager = geofenceManager; this.gpsManager = gpsManager; this.dialogs = dialogs; var hasEventType = this.WhenAny( x => x.NotifyOnEntry, x => x.NotifyOnExit, (entry, exit) => entry.GetValue() || exit.GetValue() ); this.SetCurrentLocation = ReactiveCommand.CreateFromTask(async ct => { var loc = await this.gpsManager.GetLastReading().ToTask(ct); this.CenterLatitude = loc?.Position?.Latitude ?? 0; this.CenterLongitude = loc?.Position?.Longitude ?? 0; }); this.BindBusyCommand(this.SetCurrentLocation); this.AddCnTower = ReactiveCommand.CreateFromTask( _ => this.AddGeofence( "CNTowerToronto", 43.6425662, -79.3892508, DEFAULT_DISTANCE_METERS ), hasEventType ); this.AddAppleHQ = ReactiveCommand.CreateFromTask( _ => this.AddGeofence( "AppleHQ", 37.3320045, -122.0329699, DEFAULT_DISTANCE_METERS ), hasEventType ); this.CreateGeofence = ReactiveCommand.CreateFromTask( async _ => { await this.AddGeofence( this.Identifier, this.CenterLatitude, this.CenterLongitude, this.RadiusMeters ); this.Identifier = String.Empty; this.CenterLatitude = 0; this.CenterLongitude = 0; this.RadiusMeters = DEFAULT_DISTANCE_METERS; }, this.WhenAny( x => x.Identifier, x => x.RadiusMeters, x => x.CenterLatitude, x => x.CenterLongitude, x => x.NotifyOnEntry, x => x.NotifyOnExit, (id, rad, lat, lng, entry, exit) => { if (String.IsNullOrWhiteSpace(id.GetValue())) { return(false); } var radius = rad.GetValue(); if (radius < 200 || radius > 5000) { return(false); } var latv = lat.GetValue(); if (latv >= 89.9 || latv <= -89.9) { return(false); } var lngv = lng.GetValue(); if (lngv >= 179.9 || lngv <= -179.9) { return(false); } if (!entry.GetValue() && !exit.GetValue()) { return(false); } return(true); } ) ); }