Пример #1
0
 public void Init(EpubBook book, EpubViewStyle style)
 {
     Book                = book;
     ViewStyle           = style;
     helper              = new HtmlHelper(book.Resources.Images.ToList(), style);
     helper.LinkTapped  += (_s, _e) => { LinkTapped?.Invoke(_s, _e); };
     helper.ImageTapped += (_s, _e) => { ImageTapped?.Invoke(_s, _e); };
 }
Пример #2
0
 protected override void OnApplyTemplate()
 {
     _contentContainer                 = GetTemplateChild("ContentContainer") as Grid;
     _readerView                       = GetTemplateChild("ReaderView") as ReaderView;
     _readerView.PrevPageSelected     += OnPrevPageSelected;
     _readerView.NextPageSelected     += OnNextPageSelected;
     _readerView.LoadingStatusChanged += OnLoad;
     _readerView.ProgressChanged      += OnProgressChanged;
     _readerView.TouchHolding         += OnTouchHolding;
     _readerView.TouchTapped          += (_s, _e) => { TouchTapped?.Invoke(_s, _e); };
     _readerView.Loaded               += (_s, _e) =>
     {
         _readerView.SingleColumnMaxWidth = SingleColumnMaxWidth;
         _readerView.ReaderFlyout         = ReaderFlyout;
         ViewLoaded?.Invoke(this, EventArgs.Empty);
     };
     _readerView.LinkTapped  += (_s, _e) => { LinkTapped?.Invoke(this, _e); };
     _readerView.ImageTapped += (_s, _e) => { ImageTapped?.Invoke(this, _e); };
     _rootGrid = GetTemplateChild("RootGrid") as Grid;
     base.OnApplyTemplate();
 }
Пример #3
0
        /// <summary>
        /// 打开书籍文件
        /// </summary>
        /// <param name="bookFile">书籍文件</param>
        /// <param name="style">阅读器样式</param>
        /// <returns></returns>
        public async Task OpenAsync(StorageFile bookFile, ReaderStyle style)
        {
            if (bookFile == null)
            {
                throw new ArgumentNullException();
            }

            string extension = Path.GetExtension(bookFile.Path).ToLower();

            if (extension != ".epub" && extension != ".txt")
            {
                throw new NotSupportedException("File type not support (Currently only support txt and epub file)");
            }
            OpenStarting?.Invoke(this, EventArgs.Empty);
            if (extension == ".txt")
            {
                if (!(style is TxtViewStyle))
                {
                    throw new ArgumentException("Open txt file need TxtViewStyle argument");
                }
                ReaderType = Enums.ReaderType.Txt;
                Chapters   = await GetTxtChapters(bookFile);

                ChapterLoaded?.Invoke(this, Chapters);
                if (_mainPresenter.Content == null || !(_mainPresenter.Content is TxtView))
                {
                    if (_txtView == null)
                    {
                        _txtView = new TxtView();
                        _txtView.PrevPageSelected     += OnPrevPageSelected;
                        _txtView.NextPageSelected     += OnNextPageSelected;
                        _txtView.LoadingStatusChanged += OnLoad;
                        _txtView.ProgressChanged      += OnProgressChanged;
                        _txtView.TouchHolding         += OnTouchHolding;
                        _txtView.TouchTapped          += (_s, _e) => { TouchTapped?.Invoke(_s, _e); };
                        _txtView.Loaded += (_s, _e) =>
                        {
                            _txtView.SingleColumnMaxWidth = SingleColumnMaxWidth;
                            _txtView.ReaderFlyout         = ReaderFlyout;
                            ViewLoaded?.Invoke(this, EventArgs.Empty);
                        };
                    }
                    _mainPresenter.Content = _txtView;
                }
                _txtContent = await GetTxtContent(bookFile);

                _txtView.ViewStyle = style as TxtViewStyle;
            }
            else
            {
                if (!(style is EpubViewStyle))
                {
                    throw new ArgumentException("Open epub file need EpubViewStyle argument");
                }
                ReaderType   = Enums.ReaderType.Epub;
                _epubContent = await EpubReader.Read(bookFile, Encoding.Default);

                Chapters = GetEpubChapters(_epubContent);
                ChapterLoaded?.Invoke(this, Chapters);
                if (_mainPresenter.Content == null || !(_mainPresenter.Content is EpubView))
                {
                    if (_epubView == null)
                    {
                        _epubView = new EpubView();
                        _epubView.PrevPageSelected     += OnPrevPageSelected;
                        _epubView.NextPageSelected     += OnNextPageSelected;
                        _epubView.LoadingStatusChanged += OnLoad;
                        _epubView.ProgressChanged      += OnProgressChanged;
                        _epubView.TouchHolding         += OnTouchHolding;
                        _epubView.TouchTapped          += (_s, _e) => { TouchTapped?.Invoke(_s, _e); };
                        _epubView.Loaded += (_s, _e) =>
                        {
                            _epubView.SingleColumnMaxWidth = SingleColumnMaxWidth;
                            _epubView.ReaderFlyout         = ReaderFlyout;
                            ViewLoaded?.Invoke(this, EventArgs.Empty);
                        };
                        _epubView.LinkTapped  += (_s, _e) => { LinkTapped?.Invoke(this, _e); };
                        _epubView.ImageTapped += (_s, _e) => { ImageTapped?.Invoke(this, _e); };
                    }

                    _mainPresenter.Content = _epubView;
                }
                _epubView.Init(_epubContent, style as EpubViewStyle);
            }
            OpenCompleted?.Invoke(this, EventArgs.Empty);
        }