示例#1
0
        public async void LoadBook(Book book)
        {
            _bookshelfBook = book;
            _ebook         = await EbookFormatHelper.GetBookLoader(book.Format).OpenBook(book.Path);

            var position = _bookshelfBook.Position;

            QuickPanel.PanelContent.SetNavigation(_ebook.Navigation);
            this.RefreshBookmarks();

            var chapter           = _ebook.Spines.First();
            var positionInChapter = 0;

            if (position != null)
            {
                var loadedChapter = _ebook.Spines.ElementAt(position.Spine);
                if (loadedChapter != null)
                {
                    chapter           = loadedChapter;
                    positionInChapter = position.SpinePosition;
                }
            }

            this.SendChapter(chapter, position: positionInChapter);
        }
示例#2
0
        private async void SendChapter(EbookChapter chapter, int position = 0, bool lastPage = false, string marker = "")
        {
            _currentChapter      = _ebook.HtmlFiles.IndexOf(chapter);
            _bookshelfBook.Spine = _currentChapter;

            var html         = chapter.Content;
            var bookLoader   = EbookFormatHelper.GetBookLoader(_bookshelfBook.Format);
            var preparedHtml = await bookLoader.PrepareHtml(html, _ebook, chapter);

            Device.BeginInvokeOnMainThread(() => {
                SendHtml(preparedHtml, chapter.Title, position, lastPage, marker);
                SetStatusPanelValues(new Dictionary <StatusPanelItem, object>()
                {
                    { StatusPanelItem.BookTitle, _ebook.Title }, { StatusPanelItem.BookAuthor, _ebook.Author }
                });
            });

            await _ebook.Info.WaitForProcessingToFinish();

            Device.BeginInvokeOnMainThread(() =>
            {
                var(wordsBefore, wordsCurrent, wordsAfter) = _ebook.Info.GetWordCountsAround(chapter);
                var json = new JObject {
                    { "wordsBefore", wordsBefore }, { "wordsCurrent", wordsCurrent }, { "wordsAfter", wordsAfter }
                };
                WebView.Messages.Send("setChapterInfo", json);
            });
        }
示例#3
0
        public async Task LoadBook(BookInfo info)
        {
            await _loadingPopup.Show();

            _bookshelfBook          = info;
            _bookshelfBook.LastRead = DateTime.Now;
            _bookshelfBook.ReadStats.OpenedBook();
            var loader = EbookFormatHelper.GetBookLoader(info.Format);

            _ebook = await loader.OpenBook(info);

            var position = _bookshelfBook.Position;

            Title = _ebook.Title + " - " + _ebook.Author;

            var chapter           = _ebook.HtmlFiles.First();
            var positionInChapter = 0;

            if (position != null)
            {
                var loadedChapter = _ebook.HtmlFiles[position.Spine];
                if (loadedChapter != null)
                {
                    chapter           = loadedChapter;
                    positionInChapter = position.SpinePosition;
                }
            }

            SendChapter(chapter, positionInChapter);

            _chapterListPopup.SetBook(_ebook, _bookshelfBook);
        }
示例#4
0
        private async void SendChapter(Spine chapter, int position = 0, bool lastPage = false, string marker = "")
        {
            currentChapter       = _ebook.Spines.IndexOf(chapter);
            _bookshelfBook.Spine = currentChapter;

            var bookLoader = EbookFormatHelper.GetBookLoader(_bookshelfBook.Format);

            var html = await bookLoader.GetChapter(_ebook, chapter);

            var htmlResult = await bookLoader.PrepareHTML(html, _ebook, _ebook.Files.Where(o => o.Id == chapter.Idref).First());

            Device.BeginInvokeOnMainThread(() => {
                this.SendHtml(htmlResult, position, lastPage, marker);
            });
        }
示例#5
0
        public async Task <Tuple <Book, bool> > AddBook(FileData file)
        {
            var newBook    = false;
            var bookLoader = EbookFormatHelper.GetBookLoader(file.FileName);

            var id = _cryptoService.GetMd5(file.DataArray);

            var bookshelfBook = await _bookRepository.GetBookByIDAsync(id);

            if (bookshelfBook == null)
            {
                var ebook = await bookLoader.GetBook(file.FileName, file.DataArray, id);

                bookshelfBook    = bookLoader.CreateBookshelfBook(ebook);
                bookshelfBook.ID = id;
                await _bookRepository.SaveBookAsync(bookshelfBook);

                newBook = true;
            }

            return(new Tuple <Book, bool>(bookshelfBook, newBook));
        }
        public async Task <(BookInfo, bool)> AddBook(FileData file)
        {
            var newBook    = false;
            var bookLoader = EbookFormatHelper.GetBookLoader(file.FileName);

            var id = await _fileService.GetFileHash(file.FilePath);

            var bsBook = await _bookRepository.GetBookByIdAsync(id);

            if (bsBook == null)
            {
                var ebook = await bookLoader.OpenBook(file.FilePath);

                bsBook = ebook.Info;
                await bsBook.ExtractToTemp(_fileService, ebook);

                await _bookRepository.SaveBookAsync(bsBook);

                newBook = true;
            }

            return(bsBook, newBook);
        }