public TodoistController( ClickupService clickupService, TodoistService todoistService) { _clickupService = clickupService; _todoistService = todoistService; }
public override Task RunAsyncInternal(IBackgroundTaskInstance taskInstance) { if (taskInstance == null) { return(null); } _deferral = taskInstance.GetDeferral(); return(Task.Run(async() => { Settings settings = await new UwpMemory().Read <Settings>("settings.json"); var Todoist = new TodoistService(settings.TodoistKey, settings.TodoistUserAgent); await new NotificationHandler().UpdateNotifications(Todoist); await new LiveTileService().SampleUpdate(Todoist); //// TODO WTS: Insert the code that should be executed in the background task here. //// This sample initializes a timer that counts to 100 in steps of 10. It updates Message each time. //// Documentation: //// * General: https://docs.microsoft.com/en-us/windows/uwp/launch-resume/support-your-app-with-background-tasks //// * Debug: https://docs.microsoft.com/en-us/windows/uwp/launch-resume/debug-a-background-task //// * Monitoring: https://docs.microsoft.com/windows/uwp/launch-resume/monitor-background-task-progress-and-completion //// To show the background progress and message on any page in the application, //// subscribe to the Progress and Completed events. //// You can do this via "BackgroundTaskService.GetBackgroundTasksRegistration" _taskInstance = taskInstance; _deferral.Complete(); })); }
private void GetTimezoneList() { progressIndicator.IsVisible = true; progressIndicator.IsIndeterminate = true; progressIndicator.Text = "Loading"; SystemTray.SetProgressIndicator(this, progressIndicator); TodoistService todoistService = new TodoistService(); todoistService.GetTimezoneList( (result) => { Dispatcher.BeginInvoke(() => { SearchTxtBox.IsEnabled = true; timezonesListBox.ItemsSource = result; }); }, (error) => { Dispatcher.BeginInvoke(() => { MessageBox.Show(error, "Metroist", MessageBoxButton.OK); }); }, () => { progressIndicator.IsVisible = false; progressIndicator.IsIndeterminate = false; }); }
public async Task UpdateNotifications(TodoistService todoist) { var oldToasts = ToastNotificationManager.History.GetHistory(); var oldToastsIds = oldToasts.Select(i => i.Tag).ToList(); var newToasts = await CreateNotifications(todoist); var newToastIds = newToasts.Select(i => i.Tag).ToList(); foreach (var toast in newToasts) { if (!oldToastsIds.Contains(toast.Tag)) { ToastNotificationManager.CreateToastNotifier().Show(toast); } } foreach (var toast in oldToasts) { if (!newToastIds.Contains(toast.Tag)) { ToastNotificationManager.History.Remove(toast.Tag); } } }
private void DoneBtn_Click(object sender, EventArgs e) { TodoistService todoistService = new TodoistService(); doneBtn.IsEnabled = false; if (validateForm()) { todoistService.SignUp(NameTextBox.Text, EmailTextBox.Text, PasswordBox.Password, (data) => { app.loginInfo = data; NavigationService.Navigate(Utils.MainTodoistPage(true)); }, (errorMsg) => { MessageBox.Show(errorMsg, "Metroist", MessageBoxButton.OK); doneBtn.IsEnabled = true; }); } else { if (!(GeneralLib.Utils.IsValidEmail(EmailTextBox.Text))) { MessageBox.Show("You have entered a invalid e-mail. Please try again.", "Metroist", MessageBoxButton.OK); } else if (!(PasswordBox.Password.Length >= 5)) { MessageBox.Show("Your password must have at least 5 characters.", "Metroist", MessageBoxButton.OK); } doneBtn.IsEnabled = true; } }
public async Task <IEnumerable <ToastNotification> > CreateNotifications(TodoistService todoist) { var today = await todoist.GetLabel("today"); List <Item> allTodos = await todoist.GetItems(); List <Item> todos = allTodos.Where(i => i.Labels.Contains(today.Id)).OrderBy(i => i.Priority).ToList(); //if(todos.Count == 0) //{ // todos = allTodos.Where(i => i.DueDateUtc < DateTime.UtcNow.Date.AddDays(1)).ToList(); //} var proj = await todoist.GetProjects(); return(todos.Select(i => (todo: i, toast: new ToastContent() { Visual = GetVisual(i, proj.First(j => j.Id == i.ProjectId)), Actions = GetActions(i.Id), // Arguments when the user taps body of toast Launch = new QueryString() { { "action", "viewConversation" }, { "conversationId", i.Id.ToString() } }.ToString(), ActivationType = ToastActivationType.Background, })).Select(i => new ToastNotification(i.toast.GetXml()) { SuppressPopup = true, Tag = i.todo.Id.ToString() })); }
public override Task RunAsyncInternal(IBackgroundTaskInstance taskInstance) { if (taskInstance == null) { return(null); } _deferral = taskInstance.GetDeferral(); return(Task.Run(async() => { var details = taskInstance.TriggerDetails as ToastNotificationActionTriggerDetail; Settings settings = await new UwpMemory().Read <Settings>("settings.json"); var Todoist = new TodoistService(settings.TodoistKey, settings.TodoistUserAgent); if (details != null) { string arguments = details.Argument; var userInput = details.UserInput; if (arguments.StartsWith("complete")) { TodoistService todoist = Todoist; await todoist.MarkTodoAsDone(long.Parse(details.Argument.Remove(0, 9))); } if (arguments.StartsWith("remove")) { TodoistService todoist = Todoist; ItemUpdate update = new ItemUpdate(long.Parse(details.Argument.Remove(0, 7))) { Labels = new List <long>() }; await todoist.Update(update); } // Perform tasks } //// TODO WTS: Insert the code that should be executed in the background task here. //// This sample initializes a timer that counts to 100 in steps of 10. It updates Message each time. //// Documentation: //// * General: https://docs.microsoft.com/en-us/windows/uwp/launch-resume/support-your-app-with-background-tasks //// * Debug: https://docs.microsoft.com/en-us/windows/uwp/launch-resume/debug-a-background-task //// * Monitoring: https://docs.microsoft.com/windows/uwp/launch-resume/monitor-background-task-progress-and-completion //// To show the background progress and message on any page in the application, //// subscribe to the Progress and Completed events. //// You can do this via "BackgroundTaskService.GetBackgroundTasksRegistration" _deferral.Complete(); _taskInstance = taskInstance; })); }
private bool SetGoogleCode(string url) { TodoistService todoistService = new TodoistService(); if (url.StartsWith("http://localhost")) { string urlParamsString = url.Split('?')[1]; string[] urlParamsArray = urlParamsString.Split('&'); for (int i = 0; i < urlParamsArray.Length; i++) { string[] keyValue = urlParamsArray[i].Split('='); if (keyValue[0] == "code") { TodoistService.googleCode = keyValue[1]; todoistService.GoogleAccessToken(keyValue[1], successCallback); return true; } } return false; } return false; }
private async void Page_Loaded(object sender, RoutedEventArgs e) { settings = await new UwpMemory().Read("settings.json", new Settings { }); Todoist = new TodoistService(settings.TodoistKey, settings.TodoistUserAgent); try { todayLabel = await Todoist.GetLabel("today"); } catch (Exception ex) { await ContentDialogTodoistKey.ShowAsync(); Todoist = new TodoistService(settings.TodoistKey, settings.TodoistUserAgent); todayLabel = await Todoist.GetLabel("today"); } Projects = Order(await Todoist.GetProjects()).ToList(); Labels = await Todoist.GetLabels(); Items = await Todoist.GetItems(); await new NotificationHandler().UpdateNotifications(Todoist); await Singleton <LiveTileService> .Instance.SampleUpdate(Todoist); OnPropertyChanged(nameof(InstanceLabels)); OnPropertyChanged(nameof(InstanceProjects)); OnPropertyChanged(nameof(InstanceItems)); parser = new TodoistParser(Projects, Labels); RedoTodos(); isLoaded = true; }
void doneIconButton_Click(object sender, EventArgs e) { TodoistService todoistService = new TodoistService(); var cmdTimeGenerated = DateTime.Now; var tempID = Utils.DateTimeToUnixTimestamp(cmdTimeGenerated); projSelected.name = projectNameTextBox.Text; projSelected.color = ((int)ColorPickerListBox.SelectedItem); todoistService.EditProject(cmdTimeGenerated, projSelected, (data) => { todoistService.GetData( (fullData) => { var updatedProject = fullData.Projects.Where(x => x.id == projSelected.id).First(); UpdateContext(); MainTodoistPage.updateAll(fullData); ProjectDetail.showMessage = (progress) => { ProjectDetail.projectSelected = updatedProject; Utils.ProgressIndicatorStatus(String.Format("\"{0}\" changed.", projSelected.name), progress); }; }, (error) => { MessageBox.Show(Utils.Message(error), "Metroist", MessageBoxButton.OK); }, () => { NavigationService.GoBack(); }); }, (errorMsg) => { MessageBox.Show(Utils.Message(errorMsg), "Metroist", MessageBoxButton.OK); }); }
void doneButton_Click(object sender, EventArgs e) { TodoistService todoistService = new TodoistService(); var commandTimeGenerated = DateTime.Now; Item Task = new Item { content = ContentTextBox.Text, date_string = DateStringTextBox.Text, project_id = projectSelected.id }; doneButton.IsEnabled = false; todoistService.AddTaskToProject(commandTimeGenerated, Task, (data) => { todoistService.GetData( (fullData) => { app.projects = fullData.Projects; app.notes = fullData.Notes; app.items = fullData.Items; var tempID = Utils.DateTimeToUnixTimestamp(commandTimeGenerated).ToString(); Task.id = data.TempIdMapping[tempID]; Task = app.items.Where(x => x.id == Task.id).FirstOrDefault(); MainTodoistPage.updateProjectList(fullData.Projects); ProjectDetail.showMessage = (progress) => { Utils.ProgressIndicatorStatus(String.Format("\"{0}\" added.", Task.content), progress); ProjectDetail.showMessage = null; }; }, (errorMessage) => { }, () => { doneButton.IsEnabled = true; var currentPage = app.RootFrame.Content as PhoneApplicationPage; if (currentPage == this) NavigationService.GoBack(); }); }, (errorMsg) => { MessageBox.Show(Utils.Message(errorMsg), "Metroist", MessageBoxButton.OK); }); //NavigationService.GoBack(); }
// More about Live Tiles Notifications at https://docs.microsoft.com/windows/uwp/controls-and-patterns/tiles-and-notifications-sending-a-local-tile-notification public async Task SampleUpdate(TodoistService todoist) { var today = await todoist.GetLabel("today"); List <Item> allTodos = await todoist.GetItems(); List <Item> todos = allTodos.Where(i => i.Labels.Contains(today.Id)).OrderBy(i => i.Priority).ToList(); var updater = TileUpdateManager.CreateTileUpdaterForApplication(); updater.Clear(); updater.EnableNotificationQueue(true); for (int i = 0; i < todos.Count; i += 4) { var content = new TileContent() { Visual = new TileVisual() { TileMedium = new TileBinding() { Content = new TileBindingContentAdaptive() { Children = { new AdaptiveText() { Text = $"DailyTodo ({todos.Count})", } } } }, TileWide = new TileBinding() { Content = new TileBindingContentAdaptive() { Children = { new AdaptiveText() { Text = $"DailyTodo ({todos.Count})", HintStyle = AdaptiveTextStyle.Base, } } } }, TileLarge = new TileBinding() { Content = new TileBindingContentAdaptive() { Children = { new AdaptiveText() { Text = $"DailyTodo ({todos.Count})", HintStyle = AdaptiveTextStyle.Base, } } } } } }; var todoText = todos.Skip(i).Take(4).Select(j => new AdaptiveText() { Text = $" - {NotificationHandler.DisplayContent(j.Content)}", HintStyle = AdaptiveTextStyle.CaptionSubtle }).ToList(); todoText.ForEach(j => (content.Visual.TileMedium.Content as TileBindingContentAdaptive).Children.Add(j)); todoText.ForEach(j => (content.Visual.TileWide.Content as TileBindingContentAdaptive).Children.Add(j)); todoText.ForEach(j => (content.Visual.TileLarge.Content as TileBindingContentAdaptive).Children.Add(j)); // Then create the tile notification var notification = new TileNotification(content.GetXml()); notification.Tag = "item" + i; try { updater.Update(notification); } catch (Exception) { // TODO WTS: Updating LiveTile can fail in rare conditions, please handle exceptions as appropriate to your scenario. } } // Construct the tile content }
void doneIconButton_Click(object sender, EventArgs e) { TodoistService todoistService = new TodoistService(); var cmdTimeGenerated = DateTime.Now; var tempID = Utils.DateTimeToUnixTimestamp(cmdTimeGenerated).ToString(); Project Project = new Project { name = projectNameTextBox.Text, color = ((int)ColorPickerListBox.SelectedItem), }; doneIconButton.IsEnabled = false; todoistService.AddProject(cmdTimeGenerated, Project, (data) => { app.projects.Insert(0, Project); Utils.DateTimeToUnixTimestamp(cmdTimeGenerated).ToString(); Project.id = data.TempIdMapping[tempID]; //MainTodoistPage.updateProjectList(data.Projects); MainTodoistPage.showMessage = (progress) => { Utils.ProgressIndicatorStatus(String.Format("\"{0}\" added.", Project.name), progress); }; }, (errorMsg) => { MessageBox.Show(Utils.Message(errorMsg), "Metroist", MessageBoxButton.OK); }, () => { doneIconButton.IsEnabled = true; var currentPage = app.RootFrame.Content as PhoneApplicationPage; if(currentPage == this) NavigationService.GoBack(); }); }
private void ApplicationBarCreate() { ApplicationBar = mainApplicationBar; mainApplicationBar.IsVisible = true; updateAllIconButton.IsEnabled = false; updateNewsIconButton.IsEnabled = false; updateNewsIconButton.Click += updateNewsIconButon_Click; updateAllIconButton.Click += new EventHandler(updateAllIconButton_Click); addProjectIconButton.Click += new EventHandler(addProjectIconButton_Click); filterButton.Click += (sender, e) => { NavigationService.Navigate(Utils.FilterOptionsPage()); }; aboutMenuItem.Text = "about"; aboutMenuItem.Click += (sender, e) => { NavigationService.Navigate(Utils.AboutPage()); }; logoutMenuItem.Text = "logout"; logoutMenuItem.Click += (sender, e) => { TodoistService todoistService = new TodoistService(); todoistService.cancel(); app.loginInfo = null; app.localLoginInfo.isRecorded = false; app.localLoginInfo.email = app.localLoginInfo.password = null; if (app.projects != null) app.projects.Clear(); if (app.startPageTasks != null) app.startPageTasks.Clear(); if (app.TemporaryDesynchronized != null) app.TemporaryDesynchronized.Clear(); GeneralLib.IsolatedStorage.clear(); NavigationService.Navigate(Utils.LoginPage()); }; syncButton.IsEnabled = false; syncButton.Click += new EventHandler(syncButton_Click); mainApplicationBar.MenuItems.Add(logoutMenuItem); mainApplicationBar.MenuItems.Add(aboutMenuItem); }
private void GetStartPage() { TodoistService todoistService = new TodoistService(); todoistService.GetStartPage (app.settings.DateStringHome, (data) => { //@TODO: Change this for more flexibility. ApplyStartPage(data); }, (error) => { MessageBox.Show(error); }, () => { }); }
private void UpdateDeletingToServer(Project project, int indexOf) { TodoistService todoistService = new TodoistService(); var commandTimeGenerated = DateTime.Now; deleteIconButton.IsEnabled = false; todoistService.RemoveTask(commandTimeGenerated, Task, (data) => { app.items.RemoveAt(indexOf); project.cache_count--; taskDeleted = true; MainTodoistPage.updateProjectList(data.Projects); }, (errorMsg) => { //@TODO: Error dynamic }, () => { deleteIconButton.IsEnabled = true; var currentPage = app.RootFrame.Content as PhoneApplicationPage; if (currentPage == this) NavigationService.GoBack(); }); }
void checkUncheckButton_Click(object sender, EventArgs e) { TodoistService todoistService = new TodoistService(); var cmdTime = DateTime.Now; Item selected = Task as Item; selected.selectedListBoxItem_ProjectDetail = true; if (selected != null) { var project = (from proj in app.projects where proj.id == Task.project_id select proj).FirstOrDefault(); if (project != null) { if (!selected.is_checked) { project.cache_count--; selected.is_checked = true; } else { project.cache_count++; selected.is_checked = false; } } //Update icon to Unchecked var newButton = (sender as ApplicationBarIconButton); newButton.IconUri = new Uri("/Images/" + (selected.is_checked ? "Uncheck.png" : "Check.png"), UriKind.Relative); newButton.Text = selected.is_checked ? "uncheck" : "check done"; DataContext = null; DataContext = Task; //--> todoistService.SetTaskAsChecked(cmdTime, selected, (data) => { if (MainTodoistPage.updateProjectList != null) MainTodoistPage.updateProjectList(data.Projects); }, (erroMsg) => { //@TODO: What to do here? error method MessageBox.Show(erroMsg, "Metroist", MessageBoxButton.OK); }, () => { }); } }
private void GoogleSignInBtn_Tap(object sender, System.Windows.Input.GestureEventArgs e) { TodoistService todoistService = new TodoistService(); ListBoxItem googleSignInBtn = (ListBoxItem)sender; if (googleSignInBtn.IsEnabled) { Focus(); ApplicationBar.IsVisible = false; OverlayPopup.IsOpen = true; ShowOverlay.Begin(); progressIndicator.IsVisible = true; progressIndicator.IsIndeterminate = true; progressIndicator.Text = "Connecting to Todoist service"; SystemTray.SetProgressIndicator(this, progressIndicator); ToggleGoogleBtn(); todoistService.GoogleAuth(() => { NavigationService.Navigate(Utils.MainTodoistPage(removeBackStack: true)); }); } }
private void CompleteTask_Click(object sender, RoutedEventArgs e) { TodoistService todoistService = new TodoistService(); var cmdTime = DateTime.Now; Item selected = UncompletedTasksListBox.SelectedItem as Item; selected.selectedListBoxItem_ProjectDetail = true; if (selected != null) { projectSelected.cache_count--; selected.is_checked = true; todoistService.SetTaskAsChecked(cmdTime, selected, (data) => { if (MainTodoistPage.updateProjectList != null) MainTodoistPage.updateProjectList(data.Projects); }, (erroMsg) => { //@TODO: What to do here? error method }, () => { }); } }
void syncButton_Click(object sender, EventArgs e) { if (app.TemporaryDesynchronized.Count > 0) { TodoistService todoistService = new TodoistService(); todoistService.SyncAll( (data) => { if (app.TemporaryDesynchronized.Count > 0) { //Update all based on temporary //This is needed because the responde doesn't bring the synced item or project. UpdateBasedOnTemporaryDessychronized(data); app.TemporaryDesynchronized.Clear(); SyncStatusLabel.Text = String.Format("{0} item(s) to be sync.", app.TemporaryDesynchronized.Count); } app.projects = data.Projects; }, (errorMsg) => { MessageBox.Show(errorMsg, "Metroist", MessageBoxButton.OK); }, () => { ProjectsListBox.ItemsSource = null; ProjectsListBox.ItemsSource = app.projects; }); } }
private void HandleNetworkStatusViewer() { Dispatcher.BeginInvoke(() => { TodoistService todoistService = new TodoistService(); BlockColorNetworkStatus.Background = NetworkInterface.GetIsNetworkAvailable() && todoistService.debugWithInternet ? App.Current.Resources["ProjectColor15"] as SolidColorBrush : App.Current.Resources["ProjectColor13"] as SolidColorBrush; LabelNetworkStatus.Text = NetworkInterface.GetIsNetworkAvailable() && todoistService.debugWithInternet ? "online" : "offline"; }); }
private void Logar() { TodoistService todoistService = new TodoistService(); //Take off the focus from any. Focus(); ApplicationBar.IsVisible = false; OverlayPopup.IsOpen = true; ShowOverlay.Begin(); progressIndicator.IsVisible = true; progressIndicator.IsIndeterminate = true; progressIndicator.Text = "Connecting to Todoist service"; signUpLoginBtn.IsEnabled = false; SystemTray.SetProgressIndicator(this, progressIndicator); loginButton.IsEnabled = false; todoistService.Login(EmailTxtBox.Text, PasswordBox.Password, (data) => { NavigationService.Navigate(Utils.MainTodoistPage()); }, (error) => { loginButton.IsEnabled = true; MessageBox.Show(error, "Metroist", MessageBoxButton.OK); }, () => { ShowOverlay.Stop(); OverlayPopup.IsOpen = false; progressIndicator.IsIndeterminate = false; progressIndicator.IsVisible = false; ApplicationBar.IsVisible = true; signUpLoginBtn.IsEnabled = true; }); //Empty the passwordbox, just for visual security. PasswordBox.Password = string.Empty; if (RememberCheckBox.IsChecked == true) { app.localLoginInfo.isRecorded = true; app.localLoginInfo.email = EmailTxtBox.Text; app.localLoginInfo.password = PasswordBox.Password; } }
void deleteIconButton_Click(object sender, EventArgs e) { TodoistService todoistService = new TodoistService(); var result = MessageBox.Show(string.Format("Delete project \"{0}\"?", projectSelected.name), "Metroist", MessageBoxButton.OKCancel); //@TODO: check what is the answers. if the deleted projects come also. if (result == MessageBoxResult.OK) { var cmdTimeGenerated = DateTime.Now; var tempID = Utils.DateTimeToUnixTimestamp(cmdTimeGenerated).ToString(); //if (projectSelected.last_updated == 0.0) if (projectSelected.id == null) { //@TODO: Check if there is a unsynchroned project with the same name. //There isn't another way to check if the project wasn't sync instead of checking by name //I will assume that the user never create a project with two names intentionally. } else { deleteIconButton.IsEnabled = false; todoistService.RemoveProject(cmdTimeGenerated, projectSelected, (data) => { app.projects.Remove(projectSelected); MainTodoistPage.showMessage = (progress) => { Utils.ProgressIndicatorStatus(String.Format("\"{0}\" deleted.", projectSelected.name), progress); }; }, (errorMsg) => { MessageBox.Show(Utils.Message(errorMsg), "Metroist", MessageBoxButton.OK); }, () => { deleteIconButton.IsEnabled = true; var currentPage = app.RootFrame.Content as PhoneApplicationPage; if (currentPage == this) NavigationService.GoBack(); }); } } }
private void GetData() { TodoistService todoistService = new TodoistService(); if (app.projects != null && app.projects.Count() > 0) { UpdateFilterTasksAndProjects(); } if (app.TemporaryDesynchronized.Count > 0) SyncStatusLabel.Text = String.Format("{0} item(s) to be sync.", app.TemporaryDesynchronized.Count); progressIndicator.Text = "Updating data"; updateAllIconButton.IsEnabled = false; todoistService.SyncAndGetUpdated(progressIndicator, (data) => { UpdateBasedOnTemporaryDessychronized(data); app.projects = data.Projects; app.items = data.Items; app.notes = data.Notes; }, (error) => { MessageBox.Show(error, "Metroist", MessageBoxButton.OK); }, () => { updateAllIconButton.IsEnabled = true; UpdateFilterTasksAndProjects(); }, () => { updateAllIconButton.IsEnabled = true; if (app.settings.ApplicationStartingCounter == 5 && !app.settings.ApplicationIsRated) { Visual.Controls.MessageBox msgBox = Visual.Controls.MessageBox.Show( "Do you like Metroist for Windows Phone?", "Love us?", "5 stars!", "maybe later"); msgBox.Closed += (sender, e) => { if (e.Result == Visual.Controls.MessageBox.CustomMessageBoxResult.Yes) { app.settings.ApplicationIsRated = true; try { MarketplaceReviewTask marketplaceReviewTask = new MarketplaceReviewTask(); marketplaceReviewTask.Show(); } catch { } } else app.settings.ApplicationStartingCounter = 0; }; } }); HandleNetworkStatusViewer(); }