Пример #1
0
        protected TaskViewModelBase(IWorkbook workbook, INavigationService navigationService, IMessageBoxService messageBoxService, INotificationService notificationService, ISynchronizationManager synchronizationManager, ISpeechService speechService, ITrackingManager trackingManager, IPlatformService platformService)
            : base(workbook, navigationService)
        {
            if (messageBoxService == null)
            {
                throw new ArgumentNullException(nameof(messageBoxService));
            }
            if (notificationService == null)
            {
                throw new ArgumentNullException(nameof(notificationService));
            }
            if (synchronizationManager == null)
            {
                throw new ArgumentNullException(nameof(synchronizationManager));
            }
            if (speechService == null)
            {
                throw new ArgumentNullException(nameof(speechService));
            }
            if (trackingManager == null)
            {
                throw new ArgumentNullException(nameof(trackingManager));
            }
            if (platformService == null)
            {
                throw new ArgumentNullException(nameof(platformService));
            }

            this.messageBoxService      = messageBoxService;
            this.notificationService    = notificationService;
            this.synchronizationManager = synchronizationManager;
            this.speechService          = speechService;
            this.trackingManager        = trackingManager;
            this.platformService        = platformService;

            this.syncPrioritySupport = this.synchronizationManager.SyncPrioritySupport;

            this.priority = this.Workbook.Settings.GetValue <TaskPriority>(CoreSettings.DefaultPriority);
            if (this.syncPrioritySupport == SyncPrioritySupport.LowMediumHigh && (this.priority == TaskPriority.None || this.priority == TaskPriority.Star))
            {
                this.priority = TaskPriority.Low;
            }

            var context = ModelHelper.GetDefaultContext(this.Workbook);

            if (context != null)
            {
                this.TargetContext = context;
            }

            this.dueDate = null;
            this.title   = string.Empty;
            this.note    = string.Empty;
            this.tags    = new ObservableCollection <string>();

            this.subtasks = new ObservableCollection <ITask>();

            this.targetFolder = workbook.Folders.FirstOrDefault();

            this.frequencies = new ObservableCollection <Frequency>
            {
                new Frequency(FrequencyFactory.GetCustomFrequency(FrequencyType.Once)),
                new Frequency(FrequencyFactory.GetCustomFrequency(FrequencyType.Daily)),
                new Frequency(FrequencyFactory.GetCustomFrequency(FrequencyType.Weekly)),
                new Frequency(FrequencyFactory.GetCustomFrequency(FrequencyType.Monthly)),
                new Frequency(FrequencyFactory.GetCustomFrequency(FrequencyType.Yearly))
            };
            this.defaultFrequenciesCount = this.frequencies.Count;

            // by default, select "once"
            this.selectedFrequency = this.frequencies.First();

            this.addFolderCommand        = new RelayCommand(this.AddFolderExecute);
            this.addContextCommand       = new RelayCommand(this.AddContextExecute);
            this.clearDueDateCommand     = new RelayCommand(this.ClearDueDateExecute);
            this.clearStartDateCommand   = new RelayCommand(this.ClearStartDateExecute);
            this.clearReminderCommand    = new RelayCommand(this.ClearReminderExecute);
            this.clearProgressCommand    = new RelayCommand(() => this.Progress = null);
            this.clearContextCommand     = new RelayCommand(() => this.TargetContext = null);
            this.clearFrequencyCommand   = new RelayCommand(() => this.SelectedFrequency = null);
            this.addTagCommand           = new RelayCommand <string>(this.AddTagExecute);
            this.deleteTagCommand        = new RelayCommand <string>(this.DeleteTagExecute);
            this.openLinkCommand         = new RelayCommand(this.OpenLinkExecute);
            this.startSpeechTitleCommand = new RelayCommand(this.SpeechTitleExecute);
            this.startSpeechNoteCommand  = new RelayCommand(this.SpeechNoteExecute);
            this.quickAddCommand         = new RelayCommand(this.SaveContinueExecute);
            this.editPreviousCommand     = new RelayCommand(this.EditPreviousExecute);
            this.editNextCommand         = new RelayCommand(this.EditNextExecute);
            this.callPhoneNumberCommand  = new RelayCommand(this.CallPhoneNumberExecute);
            this.addSubtaskCommand       = new RelayCommand(this.AddSubtaskExecute);
            this.deleteSubtaskCommand    = new RelayCommand <ITask>(this.DeleteSubtaskExecute);
            this.openNotesCommand        = new RelayCommand(this.OpenNotesExecute);

            this.possibleTags  = new ObservableCollection <string>();
            this.availableTags = new ObservableCollection <ItemCountViewModel>();
        }
Пример #2
0
        public void LoadTask(ITask task)
        {
            this.task = task;

            this.Title         = task.Title;
            this.Note          = task.Note;
            this.Priority      = task.Priority;
            this.TargetFolder  = task.Folder;
            this.TargetContext = task.Context;
            this.DueDate       = task.Due;

            if (task.Start.HasValue)
            {
                this.StartDate = task.Start.Value.Date;
                this.StartTime = task.Start.Value.TimeOfDay;
            }
            else
            {
                this.StartDate = null;
                this.StartTime = null;
            }

            if (task.Alarm.HasValue)
            {
                this.ReminderDate = task.Alarm.Value.Date;
                this.ReminderTime = task.Alarm.Value.TimeOfDay;
            }
            else
            {
                this.ReminderDate = null;
                this.ReminderTime = null;
            }

            this.Progress = task.Progress;

            this.IsCompleted = task.IsCompleted;

            this.Tags.Clear();
            this.Tags.AddRange(task.ReadTags());

            // selectedFrequency must map a frequency object contained in the frequencies list
            if (task.CustomFrequency != null && task.FrequencyType.HasValue)
            {
                var frequency = this.Frequencies.FirstOrDefault(f => f.CustomFrequency.FrequencyType == task.CustomFrequency.FrequencyType);
                if (frequency == null)
                {
                    // create a new instance of ICustomFrequency that will be edited and applied back to the task if user save its changes
                    ICustomFrequency customFrequency = FrequencyFactory.GetCustomFrequency <ICustomFrequency>(task.FrequencyType.Value, task.CustomFrequency.Value);
                    frequency = new Frequency(customFrequency);
                }

                this.SelectedFrequency = frequency;
                this.SelectedFrequency.UseFixedDate = task.UseFixedDate;
            }
            else
            {
                this.SelectedFrequency = null;
            }

            this.Subtasks.Clear();
            foreach (var subtask  in task.Children)
            {
                // use a copy of the actual subtask so that we can revert changes
                this.Subtasks.Add(new Core.Shared.Model.Impl.Task
                {
                    Id          = subtask.Id,
                    Title       = subtask.Title,
                    IsCompleted = subtask.IsCompleted
                });
            }

            this.UpdateTagSuggestions();

            this.RaisePropertyChanged("HasCallAction");
            this.RaisePropertyChanged("PhoneNumber");
        }
Пример #3
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            this.viewModel = (TaskViewModelBase)this.DataContext;

            this.everyFrequency = null;
            this.daysFrequency  = null;
            this.eachFrequency  = null;

            this.cbDay1.IsChecked = false;
            this.cbDay2.IsChecked = false;
            this.cbDay3.IsChecked = false;
            this.cbDay4.IsChecked = false;
            this.cbDay5.IsChecked = false;
            this.cbDay6.IsChecked = false;
            this.cbDay7.IsChecked = false;

            var selectedFrequency = this.viewModel.SelectedFrequency;

            if (selectedFrequency != null && selectedFrequency.IsCustom)
            {
                var frequency = selectedFrequency;

                if (frequency.CustomFrequency is EveryXPeriodFrequency)
                {
                    this.everyFrequency    = frequency;
                    this.rbEvery.IsChecked = true;
                }
                else if (frequency.CustomFrequency is DaysOfWeekFrequency)
                {
                    this.daysFrequency    = frequency;
                    this.rbDays.IsChecked = true;

                    var daysOfweekFrequency = (DaysOfWeekFrequency)frequency.CustomFrequency;

                    this.cbDay1.IsChecked = daysOfweekFrequency.IsMonday;
                    this.cbDay2.IsChecked = daysOfweekFrequency.IsTuesday;
                    this.cbDay3.IsChecked = daysOfweekFrequency.IsWednesday;
                    this.cbDay4.IsChecked = daysOfweekFrequency.IsThursday;
                    this.cbDay5.IsChecked = daysOfweekFrequency.IsFriday;
                    this.cbDay6.IsChecked = daysOfweekFrequency.IsSaturday;
                    this.cbDay7.IsChecked = daysOfweekFrequency.IsSunday;
                }
                else if (frequency.CustomFrequency is OnXDayFrequency)
                {
                    this.eachFrequency           = frequency;
                    this.rbDaysOfMonth.IsChecked = true;
                }

                if (frequency.UseFixedDate)
                {
                    this.rbRepeatDueDate.IsChecked = true;
                }
                else
                {
                    this.rbRepeatTaskCompletes.IsChecked = true;
                }
            }
            else
            {
                this.rbEvery.IsChecked = true;

                if (selectedFrequency != null)
                {
                    if (selectedFrequency.CustomFrequency is DailyFrequency)
                    {
                        this.cbRates.SelectedItem  = FrequencyMetadata.AvailableRates.FirstOrDefault(rate => rate.Value == 1);
                        this.cbScales.SelectedItem = FrequencyMetadata.AvailableScales.FirstOrDefault(scale => scale.Value == CustomFrequencyScale.Day);
                    }
                    else if (selectedFrequency.CustomFrequency is WeeklyFrequency)
                    {
                        this.cbRates.SelectedItem  = FrequencyMetadata.AvailableRates.FirstOrDefault(rate => rate.Value == 1);
                        this.cbScales.SelectedItem = FrequencyMetadata.AvailableScales.FirstOrDefault(scale => scale.Value == CustomFrequencyScale.Week);
                    }
                    else if (selectedFrequency.CustomFrequency is MonthlyFrequency)
                    {
                        this.cbRates.SelectedItem  = FrequencyMetadata.AvailableRates.FirstOrDefault(rate => rate.Value == 1);
                        this.cbScales.SelectedItem = FrequencyMetadata.AvailableScales.FirstOrDefault(scale => scale.Value == CustomFrequencyScale.Month);
                    }
                    else if (selectedFrequency.CustomFrequency is YearlyFrequency)
                    {
                        this.cbRates.SelectedItem  = FrequencyMetadata.AvailableRates.FirstOrDefault(rate => rate.Value == 1);
                        this.cbScales.SelectedItem = FrequencyMetadata.AvailableScales.FirstOrDefault(scale => scale.Value == CustomFrequencyScale.Year);
                    }
                }

                if (selectedFrequency != null && !selectedFrequency.UseFixedDate)
                {
                    this.rbRepeatTaskCompletes.IsChecked = true;
                }
                else
                {
                    this.rbRepeatDueDate.IsChecked = true;
                }
            }

            if (this.everyFrequency == null)
            {
                this.everyFrequency = new Frequency(FrequencyFactory.GetCustomFrequency(FrequencyType.EveryXPeriod));
            }

            if (this.daysFrequency == null)
            {
                this.daysFrequency = new Frequency(FrequencyFactory.GetCustomFrequency(FrequencyType.DaysOfWeek));
            }

            if (this.eachFrequency == null)
            {
                this.eachFrequency = new Frequency(FrequencyFactory.GetCustomFrequency(FrequencyType.OnXDayOfEachMonth));
            }

            this.areaEvery.DataContext        = this.everyFrequency.CustomFrequency;
            this.areaSpecificDays.DataContext = this.daysFrequency.CustomFrequency;
            this.areaDaysOfMonth.DataContext  = this.eachFrequency.CustomFrequency;

            if (this.cbRates.SelectedItem == null)
            {
                this.cbRates.SelectedItem = FrequencyMetadata.AvailableRates.FirstOrDefault(rate => rate.Value == this.everyFrequency.Custom <EveryXPeriodFrequency>().Rate);
            }

            if (this.cbScales.SelectedItem == null)
            {
                this.cbScales.SelectedItem = FrequencyMetadata.AvailableScales.FirstOrDefault(scale => scale.Value == this.everyFrequency.Custom <EveryXPeriodFrequency>().Scale);
            }

            this.cbRankings.SelectedItem = FrequencyMetadata.AvailableRankings.FirstOrDefault(ranking => ranking.Value == this.eachFrequency.Custom <OnXDayFrequency>().RankingPosition);
            this.cbDays.SelectedItem     = FrequencyMetadata.AvailableDays.FirstOrDefault(day => day.Value == this.eachFrequency.Custom <OnXDayFrequency>().DayOfWeek);
        }
Пример #4
0
        public static void UpdateFromExchange(this ITask task, ExchangeTask exchangeTask)
        {
            task.Title     = exchangeTask.Subject;
            task.Priority  = exchangeTask.Importance.GetPriority();
            task.Completed = exchangeTask.Completed;
            task.Due       = exchangeTask.Due;
            task.Start     = exchangeTask.Start;

            task.SyncId = exchangeTask.Id;
            task.Note   = exchangeTask.Note;
            task.Alarm  = exchangeTask.Alarm;

            // set the progress in the task if the value is exchange is more than 0 (ie, the user has set a value - 0 being the default value for all tasks)
            // or if the task has a value which is different from the value in exchange
            if (exchangeTask.ProgressPercent > 0 || (task.Progress.HasValue && task.Progress.Value != exchangeTask.ProgressPercent))
            {
                // Progress is between 0.0 and 1.0
                task.Progress = exchangeTask.ProgressPercent / 100;
            }

            task.Modified = DateTime.Now;
            // Remove recurring if task is completed
            if (!exchangeTask.IsRecurring || exchangeTask.Completed.HasValue)
            {
                task.FrequencyType = FrequencyType.Once;
            }
            else
            {
                task.UseFixedDate = true;

                switch (exchangeTask.RecurrenceType)
                {
                case ExchangeRecurrencePattern.None:

                    break;

                case ExchangeRecurrencePattern.Daily:
                case ExchangeRecurrencePattern.DailyRegeneration:

                    if (exchangeTask.Interval == 1)
                    {
                        task.CustomFrequency = FrequencyFactory.GetCustomFrequency(FrequencyType.Daily);
                    }
                    else
                    {
                        var frequency = FrequencyFactory.GetCustomFrequency <EveryXPeriodFrequency>(FrequencyType.EveryXPeriod);
                        frequency.Scale = CustomFrequencyScale.Day;
                        frequency.Rate  = exchangeTask.Interval;

                        task.CustomFrequency = frequency;
                    }

                    task.UseFixedDate = exchangeTask.RecurrenceType == ExchangeRecurrencePattern.Daily;

                    break;

                case ExchangeRecurrencePattern.Weekly:
                case ExchangeRecurrencePattern.WeeklyRegeneration:

                    if (exchangeTask.Interval < 2)
                    {
                        int daysCount = 0;
                        var frequency = FrequencyFactory.GetCustomFrequency <DaysOfWeekFrequency>(FrequencyType.DaysOfWeek);

                        if ((exchangeTask.DaysOfWeek & ExchangeDayOfWeek.Monday) == ExchangeDayOfWeek.Monday)
                        {
                            daysCount++;
                            frequency.IsMonday = true;
                        }
                        if ((exchangeTask.DaysOfWeek & ExchangeDayOfWeek.Tuesday) == ExchangeDayOfWeek.Tuesday)
                        {
                            daysCount++;
                            frequency.IsTuesday = true;
                        }
                        if ((exchangeTask.DaysOfWeek & ExchangeDayOfWeek.Wednesday) == ExchangeDayOfWeek.Wednesday)
                        {
                            daysCount++;
                            frequency.IsWednesday = true;
                        }
                        if ((exchangeTask.DaysOfWeek & ExchangeDayOfWeek.Thursday) == ExchangeDayOfWeek.Thursday)
                        {
                            daysCount++;
                            frequency.IsThursday = true;
                        }
                        if ((exchangeTask.DaysOfWeek & ExchangeDayOfWeek.Friday) == ExchangeDayOfWeek.Friday)
                        {
                            daysCount++;
                            frequency.IsFriday = true;
                        }
                        if ((exchangeTask.DaysOfWeek & ExchangeDayOfWeek.Saturday) == ExchangeDayOfWeek.Saturday)
                        {
                            daysCount++;
                            frequency.IsSaturday = true;
                        }
                        if ((exchangeTask.DaysOfWeek & ExchangeDayOfWeek.Sunday) == ExchangeDayOfWeek.Sunday)
                        {
                            daysCount++;
                            frequency.IsSunday = true;
                        }

                        // if the weekly frequency repeat on a single day that match the due date or the start date
                        // use the WeeklyFrequency instead of DaysOfWeek
                        bool matchDaysOfWeek = (!exchangeTask.Start.HasValue && exchangeTask.Due.HasValue && exchangeTask.DaysOfWeek.ToDayOfWeek() == exchangeTask.Due.Value.DayOfWeek) ||
                                               (exchangeTask.Start.HasValue && exchangeTask.DaysOfWeek.ToDayOfWeek() == exchangeTask.Start.Value.DayOfWeek);
                        if (daysCount == 0 || (daysCount == 1 && matchDaysOfWeek))
                        {
                            task.CustomFrequency = FrequencyFactory.GetCustomFrequency(FrequencyType.Weekly);
                        }
                        else if (daysCount > 0)
                        {
                            task.CustomFrequency = frequency;
                        }
                        else
                        {
                            TrackingManagerHelper.Trace("Exchange update task weekly frequency without days");
                        }
                    }
                    else
                    {
                        var frequency = FrequencyFactory.GetCustomFrequency <EveryXPeriodFrequency>(FrequencyType.EveryXPeriod);
                        frequency.Scale = CustomFrequencyScale.Week;
                        frequency.Rate  = exchangeTask.Interval;

                        task.CustomFrequency = frequency;
                    }

                    task.UseFixedDate = exchangeTask.RecurrenceType == ExchangeRecurrencePattern.Weekly;

                    break;

                case ExchangeRecurrencePattern.Monthly:
                case ExchangeRecurrencePattern.MonthlyRegeneration:

                    if (exchangeTask.Interval < 2)
                    {
                        task.CustomFrequency = FrequencyFactory.GetCustomFrequency(FrequencyType.Monthly);
                    }
                    else
                    {
                        var frequency = FrequencyFactory.GetCustomFrequency <EveryXPeriodFrequency>(FrequencyType.EveryXPeriod);
                        frequency.Scale = CustomFrequencyScale.Month;
                        frequency.Rate  = exchangeTask.Interval;

                        task.CustomFrequency = frequency;
                    }

                    task.UseFixedDate = exchangeTask.RecurrenceType == ExchangeRecurrencePattern.Monthly;

                    break;

                case ExchangeRecurrencePattern.MonthlyRelative:
                {
                    if (exchangeTask.Interval == 1)
                    {
                        var frequency = FrequencyFactory.GetCustomFrequency <OnXDayFrequency>(FrequencyType.OnXDayOfEachMonth);
                        frequency.RankingPosition = exchangeTask.DayOfWeekIndex.ToRankingPosition();
                        frequency.DayOfWeek       = exchangeTask.DaysOfWeek.ToDayOfWeek();

                        task.CustomFrequency = frequency;
                    }
                    else if (exchangeTask.Interval > 1)
                    {
                        if (exchangeTask.Due.HasValue && exchangeTask.Due.Value.DayOfWeek == exchangeTask.DaysOfWeek.ToDayOfWeek())
                        {
                            // repeat every N month, day of the week match due date => use EveryXPeriod
                            var frequency = FrequencyFactory.GetCustomFrequency <EveryXPeriodFrequency>(FrequencyType.EveryXPeriod);
                            frequency.Rate  = exchangeTask.Interval;
                            frequency.Scale = CustomFrequencyScale.Month;

                            task.CustomFrequency = frequency;
                        }
                    }
                }

                break;

                case ExchangeRecurrencePattern.Yearly:
                case ExchangeRecurrencePattern.YearlyRegeneration:

                    if (exchangeTask.Interval < 2)
                    {
                        task.CustomFrequency = FrequencyFactory.GetCustomFrequency(FrequencyType.Yearly);
                    }
                    else
                    {
                        var frequency = FrequencyFactory.GetCustomFrequency <EveryXPeriodFrequency>(FrequencyType.EveryXPeriod);
                        frequency.Scale = CustomFrequencyScale.Year;
                        frequency.Rate  = exchangeTask.Interval;

                        task.CustomFrequency = frequency;
                    }
                    task.UseFixedDate = exchangeTask.RecurrenceType == ExchangeRecurrencePattern.Yearly;

                    break;

                default:
                    TrackingManagerHelper.Trace("ExchangeHelper - Unknown recurrence type: " + exchangeTask.RecurrenceType);
                    break;
                }
            }
        }
Пример #5
0
 private void OnBtnEveryYearTapped(object sender, TappedRoutedEventArgs e)
 {
     this.viewModel.SelectedFrequency = new Frequency(FrequencyFactory.GetCustomFrequency(FrequencyType.Yearly));
     this.Hide();
 }