Skip to content
2 changes: 1 addition & 1 deletion Example/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :ios, '9.0'
platform :ios, '10.0'

use_frameworks!
inhibit_all_warnings!
Expand Down
8 changes: 4 additions & 4 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ DEPENDENCIES:
- Quick (= 1.3.2)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
https://github.com/CocoaPods/Specs.git:
- AEXML
- FontBlaster
- MenuItemKit
Expand All @@ -42,7 +42,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
AEXML: 601f41fcaa7bda7605cad153b0f43db9ec006c0f
FolioReaderKit: 6b5daca560b3dd6905ab14870f4823d7e1f283de
FolioReaderKit: e9842c8058ffa170f0574e45b2761498cfef90c4
FontBlaster: 127aa66419478d1c62926c7fdb39841633344a45
MenuItemKit: 0f850e630b0a3d2bd80fec54db87ce0d2077ada2
Nimble: 04f732da099ea4d153122aec8c2a88fd0c7219ae
Expand All @@ -52,6 +52,6 @@ SPEC CHECKSUMS:
SSZipArchive: 14401ade5f8e82aba1ff03e9f88e9de60937ae60
ZFDragableModalTransition: 0d294eaaba6edfcb9839595de765f9ca06a4b524

PODFILE CHECKSUM: f5840071ca5121876c1758f6405302b47804dd07
PODFILE CHECKSUM: 9b0cc9f299a29c5423503d26bd566e7f7bffcb6d

COCOAPODS: 1.7.5
COCOAPODS: 1.11.2
2 changes: 1 addition & 1 deletion FolioReaderKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Pod::Spec.new do |s|
s.social_media_url = 'https://twitter.com/hebertialmeida'

s.swift_version = '4.2'
s.platform = :ios, '9.0'
s.platform = :ios, '10.0'
s.requires_arc = true

s.source_files = [
Expand Down
25 changes: 11 additions & 14 deletions Source/FolioReaderAudioPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -382,22 +382,19 @@ open class FolioReaderAudioPlayer: NSObject {
}

let playbackActiveClass = book.playbackActiveClass
guard let sentence = currentPage.webView?.js("getSentenceWithIndex('\(playbackActiveClass)')") else {
if (readerCenter.isLastPage() == true) {
self.stop()
} else {
readerCenter.changePageToNext()
currentPage.webView?.js("getSentenceWithIndex('\(playbackActiveClass)')") { sentence in
guard let sentence = sentence else {
if (readerCenter.isLastPage() == true) {
self.stop()
} else {
readerCenter.changePageToNext()
}
return
}

return
guard let href = readerCenter.getCurrentChapter()?.href else { return }
// TODO QUESTION: The previous code made it possible to call `playText` with the parameter `href` being an empty string. Was that valid? should this logic be kept?
self.playText(href, text: sentence)
}

guard let href = readerCenter.getCurrentChapter()?.href else {
return
}

// TODO QUESTION: The previous code made it possible to call `playText` with the parameter `href` being an empty string. Was that valid? should this logic be kept?
self.playText(href, text: sentence)
}

func readCurrentSentence() {
Expand Down
53 changes: 22 additions & 31 deletions Source/FolioReaderCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import UIKit
import ZFDragableModalTransition
import WebKit

/// Protocol which is used from `FolioReaderCenter`s.
@objc public protocol FolioReaderCenterDelegate: class {
Expand Down Expand Up @@ -464,17 +465,11 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl
guard var html = try? String(contentsOfFile: resource.fullHref, encoding: String.Encoding.utf8) else {
return cell
}

// Inject viewport
let viewportTag = "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, shrink-to-fit=no\">"

let mediaOverlayStyleColors = "\"\(self.readerConfig.mediaOverlayColor.hexString(false))\", \"\(self.readerConfig.mediaOverlayColor.highlightColor().hexString(false))\""

// Inject CSS
let jsFilePath = Bundle.frameworkBundle().path(forResource: "Bridge", ofType: "js")
let cssFilePath = Bundle.frameworkBundle().path(forResource: "Style", ofType: "css")
let cssTag = "<link rel=\"stylesheet\" type=\"text/css\" href=\"\(cssFilePath!)\">"
let jsTag = "<script type=\"text/javascript\" src=\"\(jsFilePath!)\"></script>" +
"<script type=\"text/javascript\">setMediaOverlayStyleColors(\(mediaOverlayStyleColors))</script>"

let toInject = "\n\(cssTag)\n\(jsTag)\n</head>"
let toInject = "\n\(viewportTag)\n</head>"
html = html.replacingOccurrences(of: "</head>", with: toInject)

// Font class name
Expand Down Expand Up @@ -648,18 +643,13 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl
}

scrollScrubber?.setSliderVal()

if let readingTime = currentPage.webView?.js("getReadingTime()") {
pageIndicatorView?.totalMinutes = Int(readingTime)!
} else {
pageIndicatorView?.totalMinutes = 0
currentPage.webView?.js("getReadingTime()") { readingTime in
self.pageIndicatorView?.totalMinutes = Int(readingTime ?? "0")!
self.pagesForCurrentPage(currentPage)
self.delegate?.pageDidAppear?(currentPage)
self.delegate?.pageItemChanged?(self.getCurrentPageItemNumber())
completion?()
}
pagesForCurrentPage(currentPage)

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

completion?()
}

func pagesForCurrentPage(_ page: FolioReaderPage?) {
Expand Down Expand Up @@ -1075,9 +1065,10 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl
@objc func shareChapter(_ sender: UIBarButtonItem) {
guard let currentPage = currentPage else { return }

if let chapterText = currentPage.webView?.js("getBodyText()") {
currentPage.webView?.js("getBodyText()") { chapterText in
guard let chapterText = chapterText else { return }
let htmlText = chapterText.replacingOccurrences(of: "[\\n\\r]+", with: "<br />", options: .regularExpression)
var subject = readerConfig.localizedShareChapterSubject
var subject = self.readerConfig.localizedShareChapterSubject
var html = ""
var text = ""
var bookTitle = ""
Expand All @@ -1092,7 +1083,7 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl
}

// Get chapter name
if let chapter = getCurrentChapterName() {
if let chapter = self.getCurrentChapterName() {
chapterName = chapter
}

Expand All @@ -1104,17 +1095,17 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl
// Sharing html and text
html = "<html><body>"
html += "<br /><hr> <p>\(htmlText)</p> <hr><br />"
html += "<center><p style=\"color:gray\">"+readerConfig.localizedShareAllExcerptsFrom+"</p>"
html += "<center><p style=\"color:gray\">"+self.readerConfig.localizedShareAllExcerptsFrom+"</p>"
html += "<b>\(bookTitle)</b><br />"
html += readerConfig.localizedShareBy+" <i>\(authorName)</i><br />"

if let bookShareLink = readerConfig.localizedShareWebLink {
html += self.readerConfig.localizedShareBy+" <i>\(authorName)</i><br />"
if let bookShareLink = self.readerConfig.localizedShareWebLink {
html += "<a href=\"\(bookShareLink.absoluteString)\">\(bookShareLink.absoluteString)</a>"
shareItems.append(bookShareLink as AnyObject)
}

html += "</center></body></html>"
text = "\(chapterName)\n\n“\(chapterText)” \n\n\(bookTitle) \n\(readerConfig.localizedShareBy) \(authorName)"
text = "\(chapterName)\n\n“\(chapterText)” \n\n\(bookTitle) \n\(self.readerConfig.localizedShareBy) \(authorName)"

let act = FolioReaderSharingProvider(subject: subject, text: text, html: html)
shareItems.insert(contentsOf: [act, "" as AnyObject], at: 0)
Expand All @@ -1127,7 +1118,7 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl
actv.barButtonItem = sender
}

present(activityViewController, animated: true, completion: nil)
self.present(activityViewController, animated: true, completion: nil)
}
}

Expand Down Expand Up @@ -1281,7 +1272,7 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl
// Perform the page after a short delay as the collection view hasn't completed it's transition if this method is called (the index paths aren't right during fast scrolls).
delay(0.2, closure: { [weak self] in
if (self?.readerConfig.scrollDirection == .horizontalWithVerticalContent),
let cell = ((scrollView.superview as? UIWebView)?.delegate as? FolioReaderPage) {
let cell = ((scrollView.superview as? WKWebView)?.navigationDelegate as? FolioReaderPage) {
let currentIndexPathRow = cell.pageNumber - 1
self?.currentWebViewScrollPositions[currentIndexPathRow] = scrollView.contentOffset
}
Expand Down
Loading