From b9c0369a0282b2d24e0c50ad485cc34354dcc747 Mon Sep 17 00:00:00 2001 From: Paulo Coutinho Date: Tue, 24 Jul 2018 04:57:41 -0300 Subject: [PATCH] method to get current progress between 0 and 100 --- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++++ .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++++ Source/FolioReaderCenter.swift | 22 ++++++++++++++++++- Source/FolioReaderPageIndicator.swift | 2 +- 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 Example/Example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 FolioReaderKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Example/Example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Example/Example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Example/Example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/FolioReaderKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/FolioReaderKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/FolioReaderKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Source/FolioReaderCenter.swift b/Source/FolioReaderCenter.swift index 919174a04..a50e20225 100644 --- a/Source/FolioReaderCenter.swift +++ b/Source/FolioReaderCenter.swift @@ -658,7 +658,7 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl delegate?.pageDidAppear?(currentPage) delegate?.pageItemChanged?(self.getCurrentPageItemNumber()) - + completion?() } @@ -847,6 +847,26 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl return webViewPage } + + public func getCurrentPageProgress() -> Float { + guard let page = currentPage, let webView = page.webView else { return 0 } + + let pageSize = self.readerConfig.isDirection(pageHeight, self.pageWidth, pageHeight) + let contentSize = page.webView?.scrollView.contentSize.forDirection(withConfiguration: self.readerConfig) ?? 0 + let totalPages = ((pageSize != 0) ? Int(ceil(contentSize / pageSize)) : 0) + let currentPageItem = getCurrentPageItemNumber() + + if totalPages > 0 { + var progress = Float((currentPageItem * 100) / totalPages) + + if progress < 0 { progress = 0 } + if progress > 100 { progress = 100 } + + return progress + } + + return 0 + } public func changePageItemToPrevious(_ completion: (() -> Void)? = nil) { // TODO: It was implemented for horizontal orientation. diff --git a/Source/FolioReaderPageIndicator.swift b/Source/FolioReaderPageIndicator.swift index 4ef8581b9..1e244bd96 100644 --- a/Source/FolioReaderPageIndicator.swift +++ b/Source/FolioReaderPageIndicator.swift @@ -103,7 +103,7 @@ class FolioReaderPageIndicator: UIView { } else { minutesLabel.text = self.readerConfig.localizedReaderLessThanOneMinute+" ยท" } - + reloadView(updateShadow: false) } }