Esempio n. 1
0
        //Refreshes the token then calls RetryGetTaskList which gets the latest task lists
        #region Get task Lists
        public static async Task GetTaskList(Action <ObservableCollection <TaskListItem> > callback, bool alertWhenNoConnection = false, bool refresh = false)
        {
            // Sync the latest data between the api and the local storage
            await GTaskSettings.RefreshData(alertWhenNoConnection, null, refresh);

            // Get the actual task list
            await RetryGetTaskList(new ObservableCollection <object> {
                callback
            });
        }
Esempio n. 2
0
        public static async Task ClearCompletedTasks(string id)
        {
            const string message     = "Hmmm... I am having a hard time Clearing your Completed Tasks, can you try again?";
            var          restRequest = new RestRequest(Method.POST)
            {
                Resource = String.Format("https://www.googleapis.com/tasks/v1/lists/" + id + "/clear"),
                Timeout  = GTaskSettings.RequestTimeout
            };
            var restResponse = await GTaskSettings.ExecuteRestTask(restRequest);

            try
            {
                if (restResponse.StatusCode == HttpStatusCode.NoContent)
                {
                    //success - hide completed locally
                    // Update the task locally
                    List <TaskListItem> lists = await TaskListHelper.GetTaskListFromApplicationStorage();

                    foreach (TaskListItem list in lists.Where(x => x.id == id))
                    {
                        foreach (TaskItem task in list.taskList.Where(x => x.status == "completed" && (x.hidden == null || x.hidden == "true")))
                        {
                            task.hidden  = "True";
                            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);
                }
                else
                {
                    if (GTaskSettings.MsgError)
                    {
                        MessageBox.Show(message);
                    }
                }
            }
            catch
            {
                if (GTaskSettings.MsgError)
                {
                    MessageBox.Show(message);
                }
            }
        }
Esempio n. 3
0
        public static async Task <bool> UpdateTaskStatus(string parentListId, string currentTaskId, string due, bool isChecked)
        {
            //const string message = "Fiddlesticks.. I wasn't able to Update the Task,  can you try again?";
            var restRequest = new RestRequest(Method.PUT)
            {
                RequestFormat = DataFormat.Json,
                Resource      = String.Format("https://www.googleapis.com/tasks/v1/lists/{0}/tasks/{1}", parentListId, currentTaskId),
                Timeout       = GTaskSettings.RequestTimeout
            };
            var check   = (bool)isChecked ? "completed" : "needsAction";
            var dueDate = ",due: \"" + due + "\"";
            var param   = string.Empty;

            //Conditional on if there is a due date or not, if there isn't it sets it to No Due Date automatically, if there is we send it to retain the date an item was completed
            if (due != null)
            {
                param = "{id:\"" + currentTaskId + "\",status:\"" + check + "\"" + dueDate + "}";
            }
            else
            {
                param = "{id:\"" + currentTaskId + "\",status:\"" + check + "\"}";
            }
            restRequest.AddParameter("application/json", param, ParameterType.RequestBody);

            //Make the call
            var restResponse = await GTaskSettings.ExecuteRestTask(restRequest);

            try
            {
                if (restResponse.StatusCode == HttpStatusCode.OK)
                {
                    //success
                    return(true);
                }
            }
            catch
            {
            }

            return(false);
        }
Esempio n. 4
0
        public static async void Reminder()
        {
            //Update License (eg. If someone bought the app)
            SetLicense();

            //Set ApplicationTitle
            if (GTaskSettings.IsFree)
            {
                GTaskSettings.ApplicationTitle = "GTask";
            }
            else
            {
                GTaskSettings.ApplicationTitle = "GTask+";
            }

            //New Feature Popup (increment 1 each time you want it to show up)
            int NumFeature = 9;

            if (GTaskSettings.NewFeatureCount < NumFeature)
            {
                MessageBox.Show("- Offline Mode \r\n- Speech-to-Text \r\n- New Icons \r\n- Auto-Sync\r\n- More Customizations in Settings", "New Features!", MessageBoxButton.OK);

                if (GTaskSettings.IsFree)
                {
                    MessageBox.Show("To get the latest data from Google use the 'Sync' button.\r\n \r\nYou can enable Auto-Sync by upgrading to the Paid version\r\n \r\nSend me any questions, feedback, or issues:\r\n   - Tweet @MattLoflin\r\n   - [email protected]", "Instructions", MessageBoxButton.OK);
                }
                else
                {
                    MessageBox.Show("To get the latest data from Google use the 'Sync' button OR enable Auto-Sync in settings.\r\n \r\nSend me any questions, feedback, or issues:\r\n   - Tweet @MattLoflin\r\n   - [email protected]", "Instructions", MessageBoxButton.OK);
                }

                //due to possible data issues with localization changes - force update of Google data
                //Remove LocalStorage (if exists)
                string ApplicationDataFileName = "TaskListData.txt";

                IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
                if (storage.FileExists(ApplicationDataFileName))
                {
                    storage.DeleteFile(ApplicationDataFileName);
                }

                //Set First run to true for forced sync
                GTaskSettings.FirstRun = true;


                if (GTaskSettings.IsFree) //if free then turn off 'auto' features
                {
                    GTaskSettings.AutoClear        = false;
                    GTaskSettings.AutoRefreshLists = false;
                    GTaskSettings.AutoRefreshTasks = false;
                }

                //If the user already installed the app and HideCompleted = true then remove hidden to speed up processing
                //localStorageList should be null if not used yet
                List <Model.TaskListItem> localStorageList = await TaskListHelper.GetTaskListFromApplicationStorage(false);

                if (GTaskSettings.HideCompleted == true && (localStorageList != null || localStorageList.Count == 0))
                {
                    bool results = await GTaskSettings.RemoveHidden();
                }

                //Check for pinned lists - if pinned then prompt user to re-pin
                bool pinned = false;
                foreach (ShellTile shellTile in ShellTile.ActiveTiles)
                {
                    try
                    {
                        if (shellTile.NavigationUri.ToString().Contains("/Views/TaskView.xaml?Id="))
                        {
                            pinned = true;
                        }
                    }
                    catch (Exception)// e)
                    {
                    }
                }

                if (pinned)
                {
                    MessageBox.Show("I noticed that you have Task List(s) pinned to the Start Screen.\r\n \r\nPlease Re-pin any Task List(s) to enable updated features.", "Action Required", MessageBoxButton.OK);
                }

                //update NewFeatureCount to latest so user doesn't see this again
                GTaskSettings.NewFeatureCount = NumFeature;
            }
            //Only try to do one popup per session - if the new feature popup isn't being used, then do others (if applicable)
            else
            {
                //
                //##RATE ME POPUP##
                //
                int daysElapsed = (int)(DateTime.Now.Subtract(GTaskSettings.ReminderDate).TotalDays);
                if (daysElapsed > 7 && !GTaskSettings.Rated)
                {
                    MessageBoxResult m = MessageBox.Show("Hey! I see you have been using the app for a while now, could you click 'OK' to Rate it or Send me feedback through 'Settings'->'About'?", "Feedback?", MessageBoxButton.OKCancel);
                    if (m == MessageBoxResult.OK)
                    {
                        //Navigate to Rating Page
                        MarketplaceReviewTask oRateTask = new MarketplaceReviewTask();
                        oRateTask.Show();

                        //Set Rated = True (assuming they rated by clicking OK)
                        GTaskSettings.Rated = true;
                    }
                    else
                    {
                        //Set Reminder Date to Today to remind again in 7 days
                        GTaskSettings.ReminderDate = DateTime.Now;
                    }
                }
            }
            //If this was added after someone logged it, the value wouldn't be set until they login again
            //Given the default return is MaxValue - we can catch it and reset it to Today's date
            if (GTaskSettings.ReminderDate == DateTime.MaxValue)
            {
                GTaskSettings.ReminderDate = DateTime.Now;
            }
        }
Esempio n. 5
0
        public static async Task <string> MoveTask(string TaskListID, string Id, string PrevID)
        {
            //const string message = "I'm having issues moving this task, can you try again?";

            var restRequest = new RestRequest(Method.POST)
            {
                Timeout = GTaskSettings.RequestTimeout
            };

            if (PrevID == "")
            {
                restRequest.RequestFormat = DataFormat.Json;
                restRequest.Resource      = String.Format("https://www.googleapis.com/tasks/v1/lists/" + TaskListID + "/tasks/" + Id + "/move?");
            }
            else
            {
                restRequest.RequestFormat = DataFormat.Json;
                restRequest.Resource      = String.Format("https://www.googleapis.com/tasks/v1/lists/" + TaskListID + "/tasks/" + Id + "/move?previous=" + PrevID);
            }

            restRequest.AddParameter("application/json", ParameterType.RequestBody);

            //Make the call
            var restResponse = await GTaskSettings.ExecuteRestTask(restRequest);

            try
            {
                if (restResponse.StatusCode == HttpStatusCode.OK)
                {
                    // Get the new position from the response
                    var    m        = JObject.Parse(restResponse.Content);
                    string position = (string)m.SelectToken("position");

                    //success
                    return(position);
                }
            }
            catch
            {
            }

            // Get the locally stored list
            List <TaskListItem> TaskListList = await TaskListHelper.GetTaskListFromApplicationStorage(false);

            // Check that the task list and tasks are available in local storage
            if (TaskListList.Where(x => x.id == TaskListID).Count() == 0 ||
                TaskListList.Where(x => x.id == TaskListID).First().taskList.Where(x => x.id == Id).Count() == 0)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(PrevID))
            {
                // The item has been moved to the first position
                TaskListList.Where(x => x.id == TaskListID).First().taskList.Where(x => x.id == Id).First().position = "0";
                TaskListList.Where(x => x.id == TaskListID).First().taskList.Where(x => x.id == Id).First().updated  = DateTime.UtcNow.ToString("yyyy-MM-dd'T'hh:mm:ss.00Z"); // DateTime.UtcNow.ToString();
            }
            else
            {
                // Check that the prev id item is available in local storage
                if (TaskListList.Where(x => x.id == TaskListID).First().taskList.Where(x => x.id == PrevID).Count() == 0)
                {
                    return(null);
                }

                // get the position of the prev id item
                double position = double.Parse(TaskListList.Where(x => x.id == TaskListID).First().taskList.Where(x => x.id == PrevID).First().position);

                // Set the position of the item to 1+ the position of the previous item
                TaskListList.Where(x => x.id == TaskListID).First().taskList.Where(x => x.id == Id).First().position = (position + 1).ToString();
                TaskListList.Where(x => x.id == TaskListID).First().taskList.Where(x => x.id == Id).First().updated  = DateTime.UtcNow.ToString("yyyy-MM-dd'T'hh:mm:ss.00Z");// DateTime.UtcNow.ToString();
            }

            //submit the task list to local storage
            await TaskListHelper.SubmitToLocalStorage(TaskListList);

            return(null);
        }
Esempio n. 6
0
        public static async Task <TaskItem> RetryAddTask(IList <object> obj)
        {
            //const string message = "Golly Gee, There was an error Creating the Task, can you try it again?";
            var restRequest = new RestRequest(Method.POST)
            {
                RequestFormat = DataFormat.Json,
                Resource      = String.Format("https://www.googleapis.com/tasks/v1/lists/{0}/tasks", obj[2]),
                Timeout       = GTaskSettings.RequestTimeout
            };
            string dueDate = string.Empty;

            if (!string.IsNullOrEmpty(((TaskItem)obj[0]).due))
            {
                TaskItem t = ((TaskItem)obj[0]);
                dueDate = ",due: \"" + t.due + "\"";
            }
            var info = "{title:\"" + ((TaskItem)obj[0]).title + "\",notes:\"" + ((TaskItem)obj[0]).notes + "\"" + dueDate + "}";

            info = info.Replace("\r", "\\n");
            restRequest.AddParameter("application/json", info, ParameterType.RequestBody);

            //Make the call
            var restResponse = await GTaskSettings.ExecuteRestTask(restRequest);

            try
            {
                if (restResponse.StatusCode == HttpStatusCode.OK)
                {
                    //Success
                    var      m       = JObject.Parse(restResponse.Content);
                    TaskItem newTask = new TaskItem((string)m.SelectToken("id"),
                                                    (string)m.SelectToken("kind"),
                                                    ((string)m.SelectToken("title")) ==
                                                    String.Empty
                                                            ? "Empty"
                                                            : (string)
                                                    m.SelectToken("title"),
                                                    ((TaskItem)obj[0]).notes,
                                                    obj[2].ToString(),
                                                    (string)
                                                    m.SelectToken("position"),
                                                    (string)m.SelectToken("updated"),
                                                    (string)m.SelectToken("due"),
                                                    (string)m.SelectToken("deleted"),
                                                    (string)m.SelectToken("hidden"),
                                                    (string)m.SelectToken("status"),
                                                    (string)
                                                    m.SelectToken("selfLink"),
                                                    (string)
                                                    m.SelectToken("completed"),
                                                    (string)
                                                    m.SelectToken("updated")
                                                    );

                    // Submit task to local storage too
                    List <TaskListItem> list = await TaskListHelper.GetTaskListFromApplicationStorage();

                    // Add the task to the list
                    list.Where(x => x.id == obj[2].ToString()).First().taskList.Insert(0, newTask);

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

                    return(newTask);
                }
            }
            catch
            {
            }

            return(null);
        }
Esempio n. 7
0
        /// <summary>
        /// Load the task lists and all associated data from the api
        /// </summary>
        /// <param name="alertWhenNoConnection">Alert the user that we could not connect to the api</param>
        /// <returns>Boolean result</returns>
        public static async Task <List <TaskListItem> > LoadTaskDataFromApi(bool alertWhenNoConnection = false, string specificList = null)
        {
            try
            {
                await LoginHelper.RefreshTokenCodeAwait(true);

                var settings = IsolatedStorageSettings.ApplicationSettings;

                string url = "https://www.googleapis.com/tasks/v1/users/@me/lists?access_token=" + GTaskSettings.AccessToken;
                if (!string.IsNullOrEmpty(specificList))
                {
                    url = "https://www.googleapis.com/tasks/v1/users/@me/lists/" + specificList + "?access_token=" + GTaskSettings.AccessToken;
                }

                // Get the Task Lists
                #region Get Task Lists
                var restRequest = new RestRequest(Method.GET)
                {
                    Resource = url,
                    Timeout  = GTaskSettings.RequestTimeout
                };

                //Make the call
                var restResponse = await GTaskSettings.ExecuteRestTask(restRequest, false);

                //Store Lists
                var TaskListObject = JObject.Parse(restResponse.Content);

                // If the limit is exceeded then pop up a message, otherwise lets continue
                if (restResponse.Content.Contains("Limit Exceeded"))
                {
                    MessageBox.Show("[1] Take a screenshot and send it to @MattLoflin or [email protected]\r\n \r\n" + restResponse.Content.ToString());
                    return(null);
                }

                List <TaskListItem> TaskListList = null;
                if (string.IsNullOrEmpty(specificList))
                {
                    TaskListList = TaskListObject["items"].Select(m => new TaskListItem((string)m.SelectToken("title"),
                                                                                        (string)m.SelectToken("id"),
                                                                                        (string)m.SelectToken("kind"),
                                                                                        (string)m.SelectToken("selfLink"),
                                                                                        (string)m.SelectToken("updated"))).ToList();
                }
                else
                {
                    TaskListList = new List <TaskListItem>();
                    TaskListList.Add(new TaskListItem((string)TaskListObject.SelectToken("title"),
                                                      (string)TaskListObject.SelectToken("id"),
                                                      (string)TaskListObject.SelectToken("kind"),
                                                      (string)TaskListObject.SelectToken("selfLink"),
                                                      (string)TaskListObject.SelectToken("updated")));
                }

                //Check to see if pageToken exists
                //If so - iterate until empty
                var pageToken = string.Empty;
                if (TaskListObject["nextPageToken"] != null)
                {
                    pageToken = TaskListObject["nextPageToken"].ToString();
                }

                while (pageToken != string.Empty)
                {
                    restRequest = new RestRequest(Method.GET)
                    {
                        Resource =
                            "https://www.googleapis.com/tasks/v1/users/@me/lists?pageToken=" + pageToken + "&access_token=" + GTaskSettings.AccessToken,
                        Timeout = GTaskSettings.RequestTimeout
                    };

                    restResponse = await GTaskSettings.ExecuteRestTask(restRequest, false);

                    TaskListObject = JObject.Parse(restResponse.Content);

                    //Add the new list to the current list
                    if (string.IsNullOrEmpty(specificList))
                    {
                        TaskListList.AddRange(TaskListObject["items"].Select(m => new TaskListItem((string)m.SelectToken("title"),
                                                                                                   (string)m.SelectToken("id"),
                                                                                                   (string)m.SelectToken("kind"),
                                                                                                   (string)m.SelectToken("selfLink"),
                                                                                                   (string)m.SelectToken("updated"))));
                    }
                    else
                    {
                        TaskListList.Add(new TaskListItem((string)TaskListObject.SelectToken("title"),
                                                          (string)TaskListObject.SelectToken("id"),
                                                          (string)TaskListObject.SelectToken("kind"),
                                                          (string)TaskListObject.SelectToken("selfLink"),
                                                          (string)TaskListObject.SelectToken("updated")));
                    }

                    //reset the pageToken
                    pageToken = string.Empty;
                    if (TaskListObject["nextPageToken"] != null)
                    {
                        pageToken = TaskListObject["nextPageToken"].ToString();
                    }
                }
                #endregion

                // Get the Task Items
                #region Get Task Items
                // Loop through the task list list and get the tasks for each list
                foreach (TaskListItem list in TaskListList)
                {
                    // Instantiate the task list
                    list.taskList = new List <TaskItem>();

                    //If user wants to see Hidden (Completed) tasks, then display them. Else return current list
                    restRequest.Resource = "https://www.googleapis.com/tasks/v1/lists/" + list.id + "/tasks?access_token=" + GTaskSettings.AccessToken;
                    if (GTaskSettings.HideCompleted == false)
                    {
                        restRequest.Resource = "https://www.googleapis.com/tasks/v1/lists/" + list.id + "/tasks?showHidden=True&access_token=" + GTaskSettings.AccessToken;
                    }

                    //Make the call
                    restResponse = await GTaskSettings.ExecuteRestTask(restRequest, false);

                    var TaskObject = JObject.Parse(restResponse.Content);
                    if (!restResponse.Content.Contains("Limit Exceeded"))
                    {
                        if (TaskObject != null && TaskObject["items"] != null)
                        {
                            list.taskList = TaskObject["items"].Select(m => new TaskItem((string)m.SelectToken("id"),
                                                                                         (string)m.SelectToken("kind"),
                                                                                         ((string)m.SelectToken("title")) ==
                                                                                         String.Empty
                                                            ? "Empty"
                                                            : (string)
                                                                                         m.SelectToken("title"),
                                                                                         (string)m.SelectToken("notes"),
                                                                                         list.id,
                                                                                         (string)
                                                                                         m.SelectToken("position"),
                                                                                         (string)m.SelectToken("update"),
                                                                                         (string)m.SelectToken("due"),
                                                                                         (string)m.SelectToken("deleted"),
                                                                                         (string)m.SelectToken("hidden"),
                                                                                         (string)m.SelectToken("status"),
                                                                                         (string)
                                                                                         m.SelectToken("selfLink"),
                                                                                         (string)
                                                                                         m.SelectToken("completed"),
                                                                                         (string)
                                                                                         m.SelectToken("updated")
                                                                                         )).ToList();
                        }

                        //Check to see if pageToken exists
                        //If so - iterate until empty
                        pageToken = string.Empty;
                        if (TaskObject["nextPageToken"] != null)
                        {
                            pageToken = TaskObject["nextPageToken"].ToString();
                        }

                        while (pageToken != string.Empty)
                        {
                            //If user wants to see Hidden (Completed) tasks, then display them. Else return current list
                            restRequest.Resource = "https://www.googleapis.com/tasks/v1/lists/" + list.id + "/tasks?pageToken=" + pageToken + "&access_token=" + GTaskSettings.AccessToken;
                            if (GTaskSettings.HideCompleted == false)
                            {
                                restRequest.Resource = "https://www.googleapis.com/tasks/v1/lists/" + list.id + "/tasks?pageToken=" + pageToken + "&showHidden=True&access_token=" + GTaskSettings.AccessToken;
                            }
                            restResponse = await GTaskSettings.ExecuteRestTask(restRequest, false);

                            TaskObject = JObject.Parse(restResponse.Content);

                            //Add the new list to the current list
                            list.taskList.AddRange(TaskObject["items"].Select(
                                                       m => new TaskItem((string)m.SelectToken("id"),
                                                                         (string)m.SelectToken("kind"),
                                                                         ((string)m.SelectToken("title")) ==
                                                                         String.Empty
                                                            ? "Empty"
                                                            : (string)
                                                                         m.SelectToken("title"),
                                                                         (string)m.SelectToken("notes"),
                                                                         (string)m.SelectToken("parent"),
                                                                         (string)
                                                                         m.SelectToken("position"),
                                                                         (string)m.SelectToken("update"),
                                                                         (string)m.SelectToken("due"),
                                                                         (string)m.SelectToken("deleted"),
                                                                         (string)m.SelectToken("hidden"),
                                                                         (string)m.SelectToken("status"),
                                                                         (string)
                                                                         m.SelectToken("selfLink"),
                                                                         (string)
                                                                         m.SelectToken("completed"),
                                                                         (string)
                                                                         m.SelectToken("updated")
                                                                         )).ToList());

                            //reset the pageToken
                            pageToken = string.Empty;
                            if (TaskObject["nextPageToken"] != null)
                            {
                                pageToken = TaskObject["nextPageToken"].ToString();
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("[2] Take a screenshot and send it to @MattLoflin or [email protected]\r\n \r\n" + restResponse.Content.ToString());
                    }
                }
                #endregion

                return(TaskListList);
            }
            catch (Exception e)
            {
                // Check if an error was returned indicated that we couldnt connect to the api
                if (alertWhenNoConnection && e.ToString().Contains("Error reading JObject from JsonReader"))
                {
                    var googError = MessageBox.Show("Google is having intermittent connectivity issues, please try again in a couple minutes.", "Google Connection Issues", MessageBoxButton.OK);
                }

                // Return false
                return(null);

                // There was an issue getting the data.
                // There might not have been an internet connection so ignore the error
                // This can be handled more delicately in the future
            }
        }