Пример #1
0
        private void UpdateTimeOptions()
        {
            if (Class == null)
            {
                return;
            }

            if (Class.IsNoClassClass || !PowerPlannerApp.DoesClassOccurOnDate(Account, Date, Class))
            {
                MakeTimeOptionsLike(new string[]
                {
                    TimeOption_AllDay,
                    TimeOption_Custom
                });
            }
            else
            {
                switch (Type)
                {
                case TaskOrEventType.Task:
                    MakeTimeOptionsLike(new string[]
                    {
                        TimeOption_BeforeClass,
                        TimeOption_StartOfClass,
                        TimeOption_DuringClass,
                        TimeOption_EndOfClass,
                        TimeOption_AllDay,
                        TimeOption_Custom
                    });
                    break;

                case TaskOrEventType.Event:
                    MakeTimeOptionsLike(new string[]
                    {
                        TimeOption_AllDay,
                        TimeOption_DuringClass,
                        TimeOption_Custom
                    });
                    break;
                }
            }

            if (!TimeOptions.Contains(SelectedTimeOption))
            {
                if (Type == TaskOrEventType.Event && TimeOptions.Length == 3)
                {
                    SelectedTimeOption = TimeOptions[1];
                }
                else
                {
                    SelectedTimeOption = TimeOptions.First();
                }

                _userChangedSelectedTimeOption = false;
            }
            else
            {
                OnPropertyChanged(nameof(SelectedTimeOption));
            }
        }
Пример #2
0
        public static async Task InitializeAndLaunchAsync()
        {
            // Register the obtain dispatcher function
            PortableDispatcher.ObtainDispatcherFunction = () => { return(new DummyDispatcher()); };

            // Register message dialog
            PortableMessageDialog.Extension = (messageDialog) => { DummyMessageDialog.Show(messageDialog); return(Task.FromResult(true)); };

            // Initialize the app
            await PowerPlannerApp.InitializeAsync((PowerPlannerApp)Activator.CreateInstance(typeof(DummyPowerPlannerApp)));

            await Current.LaunchAsync();

            await Current.GetMainWindowViewModel().HandleNormalLaunchActivation();
        }
Пример #3
0
        /// <summary>
        /// Gets the time option with the class schedule factored in
        /// </summary>
        /// <returns></returns>
        public DataItemMegaItem.TimeOptions GetActualTimeOption()
        {
            switch (TimeOption)
            {
            case DataItemMegaItem.TimeOptions.AllDay:
                return(DataItemMegaItem.TimeOptions.AllDay);

            case DataItemMegaItem.TimeOptions.Custom:
                return(DataItemMegaItem.TimeOptions.Custom);
            }

            var c = GetClassOrNull();

            if (c == null || c.IsNoClassClass || !PowerPlannerApp.DoesClassOccurOnDate(Account, Date, c))
            {
                return(DataItemMegaItem.TimeOptions.AllDay);
            }

            return(TimeOption);
        }
Пример #4
0
        public override async void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action <UIBackgroundFetchResult> completionHandler)
        {
            // Payload reference: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification

            /*
             * {
             *   "content-available": 1
             *   "action": "syncAccount",
             *   "accountId": 49831
             * }
             * */

            try
            {
                if (userInfo.TryGetValue(new NSString("action"), out NSObject actionValue) &&
                    actionValue is NSString actionValueStr &&
                    actionValueStr == "syncAccount" &&
                    userInfo.TryGetValue(new NSString("accountId"), out NSObject accountIdValue) &&
                    accountIdValue is NSNumber accountIdNum)
                {
                    long accountId = accountIdNum.Int64Value;

                    await PowerPlannerApp.SyncAccountInBackgroundAsync(accountId);
                }
            }
            catch (Exception ex)
            {
                TelemetryExtension.Current?.TrackException(ex);
            }

            try
            {
                completionHandler(UIBackgroundFetchResult.NewData);
            }
            catch { }
        }
Пример #5
0
        public static AddTaskOrEventViewModel CreateForAdd(BaseViewModel parent, AddParameter addParams)
        {
            AccountDataItem account = parent.FindAncestor <MainWindowViewModel>()?.CurrentAccount;

            if (account == null)
            {
                throw new NullReferenceException("CurrentAccount was null");
            }

            if (addParams.Classes.Count == 0)
            {
                throw new InvalidOperationException("No classes");
            }

            bool     intelligentlyPickDate = true;
            DateTime now = DateTime.Now;

            IList <ViewItemClass> classes = GetClassesWithNoClassClass(addParams.Classes);

            ViewItemClass c = addParams.SelectedClass;

            if (c == null)
            {
                if (addParams.Type == TaskOrEventType.Task || addParams.Type == TaskOrEventType.Event)
                {
                    var prevClassIdentifier = NavigationManager.GetPreviousAddItemClass();
                    if (prevClassIdentifier != null)
                    {
                        // Remember user's selection
                        c = classes.FirstOrDefault(i => i.Identifier == prevClassIdentifier);
                    }

                    if (c == null)
                    {
                        // If date is specified
                        if (addParams.DueDate != null)
                        {
                            // If today
                            if (addParams.DueDate.Value.Date == now.Date)
                            {
                                // Pick currently going on class
                                c = PowerPlannerApp.GetClosestClassBasedOnSchedule(now, account, addParams.Classes);
                            }

                            // If there wasn't a class going on (or wasn't today), pick first class on that day
                            if (c == null)
                            {
                                c = PowerPlannerApp.GetFirstClassOnDay(addParams.DueDate.Value, account, addParams.Classes);
                            }
                        }

                        // Otherwise
                        else
                        {
                            // Intelligently pick based on schedule
                            c = PowerPlannerApp.GetClosestClassBasedOnSchedule(now, account, addParams.Classes);
                        }
                    }

                    if (c == null)
                    {
                        // If there wasn't a class and we're just doing the dummy pick first,
                        // don't intelligently pick class date
                        intelligentlyPickDate = false;
                        c = classes.First();
                    }
                }
                else
                {
                    // Tasks don't have classes
                    intelligentlyPickDate = false;
                }
            }

            DateTime date;

            if (addParams.DueDate != null)
            {
                date = addParams.DueDate.Value;
            }
            else
            {
                var prevDate = NavigationManager.GetPreviousAddItemDate();
                if (prevDate != null)
                {
                    date = prevDate.Value;
                }
                else
                {
                    DateTime?nextClassDate = null;

                    if (intelligentlyPickDate)
                    {
                        nextClassDate = PowerPlannerApp.GetNextClassDate(account, c);
                    }

                    if (nextClassDate != null)
                    {
                        date = nextClassDate.Value;
                    }
                    else
                    {
                        date = DateTime.Today;
                    }
                }
            }

            return(new AddTaskOrEventViewModel(parent)
            {
                Account = account,
                State = OperationState.Adding,
                AddParams = addParams,
                Classes = classes,
                Date = date.Date,
                Type = addParams.Type,
                IsClassPickerVisible = !addParams.HideClassPicker,
                IsWeightCategoryPickerVisible = true,
                ImageAttachments = new ObservableCollection <BaseEditingImageAttachmentViewModel>(),
                IsInDifferentTimeZone = parent.FindAncestorOrSelf <MainScreenViewModel>().CurrentAccount.IsInDifferentTimeZone,
                Class = c // Assign class last, since it also assigns weight categories, and updates time options from remembered times
            });
        }
Пример #6
0
        protected override async Task PerformWorkAsync(JobParameters @params)
        {
            long accountId = @params.Extras.GetLong("AccountId");

            await PowerPlannerApp.SyncAccountInBackgroundAsync(accountId);
        }