public BookViewModel(int bookId) { bookModel = new BookModel(); isLoading = true; currentHtmlContentFile = null; previousHtmlContentFile = null; nextHtmlContentFile = null; currentAnchor = null; navigateCommand = null; previousCommand = null; nextCommand = null; bookModel.OpenBookAsync(bookId).ContinueWith(epubBook => BookOpened(epubBook), TaskScheduler.FromCurrentSynchronizationContext()); }
private void BookOpened(Task <EpubBook> task) { EpubBook epubBook = task.Result; Navigation = new ObservableCollection <NavigationItemViewModel>(bookModel.GetNavigation(epubBook)); ReadingOrder = new ObservableCollection <HtmlContentFileViewModel>(bookModel.GetReadingOrder(epubBook)); if (ReadingOrder.Any()) { CurrentHtmlContentFile = ReadingOrder.First(); if (ReadingOrder.Count > 1) { nextHtmlContentFile = ReadingOrder[1]; } } IsLoading = false; NotifyPropertyChanged(nameof(IsPreviousButtonVisible)); NotifyPropertyChanged(nameof(IsNextButtonVisible)); }
private void Navigate(HtmlContentFileViewModel targetHtmlContentFileViewModel) { if (targetHtmlContentFileViewModel == null) { CurrentHtmlContentFile = null; previousHtmlContentFile = null; nextHtmlContentFile = null; } else if (CurrentHtmlContentFile != targetHtmlContentFileViewModel) { CurrentHtmlContentFile = targetHtmlContentFileViewModel; int currentReadingOrderItemIndex = ReadingOrder.IndexOf(CurrentHtmlContentFile); if (currentReadingOrderItemIndex != -1) { if (currentReadingOrderItemIndex > 0) { previousHtmlContentFile = ReadingOrder[currentReadingOrderItemIndex - 1]; } else { previousHtmlContentFile = null; } if (currentReadingOrderItemIndex < ReadingOrder.Count - 1) { nextHtmlContentFile = ReadingOrder[currentReadingOrderItemIndex + 1]; } else { nextHtmlContentFile = null; } } else { previousHtmlContentFile = null; nextHtmlContentFile = null; } } NotifyPropertyChanged(nameof(IsPreviousButtonVisible)); NotifyPropertyChanged(nameof(IsNextButtonVisible)); }