using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Windows.Media.Imaging; namespace BookReader { internal class BaseBook : IBook { #region -----------------constructors----------------- public BaseBook() { } public BaseBook(string filePath) { _filePath = filePath; RaisePropetyChanged("FilePath"); RaisePropetyChanged("FileName"); } #endregion #region -----------------properties----------------- private ImageCache _Cache = new ImageCache(); public ImageCache Cache { get { if (_Cache == null) _Cache = new ImageCache(); return _Cache; } set { _Cache = value; } } private string _filePath = string.Empty; public string FilePath { get { return _filePath; } set { _filePath = value; } } [NonSerialized()] private IBookItem _CurrentPage = null; public IBookItem CurrentPage { get { return _CurrentPage; } set { _CurrentPage = value; } } private List<IBookItem> _Pages = new List<IBookItem>(); public List<IBookItem> Pages { get { if (_Pages == null) _Pages = new List<IBookItem>(); return _Pages; } set { _Pages = value; } } private string _Bookmark = string.Empty; public string Bookmark { get { return _Bookmark; } set { _Bookmark = value; RaisePropetyChanged("Bookmark"); } } private bool _IsRead= false; public bool IsRead { get { return _IsRead; } set { _IsRead = value; RaisePropetyChanged("IsRead"); } } private BitmapImage _Cover = null; public BitmapImage Cover { get { return _Cover; } set { _Cover = value; RaisePropetyChanged("Cover"); } } public string FileName { get { return Path.GetFileName(this._filePath); } } private int _NbPages; public int NbPages { get { return _NbPages; } set { _NbPages = value; } } private long _Size; public long Size { get { return _Size; } set { _Size = value; } } #endregion #region -----------------loading/unloading----------------- virtual public void Load() { _CurrentPage = Pages[0]; } virtual public void UnLoad() { Pages.Clear(); Cache.Clear(); } #endregion #region -----------------virtual's----------------- virtual public BitmapImage GetCurrentPageImage() { throw new NotSupportedException(); } #endregion #region -----------------bookmark----------------- public void SetMark() { Bookmark = _CurrentPage.FilePath; } public void GotoMark() { if (!string.IsNullOrEmpty(_Bookmark)) { foreach (IBookItem pg in Pages) { if( pg.FilePath == _Bookmark ) _CurrentPage = pg; } } } #endregion #region -----------------page navigation management----------------- public bool GotoPage( IBookItem page ) { foreach (IBookItem pg in Pages) { if (pg == page) { _CurrentPage = pg; return true; } } return false; } public bool GotoNextPage() { int next = Pages.IndexOf(_CurrentPage); if (next >= Pages.Count-1) return false; else { next = next + 1; _CurrentPage = Pages[next]; return true; } } public bool GotoPreviousPage() { int next = Pages.IndexOf(_CurrentPage); if (next == 0) return false; else { next = next - 1; _CurrentPage = Pages[next]; return true; } } #endregion #region -----------------cache management----------------- internal IBookItem GetNextPage(IBookItem fromPage ) { int next = Pages.IndexOf(fromPage); if (next >= Pages.Count-1) return null; else { next = next + 1; return Pages[next]; } } virtual public void ManageCache() { Cache.ManageCache(); } #endregion #region -----------------INotifyPropertyChanged----------------- private void RaisePropetyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } public event PropertyChangedEventHandler PropertyChanged; #endregion } }
By viewing downloads associated with this article you agree to the Terms of use and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)
The Next Version of Android - Some of What's Coming