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

Commit

Permalink
method to get current progress between 0 and 100 (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
PRSoluções authored and hebertialmeida committed Jul 30, 2018
1 parent 4742907 commit a9ba2aa
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
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

0 comments on commit a9ba2aa

Please sign in to comment.