I am implementing an ebook reader for android. I have done the pagination part successfully. But it takes a long time to load the book. what I did was, get the raw html and break into chapters and store them in a array. Then get the entire string and using Html.fromHtml I removed the html tags (because I am using view pager and need to get the no of pages, for this reason we need to remove the unnecessary strings first). Then according to this answer I am breaking into pages. (The logic was to get a sub string and check the string height is greater than the screen height, I am checking this condition at every space in the string).
I have used epub-lib library and jsoup for this project. I am using dynamic textviews and Imageviews for this.
Now I need to optimize this process. How to do this? My idea is to load and show the initial pages to users and while the user going through them the rest of the content should be paginated and loaded using a background process.
Is this possible? I am happy to get any other suggestions as well.
Thanks
Yes that should be possible. I had a similar situation where I had a ListView that potentially listed thousands of items from a database. Instead of loading everything, I simply read the first 9 items, displayed them and then had a listener for when the scrolling had reached the bottom of the list and then updated my listview to include the next 9 items.
Also, from a performance perspective, if your book is very large, I'd suggest doing that sort of parsing work immediately after you've downloaded the file in an AsyncTask
. I would break down the pages of the book into different objects (i.e. page 1, 2, 3 in a "page" object) and then when you need to display that page, you simply read and display that object. This would also be beneficial if the user opens the ebook multiple times, as you won't have to parse the entire html file again each time that ebook is opened.
The logic would be as follows: