Esempio n. 1
0
        public DirectoryViewModel(IScreen hostScreen, IDirectoryTools directoryTools)
        {
            this.directoryTools = directoryTools;
            HostScreen          = hostScreen;

            var sourceDirectory = Preferences.Get("sourceDirectory", string.Empty);

            subDirectories.DisposeWith(Disposables);

            SelectedDirectory = new DirectoryContent(Path.GetFileName(sourceDirectory), sourceDirectory);

            this.WhenAnyValue(vm => vm.SelectedDirectory)
            .Where(x => x != null)
            .Subscribe(directoryContent => SetDirectoryContent(directoryContent.FullPath))
            .DisposeWith(Disposables);

            subDirectoriesHelper = subDirectories.ToProperty(this, vm => vm.SubDirectories);
            subDirectoriesHelper.DisposeWith(Disposables);

            CmdSetSoureDirectory = ReactiveCommand.CreateFromTask(_ =>
            {
                Preferences.Set("sourceDirectory", SelectedDirectory.FullPath);

                HostScreen.Router.Navigate.Execute(new ScannedChatsViewModel(hostScreen, directoryTools))
                .Subscribe()
                .DisposeWith(Disposables);

                return(Task.FromResult(Unit.Default));
            })
                                   .SetupErrorHandling(Disposables);

            SetDirectoryContent(sourceDirectory);
        }
 public FileVersionListViewModel()
 {
     this._versionedFiles = _versionedFilesChanges.ToProperty(this, nameof(VersionedFiles));
 }
Esempio n. 3
0
        protected ToolViewModel(Guid toolId)
        {
            Pages  = _pages;
            ToolId = toolId;

            // Listen for the page count changing
            var currentWithCount = _pages.CountChanged
                                   .CombineLatest(_currentPageIndex, (count, current) =>
                                                  new { Count = count, Current = current })
                                   .Publish(); // We have multiple listenser, so publish the value (multicast)

            // Enable the next page command when the count is less than the total number of pages
            var nextPageCmd = new ReactiveCommand(currentWithCount.Select(t =>
                                                                          t.Current + 1 < t.Count &&
                                                                          t.Count > 1));

            // When the command is invoked, call GoToPage with the next page num.
            _nextPageSub = nextPageCmd
                           .RegisterAsyncAction(_ =>
                                                GoToPage(_currentPageIndex.Value + 1), // _currentPageIndex stores the current value
                                                Scheduler.Immediate)
                           .Subscribe();

            // Enable the preious page if current is greater than 0 and there's at least two pages
            var prevPageCmd = new ReactiveCommand(currentWithCount.Select(t =>
                                                                          t.Current > 0 &&
                                                                          t.Count > 1));

            // When the command is invoked, call GoToPage with the previous index
            _prevPageSub = prevPageCmd
                           .RegisterAsyncAction(_ =>
                                                GoToPage(_currentPageIndex.Value - 1), // _currentPageIndex stores the current value
                                                Scheduler.Immediate)
                           .Subscribe();

            NextPageCommand     = nextPageCmd;
            PreviousPageCommand = prevPageCmd;

            // When the current index changes, get the current tool and expose it as a property
            // As pages flow through,
            _currentPageIndex
            .Select(i => i >= 0 ? _pages[i] : (IToolPage)null)
            .DistinctUntilChanged()
            .Scan((prev, current) =>
            {
                if (prev != null)
                {
                    prev.OnNavigatedAway();
                }
                if (current != null)
                {
                    current.OnNavigatedTo();
                }

                // This element will become prev on the next pass
                return(current);
            })
            .ToProperty(this, tvm => tvm.CurrentPage, out _currentPage);

            // Expose the current page index as a property
            _currentPageIndex.ToProperty(this, tvm => tvm.CurrentPageNumber, out _currentPageNumber);



            // Once all of our listeners are attached, turn on the stream
            _currentSub = currentWithCount.Connect();
        }