예제 #1
0
        public void OnNextPageSelected(object sender, EventArgs args)
        {
            int index = CurrentChapter.Index;

            if (index >= Chapters.Count || Chapters.Count == 0 || _isLoading)
            {
                return;
            }
            var next = Chapters.Where(p => p.Index == index + 1).FirstOrDefault();

            if (next == null)
            {
                return;
            }
            if (ReaderType == ReaderType.Txt)
            {
                string content = string.Empty;
                if (next.Index == Chapters.Count - 1)
                {
                    content = _txtContent.Substring(next.StartLength);
                }
                else
                {
                    content = _txtContent.Substring(next.StartLength, Chapters[next.Index + 1].StartLength - next.StartLength);
                }
                _txtView.SetContent(content, ReaderStartMode.First);
            }
            else if (ReaderType == ReaderType.Custom)
            {
                var detail = CustomChapterDetailList.Where(p => p.Index == next.Index).FirstOrDefault();
                if (detail != null)
                {
                    _txtView.SetContent(detail.Content, ReaderStartMode.First);
                }
                else
                {
                    CustomContentRequest?.Invoke(this, new CustomRequestEventArgs(ReaderStartMode.First, next));
                }
            }
            else
            {
                var orders = _epubContent.SpecialResources.HtmlInReadingOrder;
                if (_tempEpubChapterIndex > orders.Count - 2)
                {
                    return;
                }
                _tempEpubChapterIndex += 1;
                var nextOrder = orders[_tempEpubChapterIndex];
                next = GetLastEpubChapter(nextOrder);
                string content = nextOrder?.TextContent ?? next.Title;
                _epubView.SetContent(content, ReaderStartMode.First);
            }

            if (!next.Equals(CurrentChapter))
            {
                CurrentChapter = next;
                ChapterChanged?.Invoke(this, next);
            }
        }
예제 #2
0
        public void OnPrevPageSelected(object sender, EventArgs args)
        {
            if (CurrentChapter == null)
            {
                return;
            }
            int index = CurrentChapter.Index;

            if (index < 1 || Chapters.Count == 0 || _isLoading)
            {
                return;
            }
            var prev = Chapters.Where(p => p.Index == index - 1).FirstOrDefault();

            if (prev == null)
            {
                return;
            }
            if (ReaderType == ReaderType.Txt)
            {
                string content = _txtContent.Substring(prev.StartLength, CurrentChapter.StartLength - prev.StartLength);
                _readerView.SetContent(content, ReaderStartMode.Last);
            }
            else if (ReaderType == ReaderType.Custom)
            {
                var detail = CustomChapterDetailList.Where(p => p.Index == prev.Index).FirstOrDefault();
                if (detail != null)
                {
                    _readerView.SetContent(detail.GetReadContent(), ReaderStartMode.Last);
                }
                else
                {
                    CustomContentRequest?.Invoke(this, new CustomRequestEventArgs(ReaderStartMode.Last, prev));
                }
            }
            else
            {
                var orders = _epubContent.SpecialResources.HtmlInReadingOrder;
                if (_tempEpubChapterIndex < 1)
                {
                    return;
                }
                _tempEpubChapterIndex -= 1;
                var prevOrder = orders[_tempEpubChapterIndex];
                prev = GetLastEpubChapter(prevOrder);
                string content = prevOrder?.TextContent ?? prev.Title;
                _readerView.SetContent(content, ReaderStartMode.Last);
            }

            if (!prev.Equals(CurrentChapter))
            {
                CurrentChapter = prev;
                ChapterChanged?.Invoke(this, prev);
            }
        }
예제 #3
0
 private void SetProgress(Chapter chapter, int addonLength = 0)
 {
     if (Chapters == null || Chapters.Count == 0 || !Chapters.Any(p => p.Equals(chapter)))
     {
         throw new ArgumentOutOfRangeException("The chapter list don't have this chapter");
     }
     if (chapter != CurrentChapter)
     {
         ChapterChanged?.Invoke(this, chapter);
     }
     CurrentChapter = Chapters.Where(p => p.Equals(chapter)).FirstOrDefault();
     if (ReaderType == Enums.ReaderType.Txt)
     {
         int    nextIndex = CurrentChapter.Index + 1;
         string content   = "";
         if (nextIndex >= Chapters.Count)
         {
             content = _txtContent.Substring(CurrentChapter.StartLength);
         }
         else
         {
             content = _txtContent.Substring(CurrentChapter.StartLength, Chapters[nextIndex].StartLength - CurrentChapter.StartLength);
         }
         _readerView.SetContent(content, Enums.ReaderStartMode.First, addonLength);
     }
     else if (ReaderType == Enums.ReaderType.Custom)
     {
         var detail = CustomChapterDetailList.Where(p => p.Index == CurrentChapter.Index).FirstOrDefault();
         if (detail != null)
         {
             _readerView.SetContent(detail.GetReadContent(), Enums.ReaderStartMode.First, addonLength);
         }
         else
         {
             CustomContentRequest?.Invoke(this, new CustomRequestEventArgs(Enums.ReaderStartMode.First, CurrentChapter, addonLength));
         }
     }
     else
     {
         var    info    = _epubContent.SpecialResources.HtmlInReadingOrder.Where(p => p.AbsolutePath.Equals(chapter.Link, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
         string content = string.Empty;
         if (info != null)
         {
             content = info.TextContent;
             _tempEpubChapterIndex = _epubContent.SpecialResources.HtmlInReadingOrder.IndexOf(info);
         }
         else
         {
             content = chapter.Title;
         }
         _readerView.SetContent(content, Enums.ReaderStartMode.First, addonLength);
     }
     RaiseProgressChanged(addonLength);
 }
예제 #4
0
        /// <summary>
        /// 定位到指定文件名的章节(EPUB)
        /// </summary>
        /// <param name="fileName"></param>
        public async void LocateToSpecificFile(string fileName)
        {
            if (ReaderType != Enums.ReaderType.Epub)
            {
                throw new NotSupportedException("This method can only use in epub view");
            }
            else if (_readerView == null)
            {
                throw new InvalidOperationException("Epub view not loaded");
            }
            else if (_epubContent == null)
            {
                throw new InvalidOperationException("Epub content not loaded");
            }
            else if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException("Invalid file name");
            }

            var    orders  = _epubContent.SpecialResources.HtmlInReadingOrder;
            var    info    = orders.Where(p => p.AbsolutePath.Contains(fileName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
            string content = string.Empty;

            if (info != null)
            {
                content = info.TextContent;
                _tempEpubChapterIndex = orders.IndexOf(info);
            }
            else
            {
                throw new FileNotFoundException("File not found");
            }
            await _readerView.SetContent(content, Enums.ReaderStartMode.First, 0);

            var chapter = GetLastEpubChapter(info);

            if (!chapter.Equals(CurrentChapter))
            {
                CurrentChapter = chapter;
                ChapterChanged?.Invoke(this, chapter);
                RaiseProgressChanged(0);
            }
        }
 public void OnMediaPlayerChapterChanged(int newChapter)
 {
     ChapterChanged?.Invoke(this, new VlcMediaPlayerChapterChangedEventArgs(newChapter));
 }