public IEnumerable <MainLogSection> Flatten(IEnumerable <LogGrouping> days, IThreadSafePreferences preferences) { durationFormat = preferences.DurationFormat; return(days.Select(preferences.CollapseTimeEntries ? flatten(bySimilarTimeEntries) : flatten(withJustSingleTimeEntries))); }
private void onPreferencesChanged(IThreadSafePreferences preferences) { if (durationFormat != preferences.DurationFormat) { durationFormat = preferences.DurationFormat; var _ = fetchSectionedTimeEntries(); } }
public async Task CorrectPreferencesAreRetrieved() { IThreadSafePreferences prefs = Substitute.For <IThreadSafePreferences>(); DataSource.Preferences.Current.Returns(Observable.Return(prefs)); var result = await InteractorFactory.GetPreferences().Execute().FirstAsync(); result.Should().Be(prefs); }
private void onPreferencesChanged(IThreadSafePreferences preferences) { durationFormat = preferences.DurationFormat; foreach (var collection in TimeEntries) { collection.DurationFormat = durationFormat; foreach (var timeEntry in collection) { timeEntry.DurationFormat = durationFormat; } } }
public IEnumerable <MainLogSection> Flatten(IEnumerable <LogGrouping> days, IThreadSafePreferences preferences) { durationFormat = preferences.DurationFormat; indexInLog = 0; return(days.Select((day, dayInLog) => { var today = timeService.CurrentDateTime.Date; var sample = day.First().Start.Date; var daysInThePast = (today - sample).Days; var strategy = preferences.CollapseTimeEntries ? (Func <IEnumerable <IThreadSafeTimeEntry>, IEnumerable <IThreadSafeTimeEntry[]> >)bySimilarTimeEntries : (Func <IEnumerable <IThreadSafeTimeEntry>, IEnumerable <IThreadSafeTimeEntry[]> >)withJustSingleTimeEntries; return flatten(strategy, dayInLog, daysInThePast)(day); })); }
public static IThreadSafePreferences With( this IThreadSafePreferences original, New <TimeFormat> timeOfDayFormat = default(New <TimeFormat>), New <DateFormat> dateFormat = default(New <DateFormat>), New <DurationFormat> durationFormat = default(New <DurationFormat>), New <bool> collapseTimeEntries = default(New <bool>), New <SyncStatus> syncStatus = default(New <SyncStatus>), New <string> lastSyncErrorMessage = default(New <string>), New <bool> isDeleted = default(New <bool>) ) => new Preferences( timeOfDayFormat.ValueOr(original.TimeOfDayFormat), dateFormat.ValueOr(original.DateFormat), durationFormat.ValueOr(original.DurationFormat), collapseTimeEntries.ValueOr(original.CollapseTimeEntries), syncStatus.ValueOr(original.SyncStatus), lastSyncErrorMessage.ValueOr(original.LastSyncErrorMessage), isDeleted.ValueOr(original.IsDeleted) );
public DatabaseState( IThreadSafeUser user, IEnumerable <IThreadSafeClient> clients = null, IEnumerable <IThreadSafeProject> projects = null, IThreadSafePreferences preferences = null, IEnumerable <IThreadSafeTag> tags = null, IEnumerable <IThreadSafeTask> tasks = null, IEnumerable <IThreadSafeTimeEntry> timeEntries = null, IEnumerable <IThreadSafeWorkspace> workspaces = null, IDictionary <Type, DateTimeOffset?> sinceParameters = null) { User = user; Clients = new HashSet <IThreadSafeClient>(clients ?? new IThreadSafeClient[0]); Projects = new HashSet <IThreadSafeProject>(projects ?? new IThreadSafeProject[0]); Preferences = preferences ?? new MockPreferences(); Tags = new HashSet <IThreadSafeTag>(tags ?? new IThreadSafeTag[0]); Tasks = new HashSet <IThreadSafeTask>(tasks ?? new IThreadSafeTask[0]); TimeEntries = new HashSet <IThreadSafeTimeEntry>(timeEntries ?? new IThreadSafeTimeEntry[0]); Workspaces = new HashSet <IThreadSafeWorkspace>(workspaces ?? new IThreadSafeWorkspace[0]); SinceParameters = sinceParameters ?? new Dictionary <Type, DateTimeOffset?>(); }
public SettingsViewModel( UserAgent userAgent, IMailService mailService, ITogglDataSource dataSource, IDialogService dialogService, IUserPreferences userPreferences, IFeedbackService feedbackService, IAnalyticsService analyticsService, IInteractorFactory interactorFactory, IPlatformConstants platformConstants, IOnboardingStorage onboardingStorage, IMvxNavigationService navigationService) { Ensure.Argument.IsNotNull(userAgent, nameof(userAgent)); Ensure.Argument.IsNotNull(dataSource, nameof(dataSource)); Ensure.Argument.IsNotNull(mailService, nameof(mailService)); Ensure.Argument.IsNotNull(dialogService, nameof(dialogService)); Ensure.Argument.IsNotNull(userPreferences, nameof(userPreferences)); Ensure.Argument.IsNotNull(feedbackService, nameof(feedbackService)); Ensure.Argument.IsNotNull(analyticsService, nameof(analyticsService)); Ensure.Argument.IsNotNull(onboardingStorage, nameof(onboardingStorage)); Ensure.Argument.IsNotNull(interactorFactory, nameof(interactorFactory)); Ensure.Argument.IsNotNull(navigationService, nameof(navigationService)); Ensure.Argument.IsNotNull(platformConstants, nameof(platformConstants)); this.userAgent = userAgent; this.dataSource = dataSource; this.mailService = mailService; this.dialogService = dialogService; this.userPreferences = userPreferences; this.feedbackService = feedbackService; this.analyticsService = analyticsService; this.interactorFactory = interactorFactory; this.navigationService = navigationService; this.platformConstants = platformConstants; this.onboardingStorage = onboardingStorage; IsSynced = dataSource.SyncManager.ProgressObservable.SelectMany(checkSynced); IsRunningSync = dataSource.SyncManager .ProgressObservable .Select(isRunningSync); Name = dataSource.User.Current .Select(user => user.Fullname) .DistinctUntilChanged(); Email = dataSource.User.Current .Select(user => user.Email.ToString()) .DistinctUntilChanged(); IsManualModeEnabled = userPreferences.IsManualModeEnabledObservable; WorkspaceName = dataSource.User.Current .DistinctUntilChanged(user => user.DefaultWorkspaceId) .SelectMany(_ => interactorFactory.GetDefaultWorkspace().Execute()) .Select(workspace => workspace.Name); BeginningOfWeek = dataSource.User.Current .Select(user => user.BeginningOfWeek) .DistinctUntilChanged() .Select(beginningOfWeek => beginningOfWeek.ToString()); DateFormat = dataSource.Preferences.Current .Select(preferences => preferences.DateFormat.Localized) .DistinctUntilChanged(); DurationFormat = dataSource.Preferences.Current .Select(preferences => preferences.DurationFormat) .Select(DurationFormatToString.Convert) .DistinctUntilChanged(); UseTwentyFourHourFormat = dataSource.Preferences.Current .Select(preferences => preferences.TimeOfDayFormat.IsTwentyFourHoursFormat) .DistinctUntilChanged(); UserAvatar = dataSource.User.Current .Select(user => user.ImageUrl) .DistinctUntilChanged() .SelectMany(url => interactorFactory.GetUserAvatar(url).Execute()); Workspaces = dataSource.User.Current .DistinctUntilChanged(user => user.DefaultWorkspaceId) .SelectMany(user => interactorFactory .GetAllWorkspaces() .Execute() .Select(selectableWorkspacesFromWorkspaces(user)) ); LoggingOut = loggingOutSubject.AsObservable(); dataSource.User.Current .Subscribe(user => currentUser = user) .DisposedBy(disposeBag); dataSource.Preferences.Current .Subscribe(preferences => currentPreferences = preferences) .DisposedBy(disposeBag); IsRunningSync .Subscribe(isSyncing => this.isSyncing = isSyncing) .DisposedBy(disposeBag); IsFeedbackSuccessViewShowing = isFeedbackSuccessViewShowing.AsObservable(); }
public SettingsViewModel( ITogglDataSource dataSource, ISyncManager syncManager, IPlatformInfo platformInfo, IDialogService dialogService, IUserPreferences userPreferences, IAnalyticsService analyticsService, IUserAccessManager userAccessManager, IInteractorFactory interactorFactory, IOnboardingStorage onboardingStorage, IMvxNavigationService navigationService, IPrivateSharedStorageService privateSharedStorageService, IIntentDonationService intentDonationService, IStopwatchProvider stopwatchProvider, IRxActionFactory rxActionFactory, IPermissionsService permissionsService, ISchedulerProvider schedulerProvider) { Ensure.Argument.IsNotNull(dataSource, nameof(dataSource)); Ensure.Argument.IsNotNull(syncManager, nameof(syncManager)); Ensure.Argument.IsNotNull(platformInfo, nameof(platformInfo)); Ensure.Argument.IsNotNull(dialogService, nameof(dialogService)); Ensure.Argument.IsNotNull(userPreferences, nameof(userPreferences)); Ensure.Argument.IsNotNull(analyticsService, nameof(analyticsService)); Ensure.Argument.IsNotNull(onboardingStorage, nameof(onboardingStorage)); Ensure.Argument.IsNotNull(interactorFactory, nameof(interactorFactory)); Ensure.Argument.IsNotNull(navigationService, nameof(navigationService)); Ensure.Argument.IsNotNull(userAccessManager, nameof(userAccessManager)); Ensure.Argument.IsNotNull(privateSharedStorageService, nameof(privateSharedStorageService)); Ensure.Argument.IsNotNull(intentDonationService, nameof(intentDonationService)); Ensure.Argument.IsNotNull(stopwatchProvider, nameof(stopwatchProvider)); Ensure.Argument.IsNotNull(rxActionFactory, nameof(rxActionFactory)); Ensure.Argument.IsNotNull(permissionsService, nameof(permissionsService)); Ensure.Argument.IsNotNull(schedulerProvider, nameof(schedulerProvider)); this.dataSource = dataSource; this.syncManager = syncManager; this.platformInfo = platformInfo; this.dialogService = dialogService; this.userPreferences = userPreferences; this.rxActionFactory = rxActionFactory; this.analyticsService = analyticsService; this.interactorFactory = interactorFactory; this.navigationService = navigationService; this.userAccessManager = userAccessManager; this.onboardingStorage = onboardingStorage; this.stopwatchProvider = stopwatchProvider; this.intentDonationService = intentDonationService; this.privateSharedStorageService = privateSharedStorageService; this.rxActionFactory = rxActionFactory; this.schedulerProvider = schedulerProvider; this.permissionsService = permissionsService; IsSynced = syncManager.ProgressObservable .SelectMany(checkSynced) .AsDriver(schedulerProvider); IsRunningSync = syncManager.ProgressObservable .Select(isRunningSync) .AsDriver(schedulerProvider); Name = dataSource.User.Current .Select(user => user.Fullname) .DistinctUntilChanged() .AsDriver(schedulerProvider); Email = dataSource.User.Current .Select(user => user.Email.ToString()) .DistinctUntilChanged() .AsDriver(schedulerProvider); IsManualModeEnabled = userPreferences.IsManualModeEnabledObservable .AsDriver(schedulerProvider); AreRunningTimerNotificationsEnabled = userPreferences.AreRunningTimerNotificationsEnabledObservable .AsDriver(schedulerProvider); AreStoppedTimerNotificationsEnabled = userPreferences.AreStoppedTimerNotificationsEnabledObservable .AsDriver(schedulerProvider); WorkspaceName = dataSource.User.Current .DistinctUntilChanged(user => user.DefaultWorkspaceId) .SelectMany(_ => interactorFactory.GetDefaultWorkspace() .TrackException <InvalidOperationException, IThreadSafeWorkspace>("SettingsViewModel.constructor") .Execute() ) .Select(workspace => workspace.Name) .AsDriver(schedulerProvider); BeginningOfWeek = dataSource.User.Current .Select(user => user.BeginningOfWeek) .DistinctUntilChanged() .Select(beginningOfWeek => beginningOfWeek.ToString()) .AsDriver(schedulerProvider); DateFormat = dataSource.Preferences.Current .Select(preferences => preferences.DateFormat.Localized) .DistinctUntilChanged() .AsDriver(schedulerProvider); DurationFormat = dataSource.Preferences.Current .Select(preferences => preferences.DurationFormat) .Select(DurationFormatToString.Convert) .DistinctUntilChanged() .AsDriver(schedulerProvider); UseTwentyFourHourFormat = dataSource.Preferences.Current .Select(preferences => preferences.TimeOfDayFormat.IsTwentyFourHoursFormat) .DistinctUntilChanged() .AsDriver(schedulerProvider); IsGroupingTimeEntries = dataSource.Preferences.Current .Select(preferences => preferences.CollapseTimeEntries) .DistinctUntilChanged() .AsDriver(false, schedulerProvider); IsCalendarSmartRemindersVisible = calendarPermissionGranted.AsObservable() .CombineLatest(userPreferences.EnabledCalendars.Select(ids => ids.Any()), CommonFunctions.And); CalendarSmartReminders = userPreferences.CalendarNotificationsSettings() .Select(s => s.Title()) .DistinctUntilChanged(); UserAvatar = dataSource.User.Current .Select(user => user.ImageUrl) .DistinctUntilChanged() .SelectMany(url => interactorFactory.GetUserAvatar(url).Execute()) .AsDriver(schedulerProvider) .Where(avatar => avatar != null); Workspaces = dataSource.User.Current .DistinctUntilChanged(user => user.DefaultWorkspaceId) .SelectMany(user => interactorFactory .GetAllWorkspaces() .Execute() .Select(selectableWorkspacesFromWorkspaces(user)) ) .AsDriver(schedulerProvider); LoggingOut = loggingOutSubject.AsObservable() .AsDriver(schedulerProvider); dataSource.User.Current .Subscribe(user => currentUser = user) .DisposedBy(disposeBag); dataSource.Preferences.Current .Subscribe(preferences => currentPreferences = preferences) .DisposedBy(disposeBag); IsRunningSync .Subscribe(isSyncing => this.isSyncing = isSyncing) .DisposedBy(disposeBag); IsFeedbackSuccessViewShowing = isFeedbackSuccessViewShowing.AsObservable() .AsDriver(schedulerProvider); OpenCalendarSettings = rxActionFactory.FromAsync(openCalendarSettings); OpenCalendarSmartReminders = rxActionFactory.FromAsync(openCalendarSmartReminders); OpenNotificationSettings = rxActionFactory.FromAsync(openNotificationSettings); ToggleTwentyFourHourSettings = rxActionFactory.FromAsync(toggleUseTwentyFourHourClock); OpenHelpView = rxActionFactory.FromAsync(openHelpView); TryLogout = rxActionFactory.FromAsync(tryLogout); OpenAboutView = rxActionFactory.FromAsync(openAboutView); SubmitFeedback = rxActionFactory.FromAsync(submitFeedback); SelectDateFormat = rxActionFactory.FromAsync(selectDateFormat); PickDefaultWorkspace = rxActionFactory.FromAsync(pickDefaultWorkspace); SelectDurationFormat = rxActionFactory.FromAsync(selectDurationFormat); SelectBeginningOfWeek = rxActionFactory.FromAsync(selectBeginningOfWeek); ToggleTimeEntriesGrouping = rxActionFactory.FromAsync(toggleTimeEntriesGrouping); SelectDefaultWorkspace = rxActionFactory.FromAsync <SelectableWorkspaceViewModel>(selectDefaultWorkspace); Close = rxActionFactory.FromAsync(close); }
private void onPreferencesChanged(IThreadSafePreferences preferences) { dateFormat = preferences.DateFormat; updateCurrentDateRangeString(); }
public SettingsViewModel( ITogglDataSource dataSource, ISyncManager syncManager, IPlatformInfo platformInfo, IUserPreferences userPreferences, IAnalyticsService analyticsService, IInteractorFactory interactorFactory, IOnboardingStorage onboardingStorage, INavigationService navigationService, IRxActionFactory rxActionFactory, IPermissionsChecker permissionsChecker, ISchedulerProvider schedulerProvider) : base(navigationService) { Ensure.Argument.IsNotNull(dataSource, nameof(dataSource)); Ensure.Argument.IsNotNull(syncManager, nameof(syncManager)); Ensure.Argument.IsNotNull(platformInfo, nameof(platformInfo)); Ensure.Argument.IsNotNull(userPreferences, nameof(userPreferences)); Ensure.Argument.IsNotNull(analyticsService, nameof(analyticsService)); Ensure.Argument.IsNotNull(onboardingStorage, nameof(onboardingStorage)); Ensure.Argument.IsNotNull(interactorFactory, nameof(interactorFactory)); Ensure.Argument.IsNotNull(rxActionFactory, nameof(rxActionFactory)); Ensure.Argument.IsNotNull(permissionsChecker, nameof(permissionsChecker)); Ensure.Argument.IsNotNull(schedulerProvider, nameof(schedulerProvider)); this.dataSource = dataSource; this.syncManager = syncManager; this.platformInfo = platformInfo; this.userPreferences = userPreferences; this.analyticsService = analyticsService; this.interactorFactory = interactorFactory; this.onboardingStorage = onboardingStorage; this.permissionsChecker = permissionsChecker; IsSynced = syncManager.ProgressObservable .SelectMany(checkSynced) .AsDriver(schedulerProvider); IsRunningSync = syncManager.ProgressObservable .Select(isRunningSync) .AsDriver(schedulerProvider); Name = dataSource.User.Current .Select(user => user.Fullname) .DistinctUntilChanged() .AsDriver(schedulerProvider); Email = dataSource.User.Current .Select(user => user.Email.ToString()) .DistinctUntilChanged() .AsDriver(schedulerProvider); IsManualModeEnabled = userPreferences.IsManualModeEnabledObservable .AsDriver(schedulerProvider); AreRunningTimerNotificationsEnabled = userPreferences.AreRunningTimerNotificationsEnabledObservable .AsDriver(schedulerProvider); AreStoppedTimerNotificationsEnabled = userPreferences.AreStoppedTimerNotificationsEnabledObservable .AsDriver(schedulerProvider); WorkspaceName = dataSource.User.Current .DistinctUntilChanged(user => user.DefaultWorkspaceId) .SelectMany(_ => interactorFactory.GetDefaultWorkspace() .TrackException <InvalidOperationException, IThreadSafeWorkspace>("SettingsViewModel.constructor") .Execute() ) .Select(workspace => workspace.Name) .AsDriver(schedulerProvider); BeginningOfWeek = dataSource.User.Current .Select(user => user.BeginningOfWeek) .DistinctUntilChanged() .Select(beginningOfWeek => beginningOfWeek.ToLocalizedString()) .AsDriver(schedulerProvider); DateFormat = dataSource.Preferences.Current .Select(preferences => preferences.DateFormat.Localized) .DistinctUntilChanged() .AsDriver(schedulerProvider); DurationFormat = dataSource.Preferences.Current .Select(preferences => preferences.DurationFormat.ToFormattedString()) .DistinctUntilChanged() .AsDriver(schedulerProvider); UseTwentyFourHourFormat = dataSource.Preferences.Current .Select(preferences => preferences.TimeOfDayFormat.IsTwentyFourHoursFormat) .DistinctUntilChanged() .AsDriver(schedulerProvider); IsGroupingTimeEntries = dataSource.Preferences.Current .Select(preferences => preferences.CollapseTimeEntries) .DistinctUntilChanged() .AsDriver(false, schedulerProvider); IsCalendarSmartRemindersVisible = calendarPermissionGranted.AsObservable() .CombineLatest(userPreferences.EnabledCalendars.Select(ids => ids.Any()), CommonFunctions.And); CalendarSmartReminders = userPreferences.CalendarNotificationsSettings() .Select(s => s.Title()) .DistinctUntilChanged(); LoggingOut = loggingOutSubject.AsObservable() .AsDriver(schedulerProvider); PresentableSyncStatus combineStatuses(bool synced, bool syncing, bool loggingOut) { if (loggingOut) { return(PresentableSyncStatus.LoggingOut); } return(syncing ? PresentableSyncStatus.Syncing : PresentableSyncStatus.Synced); } CurrentSyncStatus = Observable.CombineLatest( IsSynced, IsRunningSync, LoggingOut.SelectValue(true).StartWith(false), combineStatuses); dataSource.User.Current .Subscribe(user => currentUser = user) .DisposedBy(disposeBag); dataSource.Preferences.Current .Subscribe(preferences => currentPreferences = preferences) .DisposedBy(disposeBag); IsRunningSync .Subscribe(isSyncing => this.isSyncing = isSyncing) .DisposedBy(disposeBag); IsFeedbackSuccessViewShowing = isFeedbackSuccessViewShowing.AsObservable() .AsDriver(schedulerProvider); SwipeActionsEnabled = userPreferences.SwipeActionsEnabled .AsDriver(schedulerProvider); OpenCalendarSettings = rxActionFactory.FromAsync(openCalendarSettings); OpenCalendarSmartReminders = rxActionFactory.FromAsync(openCalendarSmartReminders); OpenNotificationSettings = rxActionFactory.FromAsync(openNotificationSettings); ToggleTwentyFourHourSettings = rxActionFactory.FromAsync(toggleUseTwentyFourHourClock); OpenHelpView = rxActionFactory.FromAsync(openHelpView); TryLogout = rxActionFactory.FromAsync(tryLogout); OpenAboutView = rxActionFactory.FromAsync(openAboutView); OpenSiriShortcuts = rxActionFactory.FromAsync(openSiriShorcuts); OpenSiriWorkflows = rxActionFactory.FromAsync(openSiriWorkflows); SubmitFeedback = rxActionFactory.FromAsync(submitFeedback); SelectDateFormat = rxActionFactory.FromAsync(selectDateFormat); PickDefaultWorkspace = rxActionFactory.FromAsync(pickDefaultWorkspace); SelectDurationFormat = rxActionFactory.FromAsync(selectDurationFormat); SelectBeginningOfWeek = rxActionFactory.FromAsync(selectBeginningOfWeek); ToggleTimeEntriesGrouping = rxActionFactory.FromAsync(toggleTimeEntriesGrouping); ToggleManualMode = rxActionFactory.FromAction(toggleManualMode); ToggleSwipeActions = rxActionFactory.FromAction(toggleSwipeActions); }
private void updateFromPreferences(IThreadSafePreferences preferences) { DateFormat = preferences.DateFormat; DurationFormat = preferences.DurationFormat; UseTwentyFourHourClock = preferences.TimeOfDayFormat.IsTwentyFourHoursFormat; }