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); }