public MainViewModel() { _logger.Info($"Starting AudibleBookmarks {TitleProvider.GetTitleWithVersion()}"); ISubscribable fileSvc = new FileDialogService(); fileSvc.StartListening(); ISubscribable alertSvc = new AlertService(); alertSvc.StartListening(); _dbService = new DatabaseService(); Books = new ObservableCollection <Book>(); Bookmarks = new ObservableCollection <Bookmark>(); FilterableBooks = CollectionViewSource.GetDefaultView(Books); FilterableBooks.Filter = FilterBooks; FilterableBookmarks = CollectionViewSource.GetDefaultView(Bookmarks); FilterableBookmarks.Filter = FilterBookmarks; if (!DesignerProperties.GetIsInDesignMode(new DependencyObject())) { FileOpened(PathHelper.TryToGuessPathToLibrary()); } }
public MainWindowViewModel() { ISubscribable fileSvc = new FileDialogService(); fileSvc.StartListening(); ISubscribable alertSvc = new AlertService(); alertSvc.StartListening(); _dbService = new DatabaseService(); Books = new ReactiveList <BookWrapper>(); Bookmarks = new ReactiveList <Bookmark>(); FilterableBooks = Books.CreateDerivedCollection(b => b, FilterBooks); FilterableBookmarks = Bookmarks.CreateDerivedCollection(b => b, FilterBookmarks); var observableSelectedBook = this.WhenAnyValue(x => x.SelectedBook); observableSelectedBook.Subscribe(b => { if (b == null) { return; } LoadChapters(b); LoadBookmarks(b); }); _totalBookmarkCount = this.WhenAny( x => x.SelectedBook, x => x.Sender.Bookmarks.Count() ) .ToProperty(this, x => x.TotalBookmarkCount); _emptyBookmarkCount = this.WhenAny( x => x.SelectedBook, x => x.Sender.Bookmarks.Count(bm => bm.IsEmptyBookmark) ) .ToProperty(this, x => x.EmptyBookmarkCount); _onlyTitleBookmarkCount = this.WhenAny( x => x.SelectedBook, x => x.Sender.Bookmarks.Count(bm => string.IsNullOrWhiteSpace(bm.Note) && !string.IsNullOrWhiteSpace(bm.Title)) ) .ToProperty(this, x => x.OnlyTitleBookmarkCount); _onlyNoteBookmarkCount = this.WhenAny( x => x.SelectedBook, x => x.Sender.Bookmarks.Count(bm => string.IsNullOrWhiteSpace(bm.Title) && !string.IsNullOrWhiteSpace(bm.Note)) ) .ToProperty(this, x => x.OnlyNoteBookmarkCount); FileOpened(PathHelper.TryToGuessPathToLibrary()); }