コード例 #1
0
ファイル: MainViewModel.cs プロジェクト: xleon/mobileapp
        public override async Task Initialize()
        {
            await base.Initialize();

            interactorFactory.GetCurrentUser().Execute()
            .Select(u => u.Id)
            .Subscribe(analyticsService.SetAppCenterUserId);

            await SuggestionsViewModel.Initialize();

            await RatingViewModel.Initialize();

            widgetsService.Start();

            SyncProgressState = syncManager.ProgressObservable
                                .AsDriver(schedulerProvider);

            var isWelcome = OnboardingStorage.IsNewUser;

            var noTimeEntries = Observable
                                .CombineLatest(TimeEntriesViewModel.Empty, SuggestionsViewModel.IsEmpty,
                                               (isTimeEntryEmpty, isSuggestionEmpty) => isTimeEntryEmpty && isSuggestionEmpty)
                                .DistinctUntilChanged();

            ShouldShowEmptyState = ObservableAddons.CombineLatestAll(
                isWelcome,
                noTimeEntries
                )
                                   .DistinctUntilChanged()
                                   .AsDriver(schedulerProvider);

            ShouldShowWelcomeBack = ObservableAddons.CombineLatestAll(
                isWelcome.Select(b => !b),
                noTimeEntries
                )
                                    .StartWith(false)
                                    .DistinctUntilChanged()
                                    .AsDriver(schedulerProvider);

            IsInManualMode = userPreferences
                             .IsManualModeEnabledObservable
                             .AsDriver(schedulerProvider);

            ShouldShowRunningTimeEntryNotification = userPreferences.AreRunningTimerNotificationsEnabledObservable;
            ShouldShowStoppedTimeEntryNotification = userPreferences.AreStoppedTimerNotificationsEnabledObservable;

            CurrentRunningTimeEntry = dataSource.TimeEntries
                                      .CurrentlyRunningTimeEntry
                                      .AsDriver(schedulerProvider);

            IsTimeEntryRunning = dataSource.TimeEntries
                                 .CurrentlyRunningTimeEntry
                                 .Select(te => te != null)
                                 .DistinctUntilChanged()
                                 .AsDriver(schedulerProvider);

            var durationObservable = dataSource
                                     .Preferences
                                     .Current
                                     .Select(preferences => preferences.DurationFormat);

            ElapsedTime = TimeService
                          .CurrentDateTimeObservable
                          .CombineLatest(CurrentRunningTimeEntry, (now, te) => (now - te?.Start) ?? TimeSpan.Zero)
                          .CombineLatest(durationObservable, (duration, format) => duration.ToFormattedString(format))
                          .AsDriver(schedulerProvider);

            NumberOfSyncFailures = interactorFactory
                                   .GetItemsThatFailedToSync()
                                   .Execute()
                                   .Select(i => i.Count())
                                   .AsDriver(schedulerProvider);

            ShouldReloadTimeEntryLog = Observable.Merge(
                TimeService.MidnightObservable.SelectUnit(),
                TimeService.SignificantTimeChangeObservable.SelectUnit())
                                       .AsDriver(schedulerProvider);

            Refresh           = rxActionFactory.FromAsync(refresh);
            OpenSettings      = rxActionFactory.FromAsync(openSettings);
            OpenSyncFailures  = rxActionFactory.FromAsync(openSyncFailures);
            SelectTimeEntry   = rxActionFactory.FromAsync <EditTimeEntryInfo>(timeEntrySelected);
            ContinueTimeEntry = rxActionFactory.FromObservable <ContinueTimeEntryInfo, IThreadSafeTimeEntry>(continueTimeEntry);
            StartTimeEntry    = rxActionFactory.FromAsync <bool>(startTimeEntry, IsTimeEntryRunning.Invert());
            StopTimeEntry     = rxActionFactory.FromObservable <TimeEntryStopOrigin>(stopTimeEntry, IsTimeEntryRunning);

            ShouldShowRatingView = Observable.Merge(
                ratingViewExperiment.RatingViewShouldBeVisible,
                RatingViewModel.HideRatingView.SelectValue(false),
                hideRatingView.AsObservable().SelectValue(false)
                )
                                   .Select(canPresentRating)
                                   .DistinctUntilChanged()
                                   .Do(trackRatingViewPresentation)
                                   .AsDriver(schedulerProvider);

            OnboardingStorage.StopButtonWasTappedBefore
            .Subscribe(hasBeen => hasStopButtonEverBeenUsed = hasBeen)
            .DisposedBy(disposeBag);

            if (platformInfo.Platform == Platform.Giskard)
            {
                analyticsService.ApplicationInstallLocation.Track(platformInfo.InstallLocation);
            }

            SyncProgressState
            .Subscribe(postAccessibilityAnnouncementAboutSync)
            .DisposedBy(disposeBag);
        }
コード例 #2
0
ファイル: MainViewModel.cs プロジェクト: xleon/mobileapp
        public MainViewModel(
            ITogglDataSource dataSource,
            ISyncManager syncManager,
            ITimeService timeService,
            IRatingService ratingService,
            IUserPreferences userPreferences,
            IAnalyticsService analyticsService,
            IOnboardingStorage onboardingStorage,
            IInteractorFactory interactorFactory,
            INavigationService navigationService,
            IRemoteConfigService remoteConfigService,
            IAccessibilityService accessibilityService,
            IUpdateRemoteConfigCacheService updateRemoteConfigCacheService,
            IAccessRestrictionStorage accessRestrictionStorage,
            ISchedulerProvider schedulerProvider,
            IRxActionFactory rxActionFactory,
            IPermissionsChecker permissionsChecker,
            IBackgroundService backgroundService,
            IPlatformInfo platformInfo,
            IWidgetsService widgetsService)
            : base(navigationService)
        {
            Ensure.Argument.IsNotNull(dataSource, nameof(dataSource));
            Ensure.Argument.IsNotNull(syncManager, nameof(syncManager));
            Ensure.Argument.IsNotNull(timeService, nameof(timeService));
            Ensure.Argument.IsNotNull(ratingService, nameof(ratingService));
            Ensure.Argument.IsNotNull(userPreferences, nameof(userPreferences));
            Ensure.Argument.IsNotNull(analyticsService, nameof(analyticsService));
            Ensure.Argument.IsNotNull(interactorFactory, nameof(interactorFactory));
            Ensure.Argument.IsNotNull(onboardingStorage, nameof(onboardingStorage));
            Ensure.Argument.IsNotNull(schedulerProvider, nameof(schedulerProvider));
            Ensure.Argument.IsNotNull(remoteConfigService, nameof(remoteConfigService));
            Ensure.Argument.IsNotNull(accessibilityService, nameof(accessibilityService));
            Ensure.Argument.IsNotNull(updateRemoteConfigCacheService, nameof(updateRemoteConfigCacheService));
            Ensure.Argument.IsNotNull(accessRestrictionStorage, nameof(accessRestrictionStorage));
            Ensure.Argument.IsNotNull(rxActionFactory, nameof(rxActionFactory));
            Ensure.Argument.IsNotNull(permissionsChecker, nameof(permissionsChecker));
            Ensure.Argument.IsNotNull(backgroundService, nameof(backgroundService));
            Ensure.Argument.IsNotNull(platformInfo, nameof(platformInfo));
            Ensure.Argument.IsNotNull(widgetsService, nameof(widgetsService));

            this.dataSource               = dataSource;
            this.syncManager              = syncManager;
            this.platformInfo             = platformInfo;
            this.userPreferences          = userPreferences;
            this.rxActionFactory          = rxActionFactory;
            this.analyticsService         = analyticsService;
            this.interactorFactory        = interactorFactory;
            this.schedulerProvider        = schedulerProvider;
            this.accessibilityService     = accessibilityService;
            this.accessRestrictionStorage = accessRestrictionStorage;
            this.widgetsService           = widgetsService;

            TimeService       = timeService;
            OnboardingStorage = onboardingStorage;

            SuggestionsViewModel = new SuggestionsViewModel(interactorFactory, OnboardingStorage, schedulerProvider, rxActionFactory, analyticsService, timeService, permissionsChecker, navigationService, backgroundService, userPreferences, syncManager, widgetsService);
            RatingViewModel      = new RatingViewModel(timeService, ratingService, analyticsService, OnboardingStorage, navigationService, schedulerProvider, rxActionFactory);
            TimeEntriesViewModel = new TimeEntriesViewModel(dataSource, interactorFactory, analyticsService, schedulerProvider, rxActionFactory, timeService);

            TimeEntries = TimeEntriesViewModel.TimeEntries
                          .Throttle(TimeSpan.FromSeconds(throttlePeriodInSeconds))
                          .AsDriver(ImmutableList <MainLogSection> .Empty, schedulerProvider);

            LogEmpty         = TimeEntriesViewModel.Empty.AsDriver(schedulerProvider);
            TimeEntriesCount = TimeEntriesViewModel.Count.AsDriver(schedulerProvider);

            ratingViewExperiment = new RatingViewExperiment(timeService, dataSource, onboardingStorage, remoteConfigService, updateRemoteConfigCacheService);

            SwipeActionsEnabled = userPreferences.SwipeActionsEnabled.AsDriver(schedulerProvider);
        }