Example #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);
            }
        }
Example #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);
            }
        }
Example #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);
 }
Example #4
0
        private string GetChapterText(Chapter chapter)
        {
            string content = "";

            if (ReaderType == Enums.ReaderType.Txt)
            {
                int nextIndex = chapter.Index + 1;
                if (nextIndex >= Chapters.Count)
                {
                    content = _txtContent.Substring(chapter.StartLength);
                }
                else
                {
                    content = _txtContent.Substring(chapter.StartLength, Chapters[nextIndex].StartLength - chapter.StartLength);
                }
            }
            else if (ReaderType == Enums.ReaderType.Custom)
            {
                var detail = CustomChapterDetailList.Where(p => p.Index == chapter.Index).FirstOrDefault();
                if (detail != null)
                {
                    content = detail.GetReadContent();
                }
            }
            else
            {
                var info = _epubContent.SpecialResources.HtmlInReadingOrder.Where(p => p.AbsolutePath.Equals(chapter.Link, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                if (info != null)
                {
                    content = info.TextContent;
                }
                else
                {
                    content = chapter.Title;
                }
            }
            return(content);
        }