Esempio n. 1
0
        public static BaseArguments CreateArgumentsForView(DataItemMegaItem item, Guid localAccountId, LaunchSurface launchSurface = LaunchSurface.Normal)
        {
            BaseArgumentsWithAccountAndItem args;

            if (item.MegaItemType == PowerPlannerSending.MegaItemType.Homework)
            {
                args = new ViewHomeworkArguments();
            }

            else if (item.MegaItemType == PowerPlannerSending.MegaItemType.Exam)
            {
                args = new ViewExamArguments();
            }

            else
            {
                return new OpenAccountArguments()
                       {
                           LocalAccountId = localAccountId
                       }
            };

            args.LocalAccountId = localAccountId;
            args.ItemId         = item.Identifier;
            args.LaunchSurface  = launchSurface;

            return(args);
        }
Esempio n. 2
0
        public static BaseArguments CreateArgumentsForView(BaseViewItemHomeworkExam item, Guid localAccountId)
        {
            BaseArgumentsWithAccountAndItem args;

            if (item is ViewItemHomework)
            {
                args = new ViewHomeworkArguments();
            }

            else if (item is ViewItemExam)
            {
                args = new ViewExamArguments();
            }

            else
            {
                return new OpenAccountArguments()
                       {
                           LocalAccountId = localAccountId
                       }
            };

            args.LocalAccountId = localAccountId;
            args.ItemId         = item.Identifier;

            return(args);
        }
    }
        private static void UpdateDayOfNotification(Guid localAccountId, BaseViewItemHomeworkExam item, DateTime dayOfReminderTime, Context context, NotificationManager notificationManager, List <StatusBarNotification> existingNotifs, bool fromForeground)
        {
            ViewItemClass c = item.GetClassOrNull();

            if (c == null)
            {
                return;
            }

            string tag      = localAccountId.ToString() + ";" + item.Identifier.ToString();
            var    existing = existingNotifs.FirstOrDefault(i => i.Tag == tag);

            // If the reminder has already been sent and the notification doesn't exist,
            // that means the user dismissed it, so don't show it again
            if (item.HasSentReminder && existing == null)
            {
                return;
            }

            // If there's no existing notification, and the updated time is greater than the desired reminder time,
            // then it was edited after the notification should have been sent, so don't notify, since user was already
            // aware of this item (by the fact that they were editing it)
            if (existing == null && item.Updated.ToLocalTime() > dayOfReminderTime)
            {
                return;
            }

            if (existing == null && fromForeground)
            {
                return;
            }

            const string EXTRA_UNIQUE_ID = "UniqueId";
            string       extraUniqueId   = (item.Name + ";" + c.Name).GetHashCode().ToString();

            // If there's an existing, and it hasn't changed, do nothing
            if (existing != null && existing.Notification.Extras.GetString(EXTRA_UNIQUE_ID).Equals(extraUniqueId))
            {
                return;
            }

            BaseArguments launchArgs;

            if (item is ViewItemHomework)
            {
                launchArgs = new ViewHomeworkArguments()
                {
                    LocalAccountId = localAccountId,
                    ItemId         = item.Identifier,
                    LaunchSurface  = LaunchSurface.Toast
                };
            }
            else
            {
                launchArgs = new ViewExamArguments()
                {
                    LocalAccountId = localAccountId,
                    ItemId         = item.Identifier,
                    LaunchSurface  = LaunchSurface.Toast
                };
            }

            var    builder = CreateReminderBuilder(context, localAccountId, launchArgs);
            Bundle b       = new Bundle();

            b.PutString(EXTRA_UNIQUE_ID, extraUniqueId);
            builder.SetExtras(b);
            builder.SetContentTitle(item.Name);
            builder.SetChannelId(GetChannelIdForDayOf(localAccountId));
            string subtitle = item.GetSubtitleOrNull();

            if (subtitle != null)
            {
                builder.SetContentText(subtitle);
            }
            notificationManager.Notify(tag, NotificationIds.DAY_OF_NOTIFICATIONS, BuildReminder(builder));
        }
Esempio n. 4
0
        public static BaseArguments Parse(string queryString)
        {
            QueryString qs = QueryString.Parse(queryString);

            string          val;
            ArgumentsAction action = ArgumentsAction.Unknown;

            if (!(qs.TryGetValue(KEY_ACTION, out val) && Enum.TryParse(val, out action)))
            {
                return(null);
            }

            BaseArguments answer = null;

            switch (action)
            {
            case ArgumentsAction.ViewPage:
                answer = new ViewPageArguments();
                break;

            case ArgumentsAction.ViewSchedule:
                answer = new ViewScheduleArguments();
                break;

            case ArgumentsAction.ViewClass:
                answer = new ViewClassArguments();
                break;

            case ArgumentsAction.QuickAdd:
                answer = new QuickAddArguments();
                break;

            case ArgumentsAction.QuickAddToCurrentAccount:
                answer = new QuickAddToCurrentAccountArguments();
                break;

            case ArgumentsAction.QuickAddHomeworkToCurrentAccount:
                answer = new QuickAddHomeworkToCurrentAccountArguments();
                break;

            case ArgumentsAction.QuickAddExamToCurrentAccount:
                answer = new QuickAddExamToCurrentAccountArguments();
                break;

            case ArgumentsAction.OpenAccount:
                answer = new OpenAccountArguments();
                break;

            case ArgumentsAction.ViewHomework:
                answer = new ViewHomeworkArguments();
                break;

            case ArgumentsAction.ViewExam:
                answer = new ViewExamArguments();
                break;

            case ArgumentsAction.ViewHoliday:
                answer = new ViewHolidayArguments();
                break;
            }

            if (answer != null)
            {
                if (answer.TryParse(qs))
                {
                    return(answer);
                }
            }

            return(null);
        }
Esempio n. 5
0
        protected override async System.Threading.Tasks.Task OnLaunchedOrActivated(IActivatedEventArgs e)
        {
            try
            {
                // Always call this just to reset value back to false, since Resuming isn't called all the time
                AccountDataStore.RetrieveAndResetWasUpdatedByBackgroundTask();

#if DEBUG
                //if (System.Diagnostics.Debugger.IsAttached)
                //{
                //    this.DebugSettings.EnableFrameRateCounter = true;
                //}
#endif

                OnEntering();

                // Wait for initialization to complete, to ensure we don't accidently add multiple windows
                // Although right now we don't even do any async tasks, so this will be useless
                await PowerPlannerApp.InitializeTask;

                MainAppWindow mainAppWindow;

                // If no windows, need to register window
                mainAppWindow = PowerPlannerApp.Current.Windows.OfType <MainAppWindow>().FirstOrDefault();
                if (mainAppWindow == null)
                {
                    // This configures the view models, does NOT call Activate yet
                    var nativeWindow = new NativeUwpAppWindow();
                    mainAppWindow = new MainAppWindow();
                    await PowerPlannerApp.Current.RegisterWindowAsync(mainAppWindow, nativeWindow);

                    if (PowerPlannerApp.Current.Windows.Count > 1)
                    {
                        throw new Exception("There are more than 1 windows registered");
                    }
                }

                if (e is LaunchActivatedEventArgs)
                {
                    var launchEventArgs = e as LaunchActivatedEventArgs;
                    var launchContext   = !object.Equals(launchEventArgs.TileId, "App") ? LaunchSurface.SecondaryTile : LaunchSurface.Normal;
                    if (launchContext == LaunchSurface.Normal)
                    {
                        // Track whether was launched from primary tile
                        if (ApiInformation.IsPropertyPresent(typeof(LaunchActivatedEventArgs).FullName, nameof(LaunchActivatedEventArgs.TileActivatedInfo)))
                        {
                            if (launchEventArgs.TileActivatedInfo != null)
                            {
                                launchContext = LaunchSurface.PrimaryTile;
                            }
                        }
                    }

                    await HandleArguments(mainAppWindow, launchEventArgs.Arguments, launchContext);
                }

                else if (e is ToastNotificationActivatedEventArgs)
                {
                    var args = e as ToastNotificationActivatedEventArgs;

                    await HandleArguments(mainAppWindow, args.Argument, LaunchSurface.Toast);
                }

                else if (e is ProtocolActivatedEventArgs)
                {
                    var protocolEventArgs = e as ProtocolActivatedEventArgs;

                    if (!string.IsNullOrWhiteSpace(protocolEventArgs.Uri.PathAndQuery) && protocolEventArgs.Uri.PathAndQuery.StartsWith("?"))
                    {
                        await HandleArguments(mainAppWindow, protocolEventArgs.Uri.PathAndQuery.Substring(1), LaunchSurface.Uri);
                    }
                }

                else if (e is AppointmentsProviderShowAppointmentDetailsActivatedEventArgs)
                {
                    // Note that this code is essentially deprecated and doesn't get hit... Uri launch happens instead
                    var showDetailsArgs = e as AppointmentsProviderShowAppointmentDetailsActivatedEventArgs;

                    try
                    {
                        AppointmentsHelper.RoamingIdData data = AppointmentsHelper.RoamingIdData.FromString(showDetailsArgs.RoamingId);

                        string finalArgs = null;

                        switch (data.ItemType)
                        {
                        case ItemType.Homework:
                            finalArgs = new ViewHomeworkArguments()
                            {
                                LocalAccountId = data.LocalAccountId,
                                ItemId         = data.Identifier
                            }.SerializeToString();
                            break;

                        case ItemType.Exam:
                            finalArgs = new ViewExamArguments()
                            {
                                LocalAccountId = data.LocalAccountId,
                                ItemId         = data.Identifier
                            }.SerializeToString();
                            break;

                        case ItemType.Task:
                            // TODO: Not supported yet
                            break;

                        case ItemType.Schedule:
                            finalArgs = new ViewScheduleArguments()
                            {
                                LocalAccountId = data.LocalAccountId
                            }.SerializeToString();
                            break;

                        case ItemType.MegaItem:
                            break;
                        }

                        if (finalArgs != null)
                        {
                            await HandleArguments(mainAppWindow, finalArgs, LaunchSurface.Calendar);
                        }
                    }

                    catch (Exception ex)
                    {
                        TelemetryExtension.Current?.TrackException(ex);
                    }
                }

                if (mainAppWindow.GetViewModel().Content == null)
                {
                    await mainAppWindow.GetViewModel().HandleNormalLaunchActivation();
                }

                Window.Current.Activate();

                // Listen to window activation changes
                Window.Current.Activated += Current_Activated;

                // Set up the default window properties
                ConfigureWindowProperties();

                // Set up the sharing support
                ConfigureDataTransferManager();

                // Display updates
                HandleVersionChange();
            }

            catch (Exception ex)
            {
                TelemetryExtension.Current?.TrackException(ex);
            }
        }