public ChannelListViewModel(INavigationService navigator, INotificationManager notifications, IDialogs dialogs) { this.Create = navigator.NavigateCommand("NotificationChannelCreate"); this.LoadChannels = ReactiveCommand.CreateFromTask(async() => { var channels = await notifications.GetChannels(); this.Channels = channels .Select(x => new CommandItem { Text = x.Identifier, SecondaryCommand = ReactiveCommand.CreateFromTask(async() => { var confirm = await dialogs.Confirm("Are you sure you wish to delete this channel?"); if (confirm) { await notifications.RemoveChannel(x.Identifier); this.LoadChannels.Execute(null); } }) }) .ToList(); this.RaisePropertyChanged(nameof(this.Channels)); }); }
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)); }); }
public MainViewModel(IDataSyncManager manager, SampleDataSyncDelegate sdelegate, INavigationService navigator, IDialogs dialogs, Shiny.IMessageBus messageBus) { this.manager = manager; this.navigator = navigator; var faker = new Faker <MyEntity>() .RuleFor(x => x.FirstName, (f, _) => f.Name.FirstName()) .RuleFor(x => x.LastName, (f, _) => f.Name.LastName()); this.IsSyncEnabled = manager.Enabled; this.AllowOutgoing = sdelegate.AllowOutgoing; this.GenerateTestItem = ReactiveCommand.CreateFromTask(async() => { var entity = faker.Generate(1).First(); await manager.Save(entity, SyncOperation.Create); await this.BindList(); }); this.ForceRun = ReactiveCommand.CreateFromTask(() => //dialogs.LoadingTask(() => manager.ForceRun()) manager.ForceRun() ); this.Clear = ReactiveCommand.CreateFromTask(async() => { var result = await dialogs.Confirm("Are you sure you wish to clear the data sync pending queue?"); if (result) { await this.manager.ClearPending(); await this.BindList(); } }); this.WhenAnyValue(x => x.AllowOutgoing) .Skip(1) .Subscribe(x => sdelegate.AllowOutgoing = x) .DisposeWith(this.DestroyWith); this.WhenAnyValue(x => x.IsSyncEnabled) .Skip(1) .Subscribe(x => manager.Enabled = x) .DisposeWith(this.DestroyWith); messageBus .Listener <SyncItem>() .SubOnMainThread(x => this.Remove(x.Id)) .DisposeWith(this.DestroyWith); }
public override async void OnNavigatedTo(INavigationContext context) { if (!context.Attribute.IsRestore()) { await Navigator.PostActionAsync(() => BusyState.Using(async() => { if (await dialogs.Confirm("Cancel ?", acceptButton: "Yes", cancelButton: "No")) { await Navigator.ForwardAsync(ViewId.Menu); } })); } }
public PendingViewModel(INavigationService navigation, IHttpTransferManager httpTransfers, IDialogs dialogs) { this.httpTransfers = httpTransfers; this.dialogs = dialogs; this.Create = navigation.NavigateCommand("CreateTransfer"); this.Load = ReactiveCommand.CreateFromTask(async() => { var transfers = await httpTransfers.GetTransfers(); this.Transfers = transfers .Select(transfer => { var vm = new HttpTransferViewModel { Identifier = transfer.Identifier, Uri = transfer.Uri, IsUpload = transfer.IsUpload, Cancel = ReactiveCommand.CreateFromTask(async() => { var confirm = await dialogs.Confirm("Are you sure you want to cancel all transfers?", "Confirm", "Yes", "No"); if (confirm) { await this.httpTransfers.Cancel(transfer.Identifier); this.Load.Execute(null); } }) }; ToViewModel(vm, transfer); return(vm); }) .ToList(); }); this.CancelAll = ReactiveCommand.CreateFromTask(async() => { await httpTransfers.Cancel(); this.Load.Execute(null); }); this.BindBusyCommand(this.Load); }
public MonitoringViewModel(INavigationService navigator, IDialogs dialogs, IBeaconMonitoringManager?beaconManager = null) { this.Add = navigator.NavigateCommand("CreateBeacon"); this.Load = ReactiveCommand.CreateFromTask(async() => { if (beaconManager == null) { await dialogs.Alert("Beacon monitoring is not supported on this platform"); return; } var regions = await beaconManager.GetMonitoredRegions(); this.Regions = regions .Select(x => new CommandItem { Text = $"{x.Identifier}", Detail = $"{x.Uuid}/{x.Major ?? 0}/{x.Minor ?? 0}", PrimaryCommand = ReactiveCommand.CreateFromTask(async() => { await beaconManager.StopMonitoring(x.Identifier); this.Load.Execute(null); }) }) .ToList(); }); this.StopAllMonitoring = ReactiveCommand.CreateFromTask( async() => { var result = await dialogs.Confirm("Are you sure you wish to stop all monitoring"); if (result) { await beaconManager.StopAllMonitoring(); this.Load.Execute(null); } }, Observable.Return(beaconManager != null) ); }
public PendingViewModel(INotificationManager notifications, IDialogs dialogs) { this.Load = ReactiveCommand.CreateFromTask(async() => { var pending = await notifications.GetPending(); this.PendingList = pending .Select(x => new CommandItem { Text = $"[{x.Id}] {x.Title}", Detail = $"[{x.ScheduleDate.Value}] {x.Message}", PrimaryCommand = ReactiveCommand.CreateFromTask(async() => { await notifications.Cancel(x.Id); ((ICommand)this.Load).Execute(null); }) }) .ToList(); }); this.BindBusyCommand(this.Load); this.Clear = ReactiveCommand.CreateFromTask( async() => { var confirm = await dialogs.Confirm("Clear All Pending Notifications?"); if (confirm) { await notifications.Clear(); ((ICommand)this.Load).Execute(null); } } //this.WhenAny( // x => x.PendingList, // x => x.GetValue()?.Any() ?? false //) ); }
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() ) ); }
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); } }); }