FolioReader / FolioReader-Android

A Java ePub reader and parser framework for Android.
BSD 3-Clause "New" or "Revised" License
2.25k stars 718 forks source link

getPageNumber #263

Open veeyka opened 6 years ago

veeyka commented 6 years ago

hey how can i get page number to save it in a sharedPreference when we close book i need page number to save it and open book if user opens it later (open in last page closed) give me a sample code please thanks

KishanViramgama commented 6 years ago

Follow This Link https://github.com/FolioReader/FolioReader-Android#wiki

dumanapp commented 6 years ago

@KishanViramgama hi . I searched at FolioReader wiki you mean that get/set readposition. But I can not figure out how can I apply in my app?

KishanViramgama commented 6 years ago

store the read position with database

KishanViramgama commented 6 years ago

//--------------set book-------------//

folioReader.setReadPositionListener(new ReadPositionListener() {
                @Override
                public void saveReadPosition(ReadPosition readPosition) {
                    Log.d("readPosition", readPosition.toJson());
                    if (db.checkIdEpub(id)) {
                        db.addEpub(id, readPosition.toJson());
                    } else {
                        db.updateEpub(id, readPosition.toJson());
                    }
                }
            });

/----------- open book----------/

          try {
                    String string = db.getEpub(id);
                    JSONObject jsonObject = new JSONObject(string);
                    String bookId = jsonObject.getString("bookId");
                    String chapterId = jsonObject.getString("chapterId");
                    String chapterHref = jsonObject.getString("chapterHref");
                    int chapterIndex = Integer.parseInt(jsonObject.getString("chapterIndex"));
                    boolean usingId = Boolean.parseBoolean(jsonObject.getString("usingId"));
                    String value = jsonObject.getString("value");

                    ReadPosition readPosition = new ReadPositionImpl(bookId, chapterId,
                            chapterHref, chapterIndex, usingId, value);
                    folioReader.setReadPosition(readPosition);
                    folioReader.openBook(sdIconStorageDir.toString());

                } catch (JSONException e) {
                    e.printStackTrace();
                }
dumanapp commented 6 years ago

@KishanViramgama Thanks for your reply. I try the copy+paste your code to my app, the "db" and "addEpub" "updateEpub" give me an error "Cannot resolve symbol"

Again how can I apply get/set read position in my app ? I tried the sample FolioReader app and the app doesn't include get/set read position

KishanViramgama commented 6 years ago
hrishikesh-kadam commented 6 years ago

@veeyka Storing page number as last read position would be inconsistent as page number would be different on portarait and landscape mode or on tablet and mobiles. So we store the first visible span index or id as the last read position. Hope you have seen Wiki pages related to ReadPosition

@dumanapp We have updated Wiki pages, please have a look. It might help you to understand better.

TidelxD commented 3 years ago

@KishanViramgama i want to to calculate the total page number and store it on db for make a progress for the book for exampls : when user open the app it shows him the percentage of the book that he already read can you help me ! ( sorry for my bad english )

KishanViramgama commented 3 years ago

@TidelxD Check the bottom of Text Highlighting screen short in README.md

rohitS-786 commented 1 year ago

Hey , You can get the total number of Pages for current chapter in 'FolioPageFragment' using "webViewPager!!.totalPages()". Also , you can get total chapters in book in FolioActivity using "spine?.size".

With the combination of these two, we can find total number of pages in epub.