public CreateViewModel(INavigationService navigator, IDialogs dialogs, IBeaconRangingManager rangingManager, IBeaconMonitoringManager?monitorManager = null) { this.IsMonitoringSupported = monitorManager != null; this.EstimoteDefaults = ReactiveCommand.Create(() => { this.Identifier = "Estimote"; this.Uuid = "B9407F30-F5F8-466E-AFF9-25556B57FE6D"; }); this.WhenAnyValue(x => x.Major) .Select(x => !x.IsEmpty() && UInt16.TryParse(x, out _)) .ToPropertyEx(this, x => x.IsMajorSet); this.StartMonitoring = ReactiveCommand.CreateFromTask( async() => { var result = await monitorManager.RequestAccess(); if (result != AccessState.Available) { await dialogs.AlertAccess(result); } else { await monitorManager.StartMonitoring(this.GetBeaconRegion()); await navigator.GoBack(); } }, this.WhenAny( x => x.Identifier, x => x.Uuid, x => x.Major, x => x.Minor, x => x.NotifyOnEntry, x => x.NotifyOnExit, (idValue, uuidValue, majorValue, minorValue, entry, exit) => { if (monitorManager == null) { return(false); } var atLeast1Notification = entry.GetValue() || exit.GetValue(); if (!atLeast1Notification) { return(false); } return(this.IsValid()); } ) ); this.StartRanging = ReactiveCommand.CreateFromTask( async() => { var result = await rangingManager.RequestAccess(); if (result != AccessState.Available) { await dialogs.AlertAccess(result); } else { var region = this.GetBeaconRegion(); await navigator.GoBack(false, (nameof(BeaconRegion), region)); } }, this.WhenAny( x => x.Identifier, x => x.Uuid, x => x.Major, x => x.Minor, (idValue, uuidValue, majorValue, minorValue) => this.IsValid() ) ); }
public static async Task <bool> RequestAccess(this IDialogs dialogs, Func <Task <AccessState> > request) { var access = await request(); return(await dialogs.AlertAccess(access)); }