/// <summary> /// Adds newly created task to the <see cref="TimeTasksCalculator"/> /// </summary> public void AddNewTask() { // Check if we have everything we need for new task to create if (!ValidateUserInput()) { // Display message to the user mUIManager.DisplayPopupMessageAsync(new PopupMessageViewModel(LocalizationResource.InvalidData, LocalizationResource.ProvidedTaskDataInvalid)); // Stay at this page so user can correct his mistakes return; } // Data is correct, create new context out of it var newTask = new TimeTaskContext { Id = TaskId, Name = TaskName, Description = TaskDescription, Tags = TaskTagsString.SplitTagsString(), Type = TaskType, AssignedTime = TaskConstantTime, HasConstantTime = TaskHasConstantTime, IsImportant = TaskImportance, IsImmortal = TaskImmortality, Priority = (Priority)TaskPrioritySliderValue, CreationDate = DateTime.Now, SessionProgress = 0, Progress = TaskProgress, MaxProgress = TaskMaximumProgress }; // Pass it to the service to handle it mTimeTasksService.SaveTask(newTask); // Close this page mUIManager.GoBackToPreviousPage(this); // Refresh UI list so it gets new task TaskListHelpers.RaiseRefreshEvent(); }
/// <summary> /// Ends current user session, if he decides to /// </summary> private async void EndSessionAsync() { // Ask the user if he's certain to end the session var popupViewModel = new PopupMessageViewModel ( LocalizationResource.SessionFinished, LocalizationResource.QuestionAreYouSureToFinishSession, LocalizationResource.Yes, LocalizationResource.No ); var userResponse = await mUIManager.DisplayPopupMessageAsync(popupViewModel); // If he agreed... if (userResponse) { // End the session mSessionHandler.EndSession(); } }
/// <summary> /// Checks if user has picked the right time and calculates new session for him /// Which leads to next page /// </summary> private async Task CalculateSessionAsync() { // Save used mode mSettingsProvider.SetSetting(new SettingsPropertyInfo { Name = nameof(SessionTimeAsFinishTime), Value = SessionTimeAsFinishTime, Type = typeof(bool) }); var time = UserTime; // Alternative mode if (SessionTimeAsFinishTime) { // Subtract Now converted to timespan time -= DateTime.Now - DateTime.Today; // If negative then it should be above 24 hours if (time < TimeSpan.FromSeconds(-60)) { time += TimeSpan.FromHours(24); } } // Try to set user's selected time as session time var result = mSessionHandler.UpdateDuration(time); // If user's selected time is not enough to start a session... if (!result) { // Show user an error await mUIManager.DisplayPopupMessageAsync(new PopupMessageViewModel(LocalizationResource.Error, LocalizationResource.NotEnoughTimeForSession)); // Don't do any further actions return; } // Otherwise, go to next page which shows a summary of calculated user session mApplicationViewModel.GoToPage(ApplicationPage.TasksSummary); }