Exemplo n.º 1
0
        public void ResetDownloadPanel()
        {
            var book = DataContext as BookData;

            // Set up the uiDownload combo box
            uiDownloadList.Items.Clear();
            // Get a subset of the offered items -- we don't need to see multiple
            // text files with different character sets when we already have just
            // the one we need.
            var list = FilenameAndFormatData.GetProcessedFileList(book.Files.ToList());

            foreach (var file in list)
            {
                var cbi = new ComboBoxItem()
                {
                    Content = file.FileTypeAsString(),
                    Tag     = file
                };
                uiDownloadList.Items.Add(cbi);
            }
            if (uiDownloadList.Items.Count > 0)
            {
                uiDownloadList.SelectedIndex = 0;
            }

            var bookdb     = BookDataContext.Get();
            var dd         = CommonQueries.DownloadedBookFind(bookdb, book.BookId);
            var fileStatus = dd?.CurrFileStatus ?? DownloadData.FileStatus.Unknown;

            switch (fileStatus)
            {
            case DownloadData.FileStatus.Unknown:
            case DownloadData.FileStatus.Deleted:
                AllowEnableDownloadPanel = true;
                break;

            case DownloadData.FileStatus.Downloaded:
                AllowEnableDownloadPanel = false;
                break;
            }
            uiDownloadButton.Visibility        = Visibility.Visible;
            uiCancelDownloadButton.Visibility  = Visibility.Collapsed;
            uiDownloadProgress.IsIndeterminate = false;
            uiDownloadProgress.Value           = 0;

            uiDownloadFinished.Visibility = Visibility.Collapsed;
        }
Exemplo n.º 2
0
        private void OnCardTapped(object sender, TappedRoutedEventArgs e)
        {
            var bookdb = BookDataContext.Get();
            var book   = (sender as BookCard)?.DataContext as BookData;

            if (book == null)
            {
                return;
            }
            var dd = CommonQueries.DownloadedBookFind(bookdb, book.BookId);

            if (dd == null)
            {
                return;             // Can't display a book that isn't there!
            }
            var nav = Navigator.Get();

            nav.DisplayBook(ControlId, book);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Called externally in order to display a book; will use the BookNavigationData to move
        /// to the previous spot.
        /// </summary>
        /// <param name="bookId"></param>
        /// <returns></returns>
        public async Task DisplayBook(BookData bookData, BookLocation location = null)
        {
            // Reset all of the position values.
            CurrHtml           = "";
            CurrHtmlIndex      = -1;
            CurrHtmlFileName   = null;
            CurrScrollPosition = double.NaN;
            CurrSelectPosition = double.NaN;

            BookData = bookData;
            var bookdb = BookDataContext.Get();
            var dd     = bookData.DownloadData ?? CommonQueries.DownloadedBookFind(bookdb, BookData.BookId);
            var nav    = bookData.NavigationData ?? CommonQueries.BookNavigationDataFind(bookdb, BookData.BookId);

            if (location == null && !string.IsNullOrEmpty(nav?.CurrSpot))
            {
                location = BookLocation.FromJson(nav.CurrSpot);
            }
            SetReviewSymbol();

            if (dd == null)
            {
                return;
            }
            var fullpath = dd.FullFilePath;

            if (fullpath.Contains(@"\source\repos\SimpleEpubReader\SimpleEpubReader\bin\x64\Debug\AppX\Assets\PreinstalledBooks"))
            {
                // Whoops. The initial database might incorrectly have a developer path hard-coded.
                // Replace with correct location.
                var installationFolder = FolderMethods.InstallationFolder;
                fullpath = $"{installationFolder}\\Assets\\PreinstalledBooks\\{dd.FileName}";
            }
            else if (fullpath.StartsWith("PreinstalledBooks:"))
            {
                // Preinstalled books are in a sort of relative path. It's designed to be an invalid
                // (or at least incredibly rare) directory.
                var installationFolder = FolderMethods.InstallationFolder;
                fullpath = $"{installationFolder}\\Assets\\PreinstalledBooks\\{dd.FileName}";
            }
            var openResult = await OpenFile(fullpath, location);

            switch (openResult)
            {
            case OpenResult.OK:
                // Set up the uiAllUpPosition
                var sectionSizes = new List <double>();
                foreach (var file in EpubBook.ResourcesHtmlOrdered)
                {
                    sectionSizes.Add(file.Content.Length);
                }
                uiAllUpPosition.SetSectionSizes(sectionSizes);
                // No need to set to zero; it's already set in the OpenFile!. uiAllUpPosition.UpdatePosition(0, 0); // set to zero!

                ApplicationView appView = ApplicationView.GetForCurrentView();
                appView.Title = bookData.Title.Replace("\n", " -- ");     // title is multi-line
                break;

            case OpenResult.RedownloadableError:                     // An error. Mark the book as not downloaded + redownload
                dd.CurrFileStatus = DownloadData.FileStatus.Unknown; // deleted? gone? corrupt? we really don't know.
                CommonQueries.BookSaveChanges(bookdb);
                await BookSearch.DoSwipeDownloadOrReadAsync(BookData);

                break;

            default:                                                 // An error. Mark the book as not downloaded
                dd.CurrFileStatus = DownloadData.FileStatus.Unknown; // deleted? gone? corrupt? we really don't know.
                CommonQueries.BookSaveChanges(bookdb);
                break;
            }
        }