Comments (5)
Hi,
There is no way to calculate number of sections without actually finish reading the book. The whole book is not calculated and held in memory, which is the purpose of the library: reducing memory consumption.
Though you can still use viewpager; by setting the page count of adapter to max at the beginning, when you get OutOfPagesException from reader class' readSection method, you can just update the page count and call notifyDataSetChanged on adapter.
Check EpubParser-Sample-Android-Application out for more info.
from epubparser.
This is my soulution for Android. I have added this code to Reader class.
public int loadPageCount(Context context) {
System.out.println("loadPageCount");
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
if (!sharedPreferences.contains("PAGE_NUM-" + content.getZipFilePath()))
savePageCount(context, designatePageCount(context));
return sharedPreferences.getInt("PAGE_NUM-" + content.getZipFilePath(), Integer.MAX_VALUE);
}
private int designatePageCount(Context context) {
System.out.println("designatePageCount");
try {
readSection(Integer.MAX_VALUE);
} catch (ReadingException e) {
e.printStackTrace();
} catch (OutOfPagesException e) {
e.printStackTrace();
return e.getPageCount();
}
return Integer.MAX_VALUE;
}
private void savePageCount(Context context, int num) {
System.out.println("savePageCount");
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
sharedPreferences.edit().putInt("PAGE_NUM-" + content.getZipFilePath(), num).apply();
}
from epubparser.
Well, this is a solution for acquiring the page count, no doubt. But designatePageCount method's required time and cpu will increase in parallel to the size of books.
Avoid calculating the page count if you can, but if you couldn't, better call saveProgress to avoid parsing books again.
Thank you for your participation.
from epubparser.
Thank you for response. I find knowing page count very useful because when I set page number to bookPager.setCurrentItem in the adapter when you have Integer.MAX_VALUE element in the adapter it can freeze Android for a while. Especially when you go to a previous pages from a big number is a small number (e.g. 550 -> 1).
I my solution I check the page count only once per book.
from epubparser.
It freezes because of calling readSection for (destinationPage - currentPage) times (if the pages between are not parsed before). And if the page is not parsed before readSection will spend extra parsing time.
Spreading the parsing process over time is the best course of action. However, to get the page count, currently you are forced to parse the whole book before. I'll try to think about a workaround for this.
from epubparser.
Related Issues (20)
- how to read all chapters title? HOT 2
- please add a constructor for java.io.File HOT 2
- Recursive call to fillNavPoints overwrites "this.navPoints" HOT 1
- com.github.mertakdut.exception.ReadingException: toc.ncx not found. HOT 5
- please return the cover image file name HOT 1
- opf:guide did not load HOT 1
- Entire Book Content Length HOT 2
- this book can't parse, please check it. thanks.
- All epub files are not getting open using epub parser HOT 1
- toc.ncx. How can I get a list of chapters? HOT 1
- Manipulation was failed. HOT 1
- how do i manipulate my epub HOT 1
- sample HOT 1
- Search text HOT 1
- File too short to be a zip file: 0 HOT 1
- Unable to render image in epub
- Need add menu jump function
- javax.xml.parsers.ParserConfigurationException: http://apache.org/xml/features/nonvalidating/load-dtd-grammar
- this lib give up on maintenance? HOT 1
- Performance problem Content class HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from epubparser.