public MainViewModel(ITodoService todoService, IMaterialDialog dialogs, IConnectivity connectivity, INavigationService navigator) { this.todoService = todoService; this.dialogs = dialogs; this.navigator = navigator; connectivity .WhenInternetStatusChanged() .ToPropertyEx(this, x => x.IsNetworkAvailable) .DisposeWith(this.DestroyWith); this.Add = navigator.NavigateCommand("EditPage"); this.ToggleShowCompleted = ReactiveCommand.Create(() => { this.ShowCompleted = !this.ShowCompleted; this.DoLoad(); }); this.Load = ReactiveCommand.CreateFromTask(async() => { var todos = await todoService.GetList(this.ShowCompleted); this.List = todos.Select(ToViewModel).ToList(); }); this.WhenAnyValue(x => x.ShowCompleted) .Select(x => x ? "Hide Completed" : "Show Completed") .ToPropertyEx(this, x => x.ToggleShowText); }
public GlobalExceptionHandler(IMaterialDialog dialogs) => this.dialogs = dialogs;
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); }