Ejemplo n.º 1
0
        private async void FlyoutItem_CompleteItem(object sender, RoutedEventArgs e)
        {
            if (sender is MenuFlyoutItem flyout && flyout.DataContext is Item todo)
            {
                await Todoist.MarkTodoAsDone(todo);

                Items = await Todoist.GetItems();

                RedoTodos();
            }
        }
        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()
            }));
        }
Ejemplo n.º 3
0
        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;
        }
        // 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
        }