private void RefreshCounters(TaskDataSource taskDataSource) { this.todaysCount.Text = taskDataSource.TodaysTasks.Count.ToString(); this.overdueCount.Text = taskDataSource.OverdueTasks.Count.ToString(); this.notCompletedCount.Text = taskDataSource.NotCompletedTasks.Count.ToString(); this.completedCount.Text = taskDataSource.CompletedTasks.Count.ToString(); }
async private void markCompleted_Click(object sender, RoutedEventArgs e) { markTaskCompleted(selectedTask); TaskDataSource taskDataSource = (TaskDataSource)App.Current.Resources["taskDataSource"]; taskDataSource.RefreshLists(); RefreshCounters(taskDataSource); await showTask(selectedTask); }
private void delete_Click(object sender, RoutedEventArgs e) { TaskDataSource taskDataSource = (TaskDataSource)App.Current.Resources["taskDataSource"]; Data.Model.Task toDelete = null; foreach (Data.Model.TaskList list in taskDataSource.TaskLists) { if (list.Title == selectedTask.ListTitle) { foreach (Data.Model.Task task in list.Tasks) { if (task.Id != null && task.Id == selectedTask.Id) { task.Deleted = true; toDelete = task; break; } } if (toDelete == null) { // not found, probably task not synchronized so does not have id, trying to find by title foreach (Data.Model.Task task in list.Tasks) { if (task.Title != null && task.Title == selectedTask.Title) { task.Deleted = true; toDelete = task; break; } } } } } if (toDelete != null) { showEmptyTaskTextBlock(Messages.GetMsgValue(MessageKey.SELECT_TASK)); // trying to delete from tasksView ObservableCollection <Data.Model.Task> tasksFromView = (ObservableCollection <Data.Model.Task>)tasksView.ItemsSource; Data.Model.Task toDeleteFromVisible = null; foreach (Data.Model.Task taskFromView in tasksFromView) { if ((taskFromView.Id != null && taskFromView.Id == toDelete.Id) || taskFromView.Title == toDelete.Title) { toDeleteFromVisible = taskFromView; break; } } if (toDeleteFromVisible != null) { tasksFromView.Remove(toDeleteFromVisible); } taskDataSource.RefreshLists(); RefreshCounters(taskDataSource); hideTaskEditButtons(); } }
/// <summary> /// Invoked when application execution is being suspended. Application state is saved /// without knowing whether the application will be terminated or resumed with the contents /// of memory still intact. /// </summary> /// <param name="sender">The source of the suspend request.</param> /// <param name="e">Details about the suspend request.</param> async private void OnSuspending(object sender, SuspendingEventArgs e) { var deferral = e.SuspendingOperation.GetDeferral(); TaskDataSource taskDataSource = (TaskDataSource)App.Current.Resources["taskDataSource"]; await taskDataSource.StoreTaskListsAsync(); //TODO: Save application state and stop any background activity deferral.Complete(); }
private void addList_Click(object sender, RoutedEventArgs e) { Popup myPopup = new Popup(); myPopup.HorizontalAlignment = HorizontalAlignment.Center; myPopup.VerticalAlignment = VerticalAlignment.Center; myPopup.IsLightDismissEnabled = true; Border b = new Border(); b.BorderBrush = new SolidColorBrush(Colors.Gray); b.BorderThickness = new Thickness(2); b.Width = 400; StackPanel s = new StackPanel(); b.Child = s; s.Orientation = Orientation.Vertical; s.Width = 400; s.Background = new SolidColorBrush(Colors.White); TextBlock text = new TextBlock(); text.Text = "Name for the list:"; text.Margin = new Thickness(10, 5, 20, 0); text.Foreground = new SolidColorBrush(Colors.SteelBlue); text.FontSize = 16; s.Children.Add(text); TextBox input = new TextBox(); s.Children.Add(input); input.Margin = new Thickness(10, 5, 10, 5); Button save = new Button(); save.HorizontalAlignment = HorizontalAlignment.Right; save.Margin = new Thickness(10, 0, 10, 5); save.Content = "Save"; save.Click += new RoutedEventHandler(delegate(object sender1, RoutedEventArgs ev) { TaskDataSource taskDataSource = (TaskDataSource)App.Current.Resources["taskDataSource"]; Data.Model.TaskList t = new Data.Model.TaskList(); t.Title = input.Text; t.Updated = DateTime.Now; taskDataSource.TaskLists.Add(t); taskDataSource.RefreshLists(); myPopup.IsOpen = false; }); s.Children.Add(save); myPopup.Child = b; myPopup.IsOpen = true; myCanvas1.Children.Add(myPopup); }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used when the application is launched to open a specific file, to display /// search results, and so forth. /// </summary> /// <param name="args">Details about the launch request and process.</param> async protected override void OnLaunched(LaunchActivatedEventArgs args) { Frame rootFrame = Window.Current.Content as Frame; var connectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile(); if (connectionProfile != null) { TaskDataSource taskDataSource = (TaskDataSource)App.Current.Resources["taskDataSource"]; if (taskDataSource != null) { if (taskDataSource.TaskLists.Count == 0) { await taskDataSource.GetTaskListsAsync(false); } } } else { var messageDialog = new Windows.UI.Popups.MessageDialog("An internet connection is needed to download feeds. Please check your connection and restart the app."); var result = messageDialog.ShowAsync(); } // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter if (!rootFrame.Navigate(typeof(MainPage), args.Arguments)) { throw new Exception("Failed to create initial page"); } } // Ensure the current window is active Window.Current.Activate(); }
/* Handler for click on 'Not completed' button. */ private void notCompletedButton_Click(object sender, RoutedEventArgs e) { tasksView.Opacity = 0; HideEmptyTextBlockIfNeeded(); TaskDataSource taskDataSource = (TaskDataSource)App.Current.Resources["taskDataSource"]; tasksView.ItemsSource = taskDataSource.NotCompletedTasks; if (((ObservableCollection <Kompitu.Data.Model.Task>)tasksView.ItemsSource).Count == 0) { showEmptyTextBlock(Messages.GetMsgValue(MessageKey.NOT_COMPLETED_EMPTY)); } selectedTaskList = null; ShowTaskList.Begin(); }
/* Events handling */ /* Handler for click on 'For today' button. */ private void todaysButton_Click(object sender, RoutedEventArgs e) { tasksView.Opacity = 0; HideEmptyTextBlockIfNeeded(); TaskDataSource taskDataSource = (TaskDataSource)App.Current.Resources["taskDataSource"]; // call datasource to produce list of tasks for today tasksView.ItemsSource = taskDataSource.TodaysTasks; if (((ObservableCollection <Kompitu.Data.Model.Task>)tasksView.ItemsSource).Count == 0) { showEmptyTextBlock(Messages.GetMsgValue(MessageKey.TODAYS_EMPTY)); } selectedTaskList = null; ShowTaskList.Begin(); }
private void markListCompleted_Click(object sender, RoutedEventArgs e) { foreach (Data.Model.Task task in tasksView.SelectedItems) { if (task.Status != "completed") { markTaskCompleted(task); } } TaskDataSource taskDataSource = (TaskDataSource)App.Current.Resources["taskDataSource"]; taskDataSource.RefreshLists(); RefreshCounters(taskDataSource); showEmptyTaskTextBlock(Messages.GetMsgValue(MessageKey.SELECT_TASK)); hideTaskEditButtons(); }
private void SaveEditedTask() { bool shouldReload = false; if (selectedTask.Title != taskTitleTextBox.Text) { shouldReload = true; } selectedTask.Updated = DateTime.Now; this.taskUpdatedDateTextBox.Text = selectedTask.Updated.ToString(); selectedTask.Title = taskTitleTextBox.Text; selectedTask.Notes = taskNotesTextBox.Text; DateTime newDue; if (taskDueDateTextBox.Text == "None") { newDue = DateTime.MinValue; } else { newDue = DateTime.Parse(taskDueDateTextBox.Text); } if (selectedTask.Due != newDue) { shouldReload = true; if (newDue == DateTime.MinValue || (DateTime.Compare(selectedTask.Due, DateTime.Now) < 0 && DateTime.Compare(newDue, DateTime.Now) >= 0)) { // overdue deleted, changing color taskDueDateLabel.Foreground = new SolidColorBrush(Colors.Gray); taskDueDateTextBox.Foreground = new SolidColorBrush(Colors.Gray); } else if ((DateTime.Compare(selectedTask.Due, DateTime.Now) >= 0 || selectedTask.Due == DateTime.MinValue) && DateTime.Compare(newDue, DateTime.Now) < 0) { // overdue set, changing to red taskDueDateLabel.Foreground = new SolidColorBrush(Colors.Red); taskDueDateTextBox.Foreground = new SolidColorBrush(Colors.Red); } } selectedTask.Due = newDue; if (shouldReload) { TaskDataSource dataSource = (TaskDataSource)App.Current.Resources["taskDataSource"]; dataSource.RefreshLists(); RefreshCounters(dataSource); } }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="navigationParameter">The parameter value passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested. /// </param> /// <param name="pageState">A dictionary of state preserved by this page during an earlier /// session. This will be null the first time a page is visited.</param> protected override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState) { TaskDataSource taskDataSource = (TaskDataSource)App.Current.Resources["taskDataSource"]; if (taskDataSource != null) { this.taskListsView.ItemsSource = taskDataSource.VisibleTaskLists; // Binding myBinding = new Binding(); //myBinding.Source = taskDataSource.VisibleTaskLists; //myBinding.Path = new PropertyPath("SomeString") //myBinding.Mode = BindingMode.TwoWay; //myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; // BindingOperations.SetBinding(taskListsView, ListView.ItemsSourceProperty, myBinding); RefreshCounters(taskDataSource); showEmptyTextBlock(Messages.GetMsgValue(MessageKey.SELECT_LIST)); showEmptyTaskTextBlock(Messages.GetMsgValue(MessageKey.SELECT_TASK)); } }
async private void sync_Click(object sender, RoutedEventArgs e) { Synchronizer synchronizer = await Synchronizer.GetInstance(); if (synchronizer.IsInternetAvailable()) { progressBar.Visibility = Windows.UI.Xaml.Visibility.Visible; TaskDataSource taskDataSource = (TaskDataSource)App.Current.Resources["taskDataSource"]; bool success = await synchronizer.Synchronize(); if (success) { // pobranie jeszcze raz i zastapienie await taskDataSource.GetTaskListsAsync(true); showEmptyTextBlock(Messages.GetMsgValue(MessageKey.SELECT_LIST)); tasksView.ItemsSource = null; taskDataSource.RefreshLists(); RefreshCounters(taskDataSource); } else { var messageDialog = new Windows.UI.Popups.MessageDialog( Messages.GetMsgValue(MessageKey.SYNC_ERROR_CNTNT), Messages.GetMsgValue(MessageKey.SYNC_ERROR)); } progressBar.Visibility = Windows.UI.Xaml.Visibility.Collapsed; } else { var messageDialog = new Windows.UI.Popups.MessageDialog( Messages.GetMsgValue(MessageKey.NO_INTERNET_CNTNT), Messages.GetMsgValue(MessageKey.NO_INTERNET)); messageDialog.Commands.Add(new UICommand("OK")); } }
async private void removeList_Click(object sender, RoutedEventArgs e) { Data.Model.TaskList selectedList = (Data.Model.TaskList)taskListsView.SelectedItem; if (selectedList.Tasks.Count > 0) { var messageDialog = new Windows.UI.Popups.MessageDialog( Messages.GetMsgValue(MessageKey.DELETE_LIST_WARN_CNTNT), Messages.GetMsgValue(MessageKey.DELETE_LIST_WARN_HDR)); bool confirmed = false; messageDialog.Commands.Add(new UICommand("Yes", (command) => { confirmed = true; })); messageDialog.Commands.Add(new UICommand("No")); messageDialog.DefaultCommandIndex = 1; await messageDialog.ShowAsync(); if (!confirmed) { return; } } TaskDataSource taskDataSource = (TaskDataSource)App.Current.Resources["taskDataSource"]; foreach (Data.Model.TaskList list in taskDataSource.TaskLists) { if (list.Id == selectedList.Id) { list.Deleted = true; } } taskDataSource.RefreshLists(); RefreshCounters(taskDataSource); }
/* Handler for click event on item of taskListsView. */ private void taskListsView_ItemClick(object sender, ItemClickEventArgs e) { Kompitu.Data.Model.TaskList taskList = (Kompitu.Data.Model.TaskList)e.ClickedItem; /*if (editMode) * { * await PopupEditWarningDialog(); * return; * * komentuje bo nie pamietam po co to bylo * if (taskList.Tasks.Count != 0) * { * DisableTaskEditMode(taskList.Tasks[0]); * } * else * { * DisableTaskEditMode(null); * } * } */ //HideTaskList.Begin(); tasksView.Opacity = 0; HideEmptyTextBlockIfNeeded(); TaskDataSource taskDataSource = (TaskDataSource)App.Current.Resources["taskDataSource"]; //this.tasksView.ItemsSource = taskList.Tasks; this.tasksView.ItemsSource = taskList.OrderedTasks; if (((ObservableCollection <Kompitu.Data.Model.Task>)tasksView.ItemsSource).Count == 0) { showEmptyTextBlock(Messages.GetMsgValue(MessageKey.LIST_EMPTY)); } // this.selectedTask = null; ShowTaskList.Begin(); this.selectedTaskList = taskList; }
private void SaveNewTask() { string selectedList = null; // show select list popup Popup myPopup = new Popup(); myPopup.HorizontalAlignment = HorizontalAlignment.Center; myPopup.VerticalAlignment = VerticalAlignment.Center; myPopup.IsLightDismissEnabled = false; Border b = new Border(); b.BorderBrush = new SolidColorBrush(Colors.Gray); b.BorderThickness = new Thickness(2); b.Width = 400; StackPanel s = new StackPanel(); b.Child = s; s.Orientation = Orientation.Vertical; s.Width = 400; s.Background = new SolidColorBrush(Colors.White); TextBlock text = new TextBlock(); text.Text = "Select a list for the task:"; text.Margin = new Thickness(10, 5, 20, 0); text.Foreground = new SolidColorBrush(Colors.SteelBlue); text.FontSize = 16; s.Children.Add(text); ComboBox combo = new ComboBox(); TaskDataSource taskDataSource = (TaskDataSource)App.Current.Resources["taskDataSource"]; combo.ItemsSource = taskDataSource.VisibleTaskLists; combo.DisplayMemberPath = "Title"; s.Children.Add(combo); combo.Margin = new Thickness(10, 5, 10, 5); combo.SelectedIndex = combo.Items.Count - 1; Button ok = new Button(); ok.HorizontalAlignment = HorizontalAlignment.Right; ok.Margin = new Thickness(10, 0, 10, 5); ok.Content = "OK"; ok.Click += new RoutedEventHandler(async delegate(object sender1, RoutedEventArgs ev) { selectedList = ((Data.Model.TaskList)combo.SelectedValue).Title; Data.Model.TaskList selectedListObject = Data.Model.TaskList.GetByTitle(selectedList, taskDataSource.VisibleTaskLists); foreach (Data.Model.Task selectedListTask in selectedListObject.Tasks) { if (selectedListTask.Title == taskTitleTextBox.Text) { var messageDialog = new Windows.UI.Popups.MessageDialog( Messages.GetMsgValue(MessageKey.TASK_TITLE_EXISTS_CNTNT), Messages.GetMsgValue(MessageKey.TASK_TITLE_EXISTS_HDR)); messageDialog.Commands.Add(new UICommand("OK")); messageDialog.DefaultCommandIndex = 0; await messageDialog.ShowAsync(); myPopup.IsOpen = false; return; } } myPopup.IsOpen = false; Data.Model.Task task = new Data.Model.Task(); task.Updated = DateTime.Now; this.taskUpdatedDateLabel.Text = "Updated"; this.taskUpdatedDateTextBox.Text = task.Updated.ToString(); task.Title = taskTitleTextBox.Text; task.ListTitle = selectedList; task.Status = "needsAction"; if (taskDueDateTextBox.Text == "None") { task.Due = DateTime.MinValue; } else { task.Due = DateTime.Parse(taskDueDateTextBox.Text); } if (task.Due == DateTime.MinValue || DateTime.Compare(task.Due, DateTime.Now) >= 0) { // not overdue taskDueDateLabel.Foreground = new SolidColorBrush(Colors.Gray); taskDueDateTextBox.Foreground = new SolidColorBrush(Colors.Gray); } else if (task.Due != DateTime.MinValue && DateTime.Compare(task.Due, DateTime.Now) < 0) { taskDueDateLabel.Foreground = new SolidColorBrush(Colors.Red); taskDueDateTextBox.Foreground = new SolidColorBrush(Colors.Red); } task.Notes = taskNotesTextBox.Text; task.ListTitle = selectedList; bool added = false; foreach (Data.Model.TaskList list in taskDataSource.TaskLists.Where(l => l.Title == selectedList)) { list.Tasks.Add(task); added = true; } if (added) { taskListTextBox.Text = selectedList; selectedTask = task; taskDataSource.RefreshLists(); RefreshCounters(taskDataSource); DisableTaskEditMode(selectedTask); if (selectedTaskList != null) { if (selectedList == selectedTaskList.Title) { ((ObservableCollection <Data.Model.Task>)tasksView.ItemsSource).Add(task); } } } }); s.Children.Add(ok); myPopup.Child = b; myPopup.IsOpen = true; myCanvas1.Children.Add(myPopup); }
/// <summary> /// Preserves state associated with this page in case the application is suspended or the /// page is discarded from the navigation cache. Values must conform to the serialization /// requirements of <see cref="SuspensionManager.SessionState"/>. /// </summary> /// <param name="pageState">An empty dictionary to be populated with serializable state.</param> async protected override void SaveState(Dictionary <String, Object> pageState) { TaskDataSource taskDataSource = (TaskDataSource)App.Current.Resources["taskDataSource"]; await taskDataSource.StoreTaskListsAsync(); }
private void renameList_Click(object sender, RoutedEventArgs e) { Data.Model.TaskList selectedList = (Data.Model.TaskList)taskListsView.SelectedItem; Popup myPopup = new Popup(); myPopup.HorizontalAlignment = HorizontalAlignment.Center; myPopup.VerticalAlignment = VerticalAlignment.Center; myPopup.IsLightDismissEnabled = true; Border b = new Border(); b.BorderBrush = new SolidColorBrush(Colors.Gray); b.BorderThickness = new Thickness(2); b.Width = 400; StackPanel s = new StackPanel(); b.Child = s; s.Orientation = Orientation.Vertical; s.Width = 400; s.Background = new SolidColorBrush(Colors.White); TextBlock text = new TextBlock(); text.Text = "New name for the list:"; text.Margin = new Thickness(10, 5, 20, 0); text.Foreground = new SolidColorBrush(Colors.SteelBlue); text.FontSize = 16; s.Children.Add(text); TextBox input = new TextBox(); input.Text = selectedList.Title; s.Children.Add(input); input.Margin = new Thickness(10, 5, 10, 5); Button save = new Button(); save.HorizontalAlignment = HorizontalAlignment.Right; save.Margin = new Thickness(10, 0, 10, 5); save.Content = "Save"; save.Click += new RoutedEventHandler(async delegate(object sender1, RoutedEventArgs ev) { TaskDataSource taskDataSource = (TaskDataSource)App.Current.Resources["taskDataSource"]; if (!taskDataSource.ListTitleExists(input.Text)) { foreach (Data.Model.TaskList list in taskDataSource.TaskLists) { if (list.Id == selectedList.Id) { list.Title = input.Text; list.Updated = DateTime.Now; foreach (Data.Model.Task task in list.Tasks) { task.ListTitle = input.Text; } } } taskDataSource.RefreshLists(); myPopup.IsOpen = false; } else { var messageDialog = new Windows.UI.Popups.MessageDialog( Messages.GetMsgValue(MessageKey.LIST_TITLE_EXISTS_CNTNT), Messages.GetMsgValue(MessageKey.LIST_TITLE_EXISTS_HDR)); messageDialog.Commands.Add(new UICommand("OK")); messageDialog.DefaultCommandIndex = 1; await messageDialog.ShowAsync(); } }); s.Children.Add(save); myPopup.Child = b; myPopup.IsOpen = true; myCanvas1.Children.Add(myPopup); }