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

Feature/wkwebview #386

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/FolioReaderAddHighlightNote.swift
Expand Up @@ -67,7 +67,7 @@ class FolioReaderAddHighlightNote: UIViewController {

if !highlightSaved && !isEditHighlight {
guard let currentPage = folioReader.readerCenter?.currentPage else { return }
currentPage.webView?.js("removeThisHighlight()")
currentPage.webView?.js("removeThisHighlight()") { _ in }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
currentPage.webView?.js("removeThisHighlight()") { _ in }
currentPage.webView?.js("removeThisHighlight()")

}
}

Expand Down
37 changes: 21 additions & 16 deletions Source/FolioReaderAudioPlayer.swift
Expand Up @@ -176,7 +176,7 @@ open class FolioReaderAudioPlayer: NSObject {
@objc func play() {
if book.hasAudio {
guard let currentPage = self.folioReader.readerCenter?.currentPage else { return }
currentPage.webView?.js("playAudio()")
currentPage.webView?.js("playAudio()") { _ in }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
currentPage.webView?.js("playAudio()") { _ in }
currentPage.webView?.js("playAudio()")

} else {
self.readCurrentSentence()
}
Expand Down Expand Up @@ -382,22 +382,27 @@ 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

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)

}

// 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 All @@ -410,7 +415,7 @@ open class FolioReaderAudioPlayer: NSObject {
if synthesizer.isSpeaking {
stopSynthesizer(immediate: false, completion: {
if let currentPage = self.folioReader.readerCenter?.currentPage {
currentPage.webView?.js("resetCurrentSentenceIndex()")
currentPage.webView?.js("resetCurrentSentenceIndex()") { _ in }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
currentPage.webView?.js("resetCurrentSentenceIndex()") { _ in }
currentPage.webView?.js("resetCurrentSentenceIndex()")

}
self.speakSentence()
})
Expand Down
61 changes: 38 additions & 23 deletions Source/FolioReaderCenter.swift
Expand Up @@ -648,12 +648,21 @@ 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

guard let readingTime = readingTime
else {
self.pageIndicatorView?.totalMinutes = 0
return

}

self.pageIndicatorView?.totalMinutes = Int(readingTime)!

}


pagesForCurrentPage(currentPage)

delegate?.pageDidAppear?(currentPage)
Expand Down Expand Up @@ -1075,60 +1084,66 @@ 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 = ""
var chapterName = ""
var authorName = ""
var shareItems = [AnyObject]()

// Get book title
if let title = self.book.title {
bookTitle = title
subject += " “\(title)”"
}

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

// Get author name
if let author = self.book.metadata.creators.first {
authorName = author.name
}

// 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)

let activityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
activityViewController.excludedActivityTypes = [UIActivity.ActivityType.print, UIActivity.ActivityType.postToVimeo]

// Pop style on iPad
if let actv = activityViewController.popoverPresentationController {
actv.barButtonItem = sender
}

present(activityViewController, animated: true, completion: nil)

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

}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion Source/FolioReaderHighlightList.swift
Expand Up @@ -190,7 +190,7 @@ class FolioReaderHighlightList: UITableViewController {

if (highlight.page == self.folioReader.readerCenter?.currentPageNumber),
let page = self.folioReader.readerCenter?.currentPage {
Highlight.removeFromHTMLById(withinPage: page, highlightId: highlight.highlightId) // Remove from HTML
Highlight.removeFromHTMLById(withinPage: page, highlightId: highlight.highlightId) { _ in } // Remove from HTML
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Highlight.removeFromHTMLById(withinPage: page, highlightId: highlight.highlightId) { _ in } // Remove from HTML
Highlight.removeFromHTMLById(withinPage: page, highlightId: highlight.highlightId) // Remove from HTML

}

highlight.remove(withConfiguration: self.readerConfig) // Remove from Database
Expand Down
6 changes: 3 additions & 3 deletions Source/FolioReaderKit.swift
Expand Up @@ -185,7 +185,7 @@ extension FolioReader {

if let readerCenter = self.readerCenter {
UIView.animate(withDuration: 0.6, animations: {
_ = readerCenter.currentPage?.webView?.js("nightMode(\(self.nightMode))")
_ = readerCenter.currentPage?.webView?.js("nightMode(\(self.nightMode))") { _ in }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_ = readerCenter.currentPage?.webView?.js("nightMode(\(self.nightMode))") { _ in }
_ = readerCenter.currentPage?.webView?.js("nightMode(\(self.nightMode))")

readerCenter.pageIndicatorView?.reloadColors()
readerCenter.configureNavBar()
readerCenter.scrollScrubber?.reloadColors()
Expand All @@ -210,7 +210,7 @@ extension FolioReader {
}
set (font) {
self.defaults.set(font.rawValue, forKey: kCurrentFontFamily)
_ = self.readerCenter?.currentPage?.webView?.js("setFontName('\(font.cssIdentifier)')")
_ = self.readerCenter?.currentPage?.webView?.js("setFontName('\(font.cssIdentifier)')") { _ in }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_ = self.readerCenter?.currentPage?.webView?.js("setFontName('\(font.cssIdentifier)')") { _ in }
_ = self.readerCenter?.currentPage?.webView?.js("setFontName('\(font.cssIdentifier)')")

}
}

Expand All @@ -232,7 +232,7 @@ extension FolioReader {
return
}

currentPage.webView?.js("setFontSize('\(currentFontSize.cssIdentifier)')")
currentPage.webView?.js("setFontSize('\(currentFontSize.cssIdentifier)')") { _ in }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
currentPage.webView?.js("setFontSize('\(currentFontSize.cssIdentifier)')") { _ in }
currentPage.webView?.js("setFontSize('\(currentFontSize.cssIdentifier)')")

}
}

Expand Down