Esempio n. 1
0
        public TimeEntriesViewModel(
            ITogglDataSource dataSource,
            IInteractorFactory interactorFactory,
            IAnalyticsService analyticsService,
            ISchedulerProvider schedulerProvider,
            IRxActionFactory rxActionFactory,
            ITimeService timeService)
        {
            Ensure.Argument.IsNotNull(dataSource, nameof(dataSource));
            Ensure.Argument.IsNotNull(interactorFactory, nameof(interactorFactory));
            Ensure.Argument.IsNotNull(analyticsService, nameof(analyticsService));
            Ensure.Argument.IsNotNull(schedulerProvider, nameof(schedulerProvider));
            Ensure.Argument.IsNotNull(rxActionFactory, nameof(rxActionFactory));
            Ensure.Argument.IsNotNull(timeService, nameof(timeService));

            this.interactorFactory = interactorFactory;
            this.analyticsService  = analyticsService;
            this.schedulerProvider = schedulerProvider;

            DelayDeleteTimeEntries = rxActionFactory.FromAction <long[]>(delayDeleteTimeEntries);
            ToggleGroupExpansion   = rxActionFactory.FromAction <GroupId>(toggleGroupExpansion);
            CancelDeleteTimeEntry  = rxActionFactory.FromAction(cancelDeleteTimeEntry);

            groupsFlatteningStrategy = new TimeEntriesGroupsFlattening(timeService);

            var deletingOrPressingUndo = timeEntriesPendingDeletionSubject.SelectUnit();
            var collapsingOrExpanding  = ToggleGroupExpansion.Elements;

            var visibleTimeEntries = interactorFactory.ObserveAllTimeEntriesVisibleToTheUser().Execute()
                                     .Select(timeEntries => timeEntries.Where(isNotRunning))
                                     .ReemitWhen(deletingOrPressingUndo)
                                     .Select(timeEntries => timeEntries.Where(isNotDeleted))
                                     .Select(group)
                                     .ReemitWhen(collapsingOrExpanding);

            TimeEntries = Observable.CombineLatest(
                visibleTimeEntries,
                dataSource.Preferences.Current,
                groupsFlatteningStrategy.Flatten)
                          .AsDriver(schedulerProvider);

            Empty = TimeEntries
                    .Select(groups => groups.None())
                    .AsDriver(schedulerProvider);

            Count = TimeEntries
                    .Select(log => log.Sum(day => day.Items.Count))
                    .AsDriver(schedulerProvider);

            TimeEntriesPendingDeletion = timeEntriesPendingDeletionSubject.AsObservable().AsDriver(schedulerProvider);
        }
        public void TransformsTimeEntriesIntoACorrectTree(
            DurationFormat durationFormat,
            IEnumerable <IGrouping <DateTime, IThreadSafeTimeEntry> > log,
            HashSet <GroupId> expandedGroups,
            params AnimatableSectionModel <DaySummaryViewModel, LogItemViewModel, IMainLogKey>[] expectedTree)
        {
            var preferences =
                new MockPreferences
            {
                CollapseTimeEntries = true,
                DateFormat          = DateFormat.FromLocalizedDateFormat("YYYY-MM-DD"),
                DurationFormat      = durationFormat
            };

            var collapsingStrategy = new TimeEntriesGroupsFlattening(timeService);

            expandedGroups.ForEach(collapsingStrategy.ToggleGroupExpansion);

            var actualTree = collapsingStrategy.Flatten(log, preferences);

            actualTree.Should().BeEquivalentTo(expectedTree);
        }