public ManageUploadsViewModel(IPlatform platform, IDialogs dialogs) { this.platform = platform; this.Delete = ReactiveCommand.CreateFromTask <string>(async file => { var path = Path.Combine(this.platform.AppData.FullName, file); if (!File.Exists(path)) { await dialogs.Snackbar($"{file} does not exist"); } else { File.Delete(path); await dialogs.Snackbar($"{file} has been deleted"); } }); this.CreateRandom = ReactiveCommand.CreateFromTask( this.GenerateRandom, this.WhenAny( x => x.SizeInMegabytes, x => x.GetValue() > 0 ) ); this.BindBusyCommand(this.CreateRandom); }
public TestLogViewModel(IDialogs dialogs, ILogger <TestLogViewModel> logger) { this.Test = ReactiveCommand.Create <string>(args => { switch (args) { case "critical": logger.LogCritical("This is a critical test"); break; case "error": logger.LogError("This is an error test"); break; case "warning": logger.LogWarning("This is an error test"); break; case "info": logger.LogInformation("This is an info test"); break; case "debug": logger.LogDebug("This is a debug test"); break; } dialogs.Snackbar("Sent log"); }); }
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 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") ) ); }
public CreateViewModel(INotificationManager notificationManager, IDialogs dialogs) { this.notificationManager = notificationManager; this.WhenAnyValue ( x => x.SelectedDate, x => x.SelectedTime ) .Select(x => new DateTime( x.Item1.Year, x.Item1.Month, x.Item1.Day, x.Item2.Hours, x.Item2.Minutes, x.Item2.Seconds) ) .Subscribe(x => this.ScheduledTime = x) .DisposeWith(this.DestroyWith); //.ToPropertyEx(this, x => x.ScheduledTime); this.SelectedDate = DateTime.Now; this.SelectedTime = DateTime.Now.TimeOfDay.Add(TimeSpan.FromMinutes(10)); this.SendNow = ReactiveCommand.CreateFromTask(() => this.BuildAndSend( "Test Now", "This is a test of the sendnow stuff", null )); this.Send = ReactiveCommand.CreateFromTask( async() => { await this.BuildAndSend( this.NotificationTitle, this.NotificationMessage, this.ScheduledTime ); await dialogs.Alert("Notification Sent Successfully"); }, this.WhenAny( x => x.NotificationTitle, x => x.NotificationMessage, x => x.ScheduledTime, (title, msg, sch) => !title.GetValue().IsEmpty() && !msg.GetValue().IsEmpty() && sch.GetValue() > DateTime.Now ) ); this.PermissionCheck = ReactiveCommand.CreateFromTask(async() => { var result = await notificationManager.RequestAccess(); await dialogs.Snackbar("Permission Check Result: " + result); }); this.StartChat = ReactiveCommand.CreateFromTask(() => notificationManager.Send( "Shiny Chat", "Hi, What's your name?", "ChatName", DateTime.Now.AddSeconds(10) ) ); }
public AdapterViewModel(INavigationService navigator, IDialogs dialogs, IBleManager?bleManager = null) { this.IsScanning = bleManager?.IsScanning ?? false; this.CanControlAdapterState = bleManager?.CanControlAdapterState() ?? false; this.WhenAnyValue(x => x.SelectedPeripheral) .Skip(1) .Where(x => x != null) .Subscribe(async x => { this.SelectedPeripheral = null; this.StopScan(); await navigator.Navigate("Peripheral", ("Peripheral", x.Peripheral)); }); this.ToggleAdapterState = ReactiveCommand.CreateFromTask( async() => { if (bleManager == null) { await dialogs.Alert("Platform Not Supported"); } else { if (bleManager.Status == AccessState.Available) { await bleManager.TrySetAdapterState(false); await dialogs.Snackbar("Bluetooth Adapter Disabled"); } else { await bleManager.TrySetAdapterState(true); await dialogs.Snackbar("Bluetooth Adapter Enabled"); } } } ); this.ScanToggle = ReactiveCommand.CreateFromTask( async() => { if (bleManager == null) { await dialogs.Alert("Platform Not Supported"); return; } if (this.IsScanning) { this.StopScan(); } else { this.Peripherals.Clear(); this.IsScanning = true; this.scanSub = bleManager .Scan() .Buffer(TimeSpan.FromSeconds(1)) .Where(x => x?.Any() ?? false) .SubOnMainThread( results => { var list = new List <PeripheralItemViewModel>(); foreach (var result in results) { var peripheral = this.Peripherals.FirstOrDefault(x => x.Equals(result.Peripheral)); if (peripheral == null) { peripheral = list.FirstOrDefault(x => x.Equals(result.Peripheral)); } if (peripheral != null) { peripheral.Update(result); } else { peripheral = new PeripheralItemViewModel(result.Peripheral); peripheral.Update(result); list.Add(peripheral); } } if (list.Any()) { // XF is not able to deal with an observablelist/addrange properly foreach (var item in list) { this.Peripherals.Add(item); } } }, ex => dialogs.Alert(ex.ToString(), "ERROR") ); } } ); }
public void Snack(string message, string title, TypeSnackbar typeSnack) { dial.Snackbar(message, title, typeSnack); }
public ListViewModel(IJobManager jobManager, INavigationService navigator, IDialogs dialogs) { this.jobManager = jobManager; this.dialogs = dialogs; this.Create = navigator.NavigateCommand("CreateJob"); this.LoadJobs = ReactiveCommand.CreateFromTask(async() => { var jobs = await jobManager.GetJobs(); this.Jobs = jobs .Select(x => new CommandItem { Text = x.Identifier, Detail = x.LastRunUtc?.ToLocalTime().ToString("G") ?? "Never Run", PrimaryCommand = ReactiveCommand.CreateFromTask(() => jobManager.Run(x.Identifier)), SecondaryCommand = ReactiveCommand.CreateFromTask(async() => { await jobManager.Cancel(x.Identifier); this.LoadJobs.Execute(null); }) }) .ToList(); }); this.BindBusyCommand(this.LoadJobs); this.RunAllJobs = ReactiveCommand.CreateFromTask(async() => { if (!await this.AssertJobs()) { return; } if (this.jobManager.IsRunning) { await dialogs.Alert("Job Manager is already running"); } else { await this.jobManager.RunAll(); await dialogs.Snackbar("Job Batch Started"); } }); this.CancelAllJobs = ReactiveCommand.CreateFromTask(async _ => { if (!await this.AssertJobs()) { return; } var confirm = await dialogs.Confirm("Are you sure you wish to cancel all jobs?"); if (confirm) { await this.jobManager.CancelAll(); this.LoadJobs.Execute(null); } }); }
public CreateViewModel(INavigationService navigator, INotificationManager notificationManager, IDialogs dialogs) { this.notificationManager = notificationManager; this.NavToChannels = navigator.NavigateCommand("NotificationChannels"); this.WhenAnyValue ( x => x.SelectedDate, x => x.SelectedTime ) .Select(x => new DateTime( x.Item1.Year, x.Item1.Month, x.Item1.Day, x.Item2.Hours, x.Item2.Minutes, x.Item2.Seconds) ) .ToPropertyEx(this, x => x.ScheduledTime) .DisposeWith(this.DestroyWith); this.SelectedDate = DateTime.Now; this.SelectedTime = DateTime.Now.TimeOfDay.Add(TimeSpan.FromMinutes(1)); this.SendNow = ReactiveCommand.CreateFromTask(() => this.BuildAndSend( "现在测试", "这是对sendnow的测试", null )); this.Send = ReactiveCommand.CreateFromTask( async() => { await this.BuildAndSend( this.NotificationTitle, this.NotificationMessage, this.ScheduledTime ); await dialogs.Snackbar("通知发送成功"); }, this.WhenAny( x => x.NotificationTitle, x => x.NotificationMessage, x => x.ScheduledTime, (title, msg, sch) => !title.GetValue().IsEmpty() && !msg.GetValue().IsEmpty() && sch.GetValue() > DateTime.Now ) ); this.PermissionCheck = ReactiveCommand.CreateFromTask(async() => { var result = await notificationManager.RequestAccess(); await dialogs.Snackbar("权限检查结果: " + result); }); this.StartChat = ReactiveCommand.CreateFromTask(() => notificationManager.Send( "聊天室", "嗨,你的名字是?", "ChatName", DateTime.Now.AddSeconds(10) ) ); }