Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller for custom logics? #78

Open
lzzy12 opened this issue Apr 27, 2023 · 9 comments
Open

Controller for custom logics? #78

lzzy12 opened this issue Apr 27, 2023 · 9 comments

Comments

@lzzy12
Copy link

lzzy12 commented Apr 27, 2023

Hi, my use-case requires to get the page number the user currently is on and the total number of pages. Is this possible to get with the EpubScreen.fromFile constructor or is there any other way to do this? I am looking for something like a controller class for the reader.

@jmgeffroy
Copy link
Contributor

Hi @lzzy12, In fact, the ReaderContext does provide a currentLocationStream, which seems to be what you need if I understand correctly. To see an example in action, you can have a look at this code in the ReaderToolbar class.
If access to this stream is what you ned, I'll think about a clean way to provide access to it.

@lzzy12
Copy link
Author

lzzy12 commented Apr 27, 2023

Yes it will be helpful if this could be available through an API outside the package.

@jmgeffroy
Copy link
Contributor

jmgeffroy commented Apr 27, 2023

@lzzy12 I have added a paginationCallback parameter to the EpubScreen API, and adapted the reader widget example to showcase it:

        EpubScreen.fromPath(
          filePath: widget.dirPath,
          location: '{"cfi":" ","idref":"file_12.html"}',
          paginationCallback: (paginationInfo) {
            Fimber.d("--- paginationInfo: $paginationInfo");
          },
        )

The PaginationInfo class contains a lot of information about the position.

Does it match your requirements ?

@lzzy12
Copy link
Author

lzzy12 commented Apr 27, 2023

Hi, thanks for your quick responses. While this does give me the current page number, I could not figure out which one of the attributes stores the total number of pages in the epub file. Could you please point me to it?

@jmgeffroy
Copy link
Contributor

Hello @lzzy12, in fact PaginationInfo contains a page method, which is defined as follows (pagination_info.dart):

  int get page =>
      linkPagination.firstPageNumber +
      percent * (linkPagination.pagesCount - 1) ~/ 100;

@lzzy12
Copy link
Author

lzzy12 commented May 3, 2023

Hi @jmgeffroy Currently this page method just gives me the current page number user is on. How do I get the total number of pages present in the epub file?

@lzzy12
Copy link
Author

lzzy12 commented May 3, 2023

Also the perccent seems to be giving wrong information. It seems inconsistent with what is currently on the UI

Screenshot_1683099559
I get this when I log the percent field
[log] percent: 23
[log] percent: 23

My code:

EpubScreen.fromPath(
                        filePath: controller.bookPath!,
                        paginationCallback: (data) {
                          controller.ePubPageCount.value =
                              data.linkPagination.pagesCount;
                          controller.ePubPage.value =
                              data.percent ~/ data.linkPagination.pagesCount;
                          log("percent: ${data.percent.toString()}");
                        },
                      )

@jmgeffroy
Copy link
Contributor

Hi @lzzy12, That's a good point; thank you for your feedback. Based on your observations, I have to look into this more. Obviously, page counts in reflowable epubs are approximations, but not as bad as what you are experiencing. Today I'm busy, but I'll look at it asap.

@lzzy12
Copy link
Author

lzzy12 commented Jul 3, 2023

Hi @jmgeffroy, did you get a chance to look at this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants