Exemple #1
0
        public string convertDate(string oldDate)
        {
            string newDate = oldDate;

            if (oldDate != null)
            {
                newDate = Convert.ToDateTime(Universal.ConvertToUniversalDate(oldDate)).ToString("yyyy-MM-dd'T'hh:mm:ss.00Z");
            }
            return(newDate);
        }
Exemple #2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.NavigationMode == NavigationMode.New)
            {
                _id = NavigationContext.QueryString.ContainsKey("Id")
                          ? NavigationContext.QueryString["Id"]
                          : String.Empty;
                _listId = NavigationContext.QueryString.ContainsKey("List")
                              ? NavigationContext.QueryString["List"]
                              : String.Empty;
                if (!_id.Equals("new"))
                {
                    var s = from p in App.TaskViewModel.TaskItem
                            where p.id == _id
                            select p;
                    var taskItem = s.SingleOrDefault();
                    if (taskItem != null)
                    {
                        txtbxTitle.Text = taskItem.title;
                        txtNotes.Text   = taskItem.notes ?? String.Empty;

                        //Adjust font size if a lot of notes
                        if (GTaskSettings.TextSize != 0)
                        {
                            //large option is 24 which is option 1
                            //24 - 0*2 = 24, next option is 20 (26 - 4*1 = 22)
                            var size = 24 - (GTaskSettings.TextSize * 4);
                            txtNotes.FontSize = size;
                        }

                        SetRemaining();

                        if (!string.IsNullOrEmpty(taskItem.due))
                        {
                            chkNoDueDate.IsChecked = false;
                            txtDueDate.Value       = DateTime.Parse(Universal.ConvertToUniversalDate(taskItem.due)).Date; //DateTime.Parse(taskItem.due).Date;
                        }
                        else
                        {
                            chkNoDueDate.IsChecked = true;
                        }
                    }
                }
                else
                {
                    PageTitle.Text = PageTitle.Text.Replace("Edit", "Add");

                    SetRemaining();

                    //Based on settings set DefaultReminder
                    if (GTaskSettings.DefaultReminder == 2) //0 = Today's Date, 1 = Tomorrow's Date, 2 = No Reminder
                    {
                        txtDueDate.Value       = null;
                        txtDueDate.IsEnabled   = false;
                        chkNoDueDate.IsChecked = true;
                    }
                    else if (GTaskSettings.DefaultReminder == 0) //Today's Date
                    {
                        if (GTaskSettings.DefaultReminderTomorrowIf && DateTime.Now.TimeOfDay > GTaskSettings.DefaultReminderTomorrowIfTime.TimeOfDay)
                        {
                            txtDueDate.Value = DateTime.Now.AddDays(1).Date;
                        }
                        else
                        {
                            txtDueDate.Value = DateTime.Now.Date;
                        }
                    }
                    else //Tomorrow's Date
                    {
                        txtDueDate.Value = DateTime.Now.AddDays(1).Date;
                    }
                }
            }

            //Turnoff Ads if not paid for
            if (GTaskSettings.IsFree)
            {
                AdControl.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                AdControl.Visibility = System.Windows.Visibility.Collapsed;
            }
        }
Exemple #3
0
        private async void save_Click(object sender, EventArgs e)
        {
            SetProgressIndicator(true);
            SystemTray.ProgressIndicator.Text = "Saving Task";

            if (!string.IsNullOrEmpty(txtbxTitle.Text.Trim()))
            {
                //Disable buttons
                ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = false;
                ((ApplicationBarIconButton)ApplicationBar.Buttons[1]).IsEnabled = false;
                ((ApplicationBarIconButton)ApplicationBar.Buttons[2]).IsEnabled = false;

                if (!_id.Equals("new"))
                {
                    var s = from p in App.TaskViewModel.TaskItem
                            where p.id == _id
                            select p;

                    //Set the variables
                    var taskItem = s.First();

                    string oldNotes = null;
                    string newNotes = null;
                    if (taskItem.notes != null)
                    {
                        oldNotes = taskItem.notes;
                    }
                    if (txtNotes.Text.Trim() != null && txtNotes.Text.Trim() != "")
                    {
                        newNotes = txtNotes.Text.Trim();
                    }

                    string oldDue = null;
                    string newDue = null;
                    if (taskItem.due != null)
                    {
                        oldDue = Convert.ToDateTime(Universal.ConvertToUniversalDate(taskItem.due)).ToString("yyyy-MM-dd'T'hh:mm:ss.00Z");
                    }
                    if (txtDueDate.Value.ToString() != null)
                    {
                        newDue = GetReminderDateTime();
                    }

                    //check for changes before submitting to google
                    if (taskItem.title != txtbxTitle.Text.Trim() || oldNotes != newNotes || oldDue != newDue)
                    {
                        taskItem.title = txtbxTitle.Text.Trim();
                        taskItem.notes = newNotes;
                        taskItem.due   = newDue;

                        //Update the task
                        bool result = await taskItem.Update(GetResponse);

                        // Update the task locally
                        List <TaskListItem> lists = await TaskListHelper.GetTaskListFromApplicationStorage();

                        foreach (TaskListItem list in lists)
                        {
                            foreach (TaskItem task in list.taskList.Where(x => x.id == _id))
                            {
                                task.title   = taskItem.title;
                                task.notes   = taskItem.notes;
                                task.due     = taskItem.due;
                                task.updated = DateTime.UtcNow.ToString("yyyy-MM-dd'T'hh:mm:ss.00Z"); //DateTime.UtcNow.ToString();
                            }
                        }

                        // Resubmit the list to local storage
                        await TaskListHelper.SubmitToLocalStorage(lists);

                        if (result)
                        {
                            if (GTaskSettings.MsgUpdateTask)
                            {
                                MessageBoxResult m = MessageBox.Show("Complete.", "Update Task", MessageBoxButton.OK);
                            }
                        }
                        else
                        {
                            MessageBoxResult m = MessageBox.Show("This task was updated while offline, please sync once back online.", "Offline Mode", MessageBoxButton.OK);
                        }
                    }

                    NavigationService.Navigate(new Uri("/Views/TaskView.xaml?Id=" + _listId, UriKind.RelativeOrAbsolute));
                }
                else //if it is new
                {
                    var t = new TaskItem {
                    };
                    t.title = txtbxTitle.Text.Trim();
                    t.notes = txtNotes.Text.Trim();

                    if (!string.IsNullOrEmpty(txtDueDate.Value.ToString()))
                    {
                        t.due = GetReminderDateTime();
                    }
                    else
                    {
                        t.due = null;
                    }

                    //Create the Task
                    TaskItem result = await TaskHelper.AddTask(t, GetResponse, _listId);

                    if (result != null)
                    {
                        // Refresh the data
                        await GTaskSettings.RefreshData(false, _listId, true);

                        if (GTaskSettings.MsgCreateTask)
                        {
                            MessageBoxResult n = MessageBox.Show("Complete.", "Create Task", MessageBoxButton.OK);
                        }
                    }
                    else
                    {
                        // Create a random ID
                        t.id       = Guid.NewGuid().ToString();
                        t.status   = "needsAction";
                        t.updated  = DateTime.UtcNow.ToString("yyyy-MM-dd'T'hh:mm:ss.00Z");
                        t.kind     = "tasks#task";
                        t.selfLink = "https://www.googleapis.com/tasks/v1/lists/" + _listId + "/tasks/" + t.id;

                        // Add a setting to flag the list
                        var settings = IsolatedStorageSettings.ApplicationSettings;
                        settings.Add("Task_" + t.id + "_Action", "added");
                        settings.Add("Task_" + t.id + "_Timestamp", DateTime.UtcNow.ToString());

                        // Get local storage
                        List <TaskListItem> list = await TaskListHelper.GetTaskListFromApplicationStorage();

                        // Set the position
                        // Check if there are items in the current list
                        if (list.Where(x => x.id == _listId).First().taskList.Count() > 0)
                        {
                            t.position = (double.Parse(list.Where(x => x.id == _listId).First().taskList.OrderBy(x => x.position).First().position) - 1).ToString();
                        }
                        else
                        {
                            t.position = "10000";
                        }

                        // Add the task to the list
                        list.Where(x => x.id == _listId).First().taskList.Insert(0, t);

                        // Resubmit the list to local storage
                        await TaskListHelper.SubmitToLocalStorage(list);

                        MessageBoxResult m = MessageBox.Show("This task was created while offline, please sync once back online.", "Offline Mode", MessageBoxButton.OK);
                    }

                    //Navigate back to TaskView if "New"
                    //Given we don't know the TaskID of this item yet, if you don't return it will create multiple identical tasks
                    NavigationService.Navigate(new Uri("/Views/TaskView.xaml?Id=" + _listId, UriKind.RelativeOrAbsolute));
                }
            }
            else
            {
                MessageBoxResult o = MessageBox.Show("Well, hello there! Do you mind including a Title?", "Title?", MessageBoxButton.OK);
            }

            //re-enable buttons
            ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = true;
            ((ApplicationBarIconButton)ApplicationBar.Buttons[1]).IsEnabled = true;
            ((ApplicationBarIconButton)ApplicationBar.Buttons[2]).IsEnabled = true;

            SetProgressIndicator(false);
        }
Exemple #4
0
        //Updates the status of the tast
        private async void CheckBox_Tap(object sender, RoutedEventArgs e)
        {
            //Hide the content panel to prevent additional checks
            //TasksView.IsEnabled = false;

            //Start Progress Indicator
            SetProgressIndicator(true);
            SystemTray.ProgressIndicator.Text = "Updating Task";

            var currentItem = e.OriginalSource as CheckBox;

            if (currentItem != null)
            {
                var parentListId = ((TaskViewModel)DataContext).ParentList.id;
                var currentId    = currentItem.Tag.ToString();

                var s = from p in App.TaskViewModel.TaskItem
                        where p.id == currentId
                        select p;

                var taskItem = s.First();

                string due = null;
                if (taskItem.due != null)
                {
                    due = Convert.ToDateTime(Universal.ConvertToUniversalDate(taskItem.due)).ToString("yyyy-MM-dd'T'hh:mm:ss.00Z");

                    //due = taskItem.due.ToString("yyyy-MM-dd'T'hh:mm:ss.00Z");// Convert.ToDateTime(taskItem.due).ToString("yyyy-MM-dd'T'hh:mm:ss.00Z");
                }

                bool isChecked = currentItem.IsChecked != null && (bool)currentItem.IsChecked;
                bool results   = await TaskHelper.UpdateTaskStatus(parentListId, currentId, due, isChecked);

                List <Model.TaskListItem> localStorageList = await TaskListHelper.GetTaskListFromApplicationStorage(false);

                // Get the specific task
                if (isChecked)
                {
                    localStorageList.First(x => x.id == parentListId).taskList.First(x => x.id == currentId).status    = "completed";
                    localStorageList.First(x => x.id == parentListId).taskList.First(x => x.id == currentId).completed = DateTime.UtcNow.ToString("yyyy-MM-dd'T'hh:mm:ss.00Z");
                }
                else
                {
                    localStorageList.First(x => x.id == parentListId).taskList.First(x => x.id == currentId).status    = "needsAction";
                    localStorageList.First(x => x.id == parentListId).taskList.First(x => x.id == currentId).completed = null;
                }

                // Update the "updated" field to the current time if it was not updated online
                if (!results)
                {
                    localStorageList.First(x => x.id == parentListId).taskList.First(x => x.id == currentId).updated = DateTime.UtcNow.ToString("yyyy-MM-dd'T'hh:mm:ss.00Z"); // DateTime.UtcNow.ToString();
                }

                await TaskListHelper.SubmitToLocalStorage(localStorageList);

                refresh();

                //if (GTaskSettings.AutoClear == true && isChecked == true)
                //{
                //    ClearCompleted();
                //}
            }

            SetProgressIndicator(false);

            //show the content panel to allow checks
            //TasksView.IsEnabled = true;
        }