Esempio n. 1
0
        public async Task <bool> PinAsync(ITask task)
        {
            string tileId = LaunchArgumentsHelper.GetArgEditTask(task);

            var tile = new SecondaryTile(
                tileId,
                task.Title,
                tileId,
                SafeUri.Get("ms-appx:///Assets/Logo150.png"),
                TileSize.Wide310x150);

            tile.VisualElements.Wide310x150Logo = SafeUri.Get("ms-appx:///Assets/Wide310x150Logo.png");

            tile.RoamingEnabled = true;

            bool isPinned = await tile.RequestCreateForSelectionAsync(GetPlacement(), Placement.Above);

            if (isPinned)
            {
                if (this.updateTileTimer != null)
                {
                    this.updateTileTimer.Start();
                }

                this.secondaryTiles.Add(tile);
                this.notificationService?.ShowNotification(string.Format(StringResources.Notification_TaskPinnedFormat, task.Title), ToastType.Info);

                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        public async Task <bool> PinAsync(IAbstractFolder abstractFolder)
        {
            string tileId = LaunchArgumentsHelper.GetArgSelectFolder(abstractFolder);

            var tile = new SecondaryTile(
                tileId,
                abstractFolder.Name,
                tileId,
                SafeUri.Get("ms-appx:///Assets/Logo150.png"),
                TileSize.Wide310x150);

            tile.VisualElements.Wide310x150Logo   = SafeUri.Get("ms-appx:///Assets/Wide310x150Logo.png");
            tile.VisualElements.Square310x310Logo = SafeUri.Get("ms-appx:///Assets/Square310x310Logo.png");
            tile.VisualElements.BackgroundColor   = Colors.Transparent;

            tile.RoamingEnabled = true;

            bool isPinned = await tile.RequestCreateForSelectionAsync(GetPlacement(), Placement.Below);

            if (isPinned)
            {
                if (this.updateTileTimer != null)
                {
                    this.updateTileTimer.Start();
                }

                this.secondaryTiles.Add(tile);
                this.notificationService?.ShowNotification(string.Format(StringResources.Notification_FolderPinnedFormat, abstractFolder.Name), ToastType.Info);

                return(true);
            }

            return(false);
        }
        public override void Dispose()
        {
            this.Settings.SetValue(CoreSettings.AutoDeleteFrequency, AutoDeleteFrequencyConverter.FromDescription(this.selectedAutoDelete));
            this.Settings.SetValue(CoreSettings.DefaultPriority, TaskPriorityConverter.FromDescription(this.selectedDefaultPriority));
            this.Settings.SetValue(CoreSettings.DefaultDueDate, DefaultDateConverter.FromDescription(this.selectedDefaultDueDate));
            this.Settings.SetValue(CoreSettings.DefaultStartDate, DefaultDateConverter.FromDescription(this.selectedDefaultStartDate));
            this.Settings.SetValue(CoreSettings.CompletedTasksMode, CompletedTaskModeConverter.FromDescription(this.selectedCompletedTaskMode));
            this.Settings.SetValue(CoreSettings.UseGroupedDates, this.useGroupedDates);
            this.Settings.SetValue(CoreSettings.ShowFutureStartDates, this.showFutureStartDates);
            this.Settings.SetValue(CoreSettings.IncludeNoDateInViews, this.showNoDueWithOther);
            this.Settings.SetValue(CoreSettings.AutoDeleteTags, this.autoDeleteTags);
            this.Settings.SetValue(CoreSettings.CompleteTaskSetProgress, this.completeTaskSetsProgress);

            if (this.selectedDefaultContext != null)
            {
                this.Settings.SetValue(CoreSettings.DefaultContext, this.selectedDefaultContext.Id);
            }
            else
            {
                this.Settings.SetValue(CoreSettings.DefaultContext, -1);
            }

            if (this.selectedBadgeValue != this.originalSelectedBadgeValue)
            {
                string settingValue = null;
                if (this.selectedBadgeValue != this.badgeValues[0])
                {
                    settingValue = LaunchArgumentsHelper.GetArgSelectFolder(this.selectedBadgeValue);
                }

                this.Settings.SetValue(CoreSettings.BadgeValue, settingValue);
                this.tileManager.UpdateTiles();
            }
        }
        public static XmlDocument CreateTaskToastNotification(ITask task)
        {
            string content = string.Empty;

            try
            {
                XmlDocument xmlDocument = new XmlDocument();

                const string templateXml = @"
                    <toast scenario='reminder'>
                        <visual>
                            <binding template='ToastGeneric'>
                                <text>{0}</text>
                                <text>{1}</text>
                                <image placement='AppLogoOverride' src='{2}' />
                            </binding>
                        </visual>
                        <actions>
                            <input id='snoozeTime' type='selection' defaultInput='5'>
                              <selection id='5' content='5 {3}' />
                              <selection id='30' content='30 {3}' />
                              <selection id='60' content='1 {4}' />
                              <selection id='240' content='4 {5}' />
                              <selection id='1440' content='1 {6}' />
                            </input>
                            <action activationType='system' arguments='snooze' hint-inputId='snoozeTime' content=''/>
                            <action content='{7}' arguments='{8}' activationType='background' />
                            <action content='{9}' arguments='{10}' activationType='foreground' />
                        </actions>
                        <audio src='ms-winsoundevent:Notification.Reminder' />
                    </toast>
                    ";

                content = string.Format(
                    templateXml,
                    SafeEscape(task.Title),                         // 0
                    SafeEscape(task.Note ?? string.Empty),          // 1
                    ResourcesLocator.GetAppIconPng(),               // 2
                    StringResources.Notification_SnoozeMinutes,     // 3
                    StringResources.Notification_SnoozeHour,        // 4
                    StringResources.Notification_SnoozeHours,       // 5
                    StringResources.Notification_SnoozeDay,         // 6
                    StringResources.Notification_Done,              // 7
                    LaunchArgumentsHelper.GetArgCompleteTask(task), // 8
                    StringResources.Notification_Edit,              // 9
                    LaunchArgumentsHelper.GetArgEditTask(task)      // 10
                    );

                xmlDocument.LoadXml(content);

                return(xmlDocument);
            }
            catch (Exception ex)
            {
                TrackingManagerHelper.Exception(ex, string.Format("Exception CreateTaskToastNotification: {0}", content));
                return(null);
            }
        }
        public void SmartView()
        {
            // act
            var descriptor = LaunchArgumentsHelper.GetDescriptorFromArgument(this.workbook, "smartview-5");

            // verify
            Assert.AreEqual(this.workbook.SmartViews[0], descriptor.Folder);
            Assert.AreEqual(LaunchArgumentType.Select, descriptor.Type);
            Assert.IsNull(descriptor.Task);
        }
        public void Tag()
        {
            // act
            var descriptor = LaunchArgumentsHelper.GetDescriptorFromArgument(this.workbook, "tag-12");

            // verify
            Assert.AreEqual(this.workbook.Tags.ElementAt(0), descriptor.Folder);
            Assert.AreEqual(LaunchArgumentType.Select, descriptor.Type);
            Assert.IsNull(descriptor.Task);
        }
        public void Context()
        {
            // act
            var descriptor = LaunchArgumentsHelper.GetDescriptorFromArgument(this.workbook, "context-7");

            // verify
            Assert.AreEqual(this.workbook.Contexts[0], descriptor.Folder);
            Assert.AreEqual(LaunchArgumentType.Select, descriptor.Type);
            Assert.IsNull(descriptor.Task);
        }
        public void UnkownTask()
        {
            // act
            var descriptor = LaunchArgumentsHelper.GetDescriptorFromArgument(this.workbook, "task-100");

            // verify
            Assert.AreEqual(LaunchArgumentType.Unknown, descriptor.Type);
            Assert.IsNull(descriptor.Task);
            Assert.IsNull(descriptor.Folder);
        }
        public void Complete_Task()
        {
            // act
            var descriptor = LaunchArgumentsHelper.GetDescriptorFromArgument(this.workbook, "complete/task-9");

            // verify
            Assert.AreEqual(this.workbook.Tasks[0], descriptor.Task);
            Assert.AreEqual(LaunchArgumentType.CompleteTask, descriptor.Type);
            Assert.IsNull(descriptor.Folder);
        }
        public void Edit_Task_NoPrefix()
        {
            // act
            var descriptor = LaunchArgumentsHelper.GetDescriptorFromArgument(this.workbook, "task-9");

            // verify
            Assert.AreEqual(this.workbook.Tasks[0], descriptor.Task);
            Assert.AreEqual(LaunchArgumentType.EditTask, descriptor.Type);
            Assert.IsNull(descriptor.Folder);
        }
        public void WhitespaceArgs()
        {
            // act
            var descriptor = LaunchArgumentsHelper.GetDescriptorFromArgument(this.workbook, " ");

            // verify
            Assert.IsNotNull(descriptor);
            Assert.IsNull(descriptor.Task);
            Assert.IsNull(descriptor.Folder);
            Assert.AreEqual(LaunchArgumentType.Unknown, descriptor.Type);
        }
Esempio n. 12
0
 public bool IsPinned(ITask task)
 {
     try
     {
         return(SecondaryTile.Exists(LaunchArgumentsHelper.GetArgEditTask(task)));
     }
     catch (Exception ex)
     {
         LogService.Log("TileManager", $"Exception in IsPinned: {ex}");
         return(false);
     }
 }
Esempio n. 13
0
 public bool IsPinned(IAbstractFolder folder)
 {
     try
     {
         return(SecondaryTile.Exists(LaunchArgumentsHelper.GetArgSelectFolder(folder)));
     }
     catch (Exception ex)
     {
         LogService.Log("TileManager", $"Exception in IsPinned: {ex}");
         return(false);
     }
 }
Esempio n. 14
0
        public async Task <bool> UnpinAsync(IAbstractFolder folder)
        {
            if (this.IsPinned(folder))
            {
                string id     = LaunchArgumentsHelper.GetArgSelectFolder(folder);
                var    tile   = new SecondaryTile(id);
                bool   result = await tile.RequestDeleteForSelectionAsync(GetPlacement(), Placement.Below);

                if (result)
                {
                    this.secondaryTiles.Remove(t => t.TileId == id);
                    this.notificationService?.ShowNotification(string.Format(StringResources.Notification_FolderUnpinnedFormat, folder.Name), ToastType.Info);
                }

                return(result);
            }

            return(false);
        }
Esempio n. 15
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var details = taskInstance.TriggerDetails as ToastNotificationActionTriggerDetail;

            if (details != null && !string.IsNullOrWhiteSpace(details.Argument))
            {
                var persistenceLayer = new WinPersistenceLayer(automaticSave: false);
                var workbook         = persistenceLayer.Open(tryUpgrade: true);
                workbook.Initialize();

                var platformService = new PlatformService(
                    ApplicationVersion.GetAppVersion(),
                    workbook.Settings.GetValue <string>(CoreSettings.DeviceId),
                    () => string.Empty);

                // important: load alarm manager so that we update reminders properly is a recurring task is created
                var alarmManager = new AlarmManager(workbook);

                LaunchArgumentDescriptor descriptor = LaunchArgumentsHelper.GetDescriptorFromArgument(workbook, details.Argument);
                if (descriptor.Task != null && descriptor.Type == LaunchArgumentType.CompleteTask)
                {
                    descriptor.Task.IsCompleted = true;
                    persistenceLayer.Save();

                    UpdateSyncMetadata(workbook, platformService, descriptor);

                    var tileManager = new TileManager(workbook, new TrackingManager(false, DeviceFamily.Unkown), null, true);
                    tileManager.LoadSecondaryTilesAsync().Wait(500);
                    tileManager.UpdateTiles();

                    // signal changes (usefull if app is currently running)
                    waitHandle.Set();
                }
            }

            taskInstance.GetDeferral().Complete();
        }
        public GeneralSettingsPageViewModel(IWorkbook workbook, INavigationService navigationService, ITileManager tileManager)
            : base(workbook, navigationService)
        {
            if (tileManager == null)
            {
                throw new ArgumentNullException(nameof(tileManager));
            }

            this.tileManager           = tileManager;
            this.defaultContextChoices = new List <IContext>(this.Workbook.Contexts);
            this.defaultContextChoices.Insert(0, null);

            this.badgeValues = new List <IAbstractFolder> {
                new Folder {
                    Name = StringResources.Settings_NoBadgeValue.ToLowerInvariant()
                }
            };
            this.badgeValues.AddRange(this.Workbook.Views);
            this.badgeValues.AddRange(this.Workbook.SmartViews);
            this.badgeValues.AddRange(this.Workbook.Folders);
            this.badgeValues.AddRange(this.Workbook.Contexts);
            this.badgeValues.AddRange(this.Workbook.Tags);

            AutoDeleteFrequency frequency = this.Settings.GetValue <AutoDeleteFrequency>(CoreSettings.AutoDeleteFrequency);

            this.selectedAutoDelete = frequency.GetDescription();

            TaskPriority priority = this.Settings.GetValue <TaskPriority>(CoreSettings.DefaultPriority);

            this.selectedDefaultPriority = priority.GetDescription();

            string badgeValue = this.Settings.GetValue <string>(CoreSettings.BadgeValue);

            if (!string.IsNullOrWhiteSpace(badgeValue))
            {
                var descriptor = LaunchArgumentsHelper.GetDescriptorFromArgument(this.Workbook, badgeValue);
                if (descriptor != null && descriptor.Folder != null)
                {
                    this.originalSelectedBadgeValue = descriptor.Folder;
                    this.selectedBadgeValue         = descriptor.Folder;
                }
            }

            if (this.selectedBadgeValue == null)
            {
                this.selectedBadgeValue = this.badgeValues[0];
            }

            int      contextId      = this.Settings.GetValue <int>(CoreSettings.DefaultContext);
            IContext defaultContext = this.Workbook.Contexts.FirstOrDefault(c => c.Id == contextId);

            if (defaultContext != null)
            {
                this.selectedDefaultContext = defaultContext;
            }

            DefaultDate defaultDueDate = this.Settings.GetValue <DefaultDate>(CoreSettings.DefaultDueDate);

            this.selectedDefaultDueDate = defaultDueDate.GetDescription();

            DefaultDate defaultStartDate = this.Settings.GetValue <DefaultDate>(CoreSettings.DefaultStartDate);

            this.selectedDefaultStartDate = defaultStartDate.GetDescription();

            CompletedTaskMode completedTaskMode = this.Settings.GetValue <CompletedTaskMode>(CoreSettings.CompletedTasksMode);

            this.selectedCompletedTaskMode = completedTaskMode.GetDescription();

            this.useGroupedDates          = this.Settings.GetValue <bool>(CoreSettings.UseGroupedDates);
            this.showNoDueWithOther       = this.Settings.GetValue <bool>(CoreSettings.IncludeNoDateInViews);
            this.showFutureStartDates     = this.Settings.GetValue <bool>(CoreSettings.ShowFutureStartDates);
            this.autoDeleteTags           = this.Settings.GetValue <bool>(CoreSettings.AutoDeleteTags);
            this.completeTaskSetsProgress = this.Settings.GetValue <bool>(CoreSettings.CompleteTaskSetProgress);
        }
 public void GetArgSelectSmartView()
 {
     Assert.AreEqual("smartview-" + this.workbook.SmartViews.ElementAt(0).Id, LaunchArgumentsHelper.GetArgSelectFolder(this.workbook.SmartViews.ElementAt(0)));
 }
 public void GetArgCompleteTask()
 {
     Assert.AreEqual("complete/task-9", LaunchArgumentsHelper.GetArgCompleteTask(this.workbook.Tasks[0]));
 }
 public void GetArgEditTask()
 {
     Assert.AreEqual("task-9", LaunchArgumentsHelper.GetArgEditTask(this.workbook.Tasks[0]));
 }
 public void GetArgSelectContext()
 {
     Assert.AreEqual("context-" + this.workbook.Contexts.ElementAt(0).Id, LaunchArgumentsHelper.GetArgSelectFolder(this.workbook.Contexts.ElementAt(0)));
 }
Esempio n. 21
0
        public void UpdateTiles()
        {
            try
            {
                // update main tile
                var todayView = this.workbook.Views.FirstOrDefault(v => v.ViewKind == ViewKind.Today);
                if (todayView != null)
                {
                    var todayTasks = this.PickTasks(todayView);
                    this.SetTileContent(StringResources.SystemView_TitleToday, todayTasks, TileUpdateManager.CreateTileUpdaterForApplication());

                    bool   badgeSet         = false;
                    string badgeFolderValue = this.workbook.Settings.GetValue <string>(CoreSettings.BadgeValue);
                    if (!string.IsNullOrWhiteSpace(badgeFolderValue))
                    {
                        var descriptor = LaunchArgumentsHelper.GetDescriptorFromArgument(this.workbook, badgeFolderValue);
                        if (descriptor != null && descriptor.Folder != null)
                        {
                            var folder = descriptor.Folder;
                            this.SetBadgeValue(BadgeUpdateManager.CreateBadgeUpdaterForApplication(), this.PickTasks(folder).Count);
                            badgeSet = true;
                        }
                    }

                    if (!badgeSet)
                    {
                        this.SetBadgeValue(BadgeUpdateManager.CreateBadgeUpdaterForApplication(), 0);
                    }
                }
                else
                {
                    this.TrackEvent("Update main tile", "Could not find view today");
                }
            }
            catch (Exception ex)
            {
                TrackingManagerHelper.Exception(ex, "Error while updating main tile");
            }

            if (this.secondaryTiles == null)
            {
                this.TrackEvent("Update secondary tiles", "Secondary tiles are not loaded, skipping update");
                return;
            }

            foreach (var secondaryTile in this.secondaryTiles)
            {
                try
                {
                    TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(secondaryTile.TileId);

                    IAbstractFolder folder = LaunchArgumentsHelper.GetDescriptorFromArgument(this.workbook, secondaryTile.TileId).Folder;
                    ITask           task   = LaunchArgumentsHelper.GetDescriptorFromArgument(this.workbook, secondaryTile.TileId).Task;

                    if (folder != null)
                    {
                        var title       = folder.Name;
                        var folderTasks = this.PickTasks(folder);

                        this.SetTileContent(title, folderTasks, tileUpdater, folder);
                        this.SetBadgeValue(BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(secondaryTile.TileId), folderTasks.Count);
                    }
                    else if (task != null)
                    {
                        this.SetTileContent(task, tileUpdater);
                    }
                    else if (secondaryTile.TileId != quickAddTaskTileId)
                    {
                        // task that is linked to no folder and no task...
                        this.SetTileContent(StringResources.Message_LiveTileRemoveMe, new List <ITask>(), tileUpdater);
                    }
                }
                catch (Exception ex)
                {
                    TrackingManagerHelper.Exception(ex, "Update secondary tiles");
                }
            }
        }
Esempio n. 22
0
        public static void TryHandleArgs(object args)
        {
            try
            {
                if (!Ioc.HasType <IWorkbook>() || !Ioc.HasType <ITileManager>() || !Ioc.HasType <INavigationService>())
                {
                    return;
                }

                var workbook          = Ioc.Resolve <IWorkbook>();
                var platformService   = Ioc.Resolve <IPlatformService>();
                var navigationService = Ioc.Resolve <INavigationService>();

                Frame             rootFrame = Window.Current.Content as Frame;
                MainPage          mainPage  = null;
                MainPageViewModel viewModel = null;

                if (rootFrame != null && rootFrame.Content is MainPage)
                {
                    mainPage = (MainPage)rootFrame.Content;
                }
                if (mainPage != null && mainPage.DataContext is MainPageViewModel)
                {
                    viewModel = (MainPageViewModel)mainPage.DataContext;
                }

                string arguments = args as string;

                if (args is IActivatedEventArgs)
                {
                    var activatedEventArgs = (IActivatedEventArgs)args;
                    if (activatedEventArgs.Kind == ActivationKind.VoiceCommand)
                    {
                        var cortanaService = new CortanaRuntimeService(workbook);
                        cortanaService.TryHandleActivation(new CortanaRuntimeAction(), activatedEventArgs);

                        return;
                    }
                }

                if (arguments == LaunchArgumentsHelper.QuickAddTask)
                {
                    navigationService.FlyoutTo(typeof(TaskPage), null);
                    return;
                }

                if (args is ToastNotificationActivatedEventArgs)
                {
                    arguments = ((ToastNotificationActivatedEventArgs)args).Argument;
                    if (!string.IsNullOrWhiteSpace(arguments) && arguments.ToLowerInvariant().StartsWith("http"))
                    {
                        platformService.OpenWebUri(arguments);
                    }
                }

                var descriptor = LaunchArgumentsHelper.GetDescriptorFromArgument(workbook, arguments);
                if (descriptor.Task != null && descriptor.Type == LaunchArgumentType.EditTask)
                {
                    navigationService.FlyoutTo(typeof(TaskPage), descriptor.Task);
                }
                else if (descriptor.Folder != null && descriptor.Type == LaunchArgumentType.Select && viewModel != null)
                {
                    if (descriptor.Folder is IFolder)
                    {
                        SelectMenuItem <IFolder>(viewModel, descriptor.Folder.Id);
                    }
                    else if (descriptor.Folder is ITag)
                    {
                        SelectMenuItem <ITag>(viewModel, descriptor.Folder.Id);
                    }
                    else if (descriptor.Folder is ISmartView)
                    {
                        SelectMenuItem <ISmartView>(viewModel, descriptor.Folder.Id);
                    }
                    else if (descriptor.Folder is IView)
                    {
                        SelectMenuItem <IView>(viewModel, descriptor.Folder.Id);
                    }
                    else if (descriptor.Folder is IContext)
                    {
                        SelectMenuItem <IContext>(viewModel, descriptor.Folder.Id);
                    }
                }
                else if (descriptor.Type == LaunchArgumentType.Sync && viewModel != null)
                {
                    viewModel.SyncCommand.Execute(null);
                }
            }
            catch (Exception ex)
            {
                TrackingManagerHelper.Exception(ex, string.Format("LauncherHelper.TryHandleArgs: {0} {1}", args, ex));
            }
        }
 public void GetArgSelectTag()
 {
     Assert.AreEqual("tag-" + this.workbook.Tags.ElementAt(0).Id, LaunchArgumentsHelper.GetArgSelectFolder(this.workbook.Tags.ElementAt(0)));
 }
 public void HandleException()
 {
     LaunchArgumentsHelper.GetDescriptorFromArgument(null, "test");
 }