FolioReader-Android icon indicating copy to clipboard operation
FolioReader-Android copied to clipboard

getPageNumber

Open veeyka opened this issue 7 years ago • 10 comments

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

veeyka avatar Aug 25 '18 05:08 veeyka

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

KishanViramgama avatar Aug 25 '18 15:08 KishanViramgama

@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?

dumanapp avatar Aug 26 '18 16:08 dumanapp

store the read position with database

KishanViramgama avatar Aug 27 '18 04:08 KishanViramgama

//--------------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();
                }

KishanViramgama avatar Aug 27 '18 04:08 KishanViramgama

@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

dumanapp avatar Aug 27 '18 10:08 dumanapp

  • i have show you example how to work
  • db is a my database class object name and checkIdEpub() is a my method i have check book is already store or not
  • addEpub() is a method to store the lastread read position information
  • updateEpub() is a my method already save last read position information update to the database
  • getEpub() is a my method get the last read position information in book

KishanViramgama avatar Aug 27 '18 16:08 KishanViramgama

@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.

hrishikesh-kadam avatar Aug 28 '18 12:08 hrishikesh-kadam

@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 )

TidelxD avatar Apr 26 '21 14:04 TidelxD

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

KishanViramgama avatar May 01 '21 11:05 KishanViramgama

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.

rohitS-786 avatar Mar 23 '23 17:03 rohitS-786