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

Replaced func with var on FRbook #296

Merged
merged 2 commits into from
Jan 11, 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
43 changes: 19 additions & 24 deletions Source/EPUBCore/FRBook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,70 +23,65 @@ open class FRBook: NSObject {
public var resources = FRResources()
public var tableOfContents: [FRTocReference]!
public var flatTableOfContents: [FRTocReference]!
public func hasAudio() -> Bool {
return smils.smils.count > 0 ? true : false

var hasAudio: Bool {
return smils.smils.count > 0
}

public func title() -> String? {
var title: String? {
return metadata.titles.first
}

public func authorName() -> String? {
var authorName: String? {
return metadata.creators.first?.name
}

// MARK: - Media Overlay Metadata
// http://www.idpf.org/epub/301/spec/epub-mediaoverlays.html#sec-package-metadata

func duration() -> String? {
return metadata.findMetaByProperty("media:duration");
}

// @NOTE: should "#" be automatically prefixed with the ID?
func durationFor(_ ID: String) -> String? {
return metadata.findMetaByProperty("media:duration", refinedBy: ID)
var duration: String? {
return metadata.findMetaByProperty("media:duration")
}


func activeClass() -> String {
var activeClass: String {
guard let className = metadata.findMetaByProperty("media:active-class") else {
return "epub-media-overlay-active"
}
return className
}

func playbackActiveClass() -> String {
var playbackActiveClass: String {
guard let className = metadata.findMetaByProperty("media:playback-active-class") else {
return "epub-media-overlay-playing"
}
return className
}


// MARK: - Media Overlay (SMIL) retrieval

/**
Get Smil File from a resource (if it has a media-overlay)
*/
func smilFileForResource(_ resource: FRResource!) -> FRSmilFile! {
if( resource == nil || resource.mediaOverlay == nil ){
return nil
}
func smilFileForResource(_ resource: FRResource?) -> FRSmilFile? {
guard let resource = resource, let mediaOverlay = resource.mediaOverlay else { return nil }

// lookup the smile resource to get info about the file
let smilResource = resources.findById(resource.mediaOverlay)
guard let smilResource = resources.findById(mediaOverlay) else { return nil }

// use the resource to get the file
return smils.findByHref( smilResource!.href )
return smils.findByHref(smilResource.href)
}

func smilFileForHref(_ href: String) -> FRSmilFile! {
func smilFile(forHref href: String) -> FRSmilFile? {
return smilFileForResource(resources.findByHref(href))
}

func smilFileForId(_ ID: String) -> FRSmilFile! {
func smilFile(forId ID: String) -> FRSmilFile? {
return smilFileForResource(resources.findById(ID))
}

// @NOTE: should "#" be automatically prefixed with the ID?
func duration(for ID: String) -> String? {
return metadata.findMetaByProperty("media:duration", refinedBy: ID)
}
}
4 changes: 2 additions & 2 deletions Source/EPUBCore/FREpubParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
}

func parseTitle(_ epubPath: String) throws -> String? {
guard let book = try readEpub(epubPath: epubPath, removeEpub: false), let title = book.title() else {
guard let book = try readEpub(epubPath: epubPath, removeEpub: false), let title = book.title else {
throw FolioReaderError(kind: .TitleNotAvailable)
}
return title
}

func parseAuthorName(_ epubPath: String) throws -> String? {
guard let book = try readEpub(epubPath: epubPath, removeEpub: false), let authorName = book.authorName() else {
guard let book = try readEpub(epubPath: epubPath, removeEpub: false), let authorName = book.authorName else {
throw FolioReaderError(kind: .AuthorNameNotAvailable)
}
return authorName
Expand Down
10 changes: 5 additions & 5 deletions Source/FolioReaderAudioPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ open class FolioReaderAudioPlayer: NSObject {
}

@objc func play() {
if (self.book.hasAudio() == true) {
if book.hasAudio {
guard let currentPage = self.folioReader.readerCenter?.currentPage else { return }
currentPage.webView?.js("playAudio()")
} else {
Expand All @@ -178,7 +178,7 @@ open class FolioReaderAudioPlayer: NSObject {

self.stop()

let smilFile = self.book.smilFileForHref(href)
let smilFile = book.smilFile(forHref: href)

// if no smil file for this href and the same href is being requested, we've hit the end. stop playing
if smilFile == nil && currentHref != nil && href == currentHref {
Expand Down Expand Up @@ -308,7 +308,7 @@ open class FolioReaderAudioPlayer: NSObject {
*/
fileprivate func nextAudioFragment() -> FRSmilElement? {

guard let smilFile = self.book.smilFileForHref(currentHref) else {
guard let smilFile = book.smilFile(forHref: currentHref) else {
return nil
}

Expand Down Expand Up @@ -362,7 +362,7 @@ open class FolioReaderAudioPlayer: NSObject {
return
}

let playbackActiveClass = self.book.playbackActiveClass()
let playbackActiveClass = book.playbackActiveClass
guard let sentence = currentPage.webView?.js("getSentenceWithIndex('\(playbackActiveClass)')") else {
if (readerCenter.isLastPage() == true) {
self.stop()
Expand Down Expand Up @@ -441,7 +441,7 @@ open class FolioReaderAudioPlayer: NSObject {
}

// Get book title
if let title = self.book.title() {
if let title = self.book.title {
songInfo[MPMediaItemPropertyAlbumTitle] = title as AnyObject?
}

Expand Down
8 changes: 4 additions & 4 deletions Source/FolioReaderCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl
rightBarIcons.append(UIBarButtonItem(image: shareIcon, style: .plain, target: self, action:#selector(shareChapter(_:))))
}

if (self.book.hasAudio() == true || self.readerConfig.enableTTS == true) {
if self.book.hasAudio || self.readerConfig.enableTTS {
rightBarIcons.append(UIBarButtonItem(image: audioIcon, style: .plain, target: self, action:#selector(presentPlayerMenu(_:))))
}

Expand All @@ -285,7 +285,7 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl
navigationItem.rightBarButtonItems = rightBarIcons

if(self.readerConfig.displayTitle){
navigationItem.title = book.title()
navigationItem.title = book.title
}
}

Expand Down Expand Up @@ -1051,7 +1051,7 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl
var shareItems = [AnyObject]()

// Get book title
if let title = self.book.title() {
if let title = self.book.title {
bookTitle = title
subject += " “\(title)”"
}
Expand Down Expand Up @@ -1109,7 +1109,7 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl
var shareItems = [AnyObject]()

// Get book title
if let title = self.book.title() {
if let title = self.book.title {
bookTitle = title
subject += " “\(title)”"
}
Expand Down
2 changes: 1 addition & 1 deletion Source/FolioReaderChapterList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class FolioReaderChapterList: UITableViewController {
// Add audio duration for Media Ovelay
if let resource = tocReference.resource {
if let mediaOverlay = resource.mediaOverlay {
let duration = self.book.durationFor("#"+mediaOverlay)
let duration = self.book.duration(for: "#"+mediaOverlay)

if let durationFormatted = (duration != nil ? duration : "")?.clockTimeToMinutesString() {
let text = cell.indexLabel?.text ?? ""
Expand Down
2 changes: 1 addition & 1 deletion Source/FolioReaderContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ open class FolioReaderContainer: UIViewController {
DispatchQueue.main.async {

// Add audio player if needed
if (self.book.hasAudio() == true || self.readerConfig.enableTTS == true) {
if self.book.hasAudio || self.readerConfig.enableTTS {
self.addAudioPlayer()
}
self.centerViewController?.reloadData()
Expand Down
4 changes: 2 additions & 2 deletions Source/FolioReaderPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ open class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRe

refreshPageMode()

if (self.readerConfig.enableTTS == true && self.book.hasAudio() == false) {
if self.readerConfig.enableTTS && !self.book.hasAudio {
webView.js("wrappingSentencesWithinPTags()")

if let audioPlayer = self.folioReader.readerAudioPlayer, (audioPlayer.isPlaying() == true) {
Expand Down Expand Up @@ -485,7 +485,7 @@ open class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRe
return
}

let playbackActiveClass = self.book.playbackActiveClass()
let playbackActiveClass = self.book.playbackActiveClass
currentPage.webView?.js("audioMarkID('\(playbackActiveClass)','\(identifier)')")
}

Expand Down
4 changes: 2 additions & 2 deletions Source/FolioReaderQuoteShare.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class FolioReaderQuoteShare: UIViewController {
var bookTitle = ""
var authorName = ""

if let title = self.book.title() {
if let title = self.book.title {
bookTitle = title
}

Expand Down Expand Up @@ -262,7 +262,7 @@ class FolioReaderQuoteShare: UIViewController {
var shareItems = [AnyObject]()

// Get book title
if let title = self.book.title() {
if let title = self.book.title {
bookTitle = title
subject += " “\(title)”"
}
Expand Down
10 changes: 5 additions & 5 deletions Source/FolioReaderWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ open class FolioReaderWebView: UIWebView {
// MARK: - UIMenuController

open override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
guard (self.readerConfig.useReaderMenuController == true) else {
guard readerConfig.useReaderMenuController else {
return super.canPerformAction(action, withSender: sender)
}

Expand All @@ -59,9 +59,9 @@ open class FolioReaderWebView: UIWebView {
} else {
if action == #selector(highlight(_:))
|| (action == #selector(define(_:)) && isOneWord)
|| (action == #selector(play(_:)) && (self.book.hasAudio() == true || self.readerConfig.enableTTS == true))
|| (action == #selector(share(_:)) && self.readerConfig.allowSharing == true)
|| (action == #selector(copy(_:)) && self.readerConfig.allowSharing == true) {
|| (action == #selector(play(_:)) && (book.hasAudio || readerConfig.enableTTS))
|| (action == #selector(share(_:)) && readerConfig.allowSharing)
|| (action == #selector(copy(_:)) && readerConfig.allowSharing) {
return true
}
return false
Expand Down Expand Up @@ -275,7 +275,7 @@ open class FolioReaderWebView: UIWebView {
// default menu
menuItems = [highlightItem, defineItem, shareItem]

if (self.book.hasAudio() == true || self.readerConfig.enableTTS == true) {
if self.book.hasAudio || self.readerConfig.enableTTS {
menuItems.insert(playAudioItem, at: 0)
}

Expand Down