Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Method to get current progress between 0 and 100 #348

Merged
merged 2 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
22 changes: 21 additions & 1 deletion Source/FolioReaderCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl

delegate?.pageDidAppear?(currentPage)
delegate?.pageItemChanged?(self.getCurrentPageItemNumber())

completion?()
}

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Source/FolioReaderPageIndicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class FolioReaderPageIndicator: UIView {
} else {
minutesLabel.text = self.readerConfig.localizedReaderLessThanOneMinute+" ·"
}

reloadView(updateShadow: false)
}
}
Expand Down