public SettingsViewModel(IAppService appService) { AppService = appService; LoadSettings(appService.AppSettings); ClearStatistic = new Command( execute: async() => { var displayAlert = new DialogProvider(Page); var changeTask = await displayAlert.DisplayAlert("Clear Task Statistics", "All statistics about finished task will be deleted. Did you want to continue.", "ok", "cancel"); if (!changeTask) { return; } AppService.ClearStatistics(); } ); Save = new Command( execute: async() => { var settings = this.CreatePomodoroSettings(); if (settings != null) { IsBusy = true; var isSaved = await AppService.SaveSettingsAsync(settings); if (isSaved) { var notificator = DependencyService.Get <INotification>(); notificator.Show("Saved."); } IsBusy = false; } } ); LoadDefault = new Command( execute: async() => { var settings = AppConstants.DEFAULT_APP_SETTINGS; if (settings != null) { this.IsBusy = true; await AppService.SaveSettingsAsync(settings); this.LoadSettings(settings); this.IsBusy = false; } } ); }
protected override bool OnBackButtonPressed() { try { bool exitapp = true;; var previous = PageProvider.GetPrevious(); if (previous == null) { if (AppMainService.Instance.PomodoroStatus?.TimerState == Enums.TimerState.Running) { Device.BeginInvokeOnMainThread(async() => { var displayAlert = new DialogProvider(Detail); var cancelRunnigTimer = await displayAlert.DisplayAlert("Cancel Timer", "Running timer will be stopped. Do you want to continue ?", "ok", "cancel"); if (cancelRunnigTimer) { AppMainService.Instance.StopPomodoro(); exitapp = true; } else { exitapp = false; } if (exitapp) { OnBackButtonPressed(); } }); return(true); } else { base.OnBackButtonPressed(); return(false); } } else { Detail = previous; return(true); } } catch (Exception ex) { Debug.Fail(ex.Message); return(true); } }
private async void DeleteItem(object item) { var displayAlert = new DialogProvider(Page); var changeTask = await displayAlert.DisplayAlert("Delete Task", "Task will be deleted. Did you want to continue.", "ok", "cancel"); if (!changeTask) { return; } var deletedTask = item as UserTask; var result = await AppService.RemoveUserTask(deletedTask); if (result) { UserTasks.Remove(deletedTask); } }
public HomeViewModel(IAppService appService) { TickCount = 90; AppService = appService; ActiveTask = AppService.ActiveTask; UserTasks = new ObservableCollection <UserTaskViewModel>(AppService.UserTasks.Select(x => new UserTaskViewModel(x))); AppService.UserTaskRemovedEvent += OnUserTaskRemoved; AppService.TimerFinishedEvent += OnTimerFinished; AppService.UserTaskModifiedEvent += OnUserTaskUpdate; AppService.AppResumedEvent += OnAppResumed; AppService.PomodoroTimerStateChangedEvent += OnPomodoroStateChanged; LoadState(appService.PomodoroStatus); ChangeTask = new Command( execute: async(o) => { if (o is UserTaskViewModel userTaskViewModel) { if (userTaskViewModel.Id == ActiveTask.Id) { return; } if (IsPomodoro && IsTimerRunning) { var displayAlert = new DialogProvider(Page); var changeTask = await displayAlert.DisplayAlert("Change Task", "Pomodoro will be cancelled. Did you want to continue", "ok", "cancel"); if (!changeTask) { return; } } StopTimer.Execute(null); ActiveTask = userTaskViewModel.UserTask; AppService.SetActiveTask(userTaskViewModel.UserTask); } } ); SetTimerStatus = new Command( execute: () => { if (IsPomodoro && IsTimerRunning) { TimerInfo = AppService.PausePomodoro(); //StopTimerTick(); } else { TimerInfo = AppService.StartPomodoro(); //StartTimerTick(); } } ); StopTimer = new Command( execute: () => { //TimerInfo.TimerState = TimerState.Stoped; //TimerInfo.PomodoroState = PomodoroState.Ready; //RemainingTimeValue = TimeSpan.Zero; //Tick = 0; //OnPropertyChanged("TimerInfo"); Tick = 0; AppService.StopPomodoro(); //StopTimerTick(); } ); }