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

Commit

Permalink
Merge pull request #99 from FolioReader/feature/unified-navigation-ba…
Browse files Browse the repository at this point in the history
…r#88

Feature/unified navigation bar closes #88
  • Loading branch information
hebertialmeida authored Jul 20, 2016
2 parents a74404f + d513c17 commit 1d24122
Show file tree
Hide file tree
Showing 144 changed files with 1,936 additions and 1,809 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ before_install:
- pod repo update
script:
- set -o pipefail && xcodebuild test -workspace Example/Example.xcworkspace -scheme Example -sdk iphonesimulator9.3 ONLY_ACTIVE_ARCH=NO | xcpretty
- pod lib lint
- pod lib lint --allow-warnings
2 changes: 1 addition & 1 deletion Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ViewController: UIViewController {
openEpub(sender.tag);
}

func openEpub(sampleNum:Int) {
func openEpub(sampleNum: Int) {
let config = FolioReaderConfig()
config.shouldHideNavigationOnTap = sampleNum == 1 ? true : false
config.scrollDirection = sampleNum == 1 ? .horizontal : .vertical
Expand Down
2 changes: 1 addition & 1 deletion Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
AEXML: 716fb0a8decba4a3517324a71fee3685b30233d2
FolioReaderKit: e5e80a3b1d03f4c5b47e36bdb4117b3de73ad9af
FolioReaderKit: 490e17a79986704ee431fe1c307eb38da243d592
FontBlaster: b780f709b8f705638d0c80a1ecdfb23b3077d0a6
JSQWebViewController: eaa6bd68d9e1426ae25ade99c9bbde4c6cdd4120
Nimble: 97a0a4cae5124c117115634b2d055d8c97d0af19
Expand Down
2 changes: 1 addition & 1 deletion FolioReaderKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Pod::Spec.new do |s|
]
s.resources = [
'Source/**/*.{js,css,xcdatamodeld}',
'Source/Resources/Images/*.png',
'Source/Resources/*.xcassets',
'Source/Resources/Fonts/**/*.{otf,ttf}'
]
s.preserve_paths = 'Source/**/*.xcdatamodeld'
Expand Down
840 changes: 262 additions & 578 deletions FolioReaderKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Source/EPUBCore/FRBook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ class FRBook: NSObject {
var spine = FRSpine()
var smils = FRSmils()
var tableOfContents: [FRTocReference]!
var flatTableOfContents: [FRTocReference]!
var opfResource: FRResource!
var ncxResource: FRResource!
var coverImage: FRResource!

func hasAudio() -> Bool {
return smils.smils.count > 0 ? true : false;
return smils.smils.count > 0 ? true : false
}

func title() -> String? {
Expand Down
46 changes: 35 additions & 11 deletions Source/EPUBCore/FREpubParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
}

/**
Unzip, delete and read an epub file.
Returns a FRBook.
Unzip, delete and read an epub file.
Returns a FRBook.
*/
func readEpub(epubPath withEpubPath: String, removeEpub: Bool = true) -> FRBook {
epubPathToRemove = withEpubPath
Expand All @@ -61,8 +61,8 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {


/**
Read an unziped epub file.
Returns a FRBook.
Read an unziped epub file.
Returns a FRBook.
*/
func readEpub(filePath withFilePath: String) -> FRBook {
bookBasePath = withFilePath
Expand All @@ -73,7 +73,7 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
}

/**
Read and parse container.xml file.
Read and parse container.xml file.
*/
private func readContainer() {
let containerPath = "META-INF/container.xml"
Expand All @@ -92,7 +92,7 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
}

/**
Read and parse .opf file.
Read and parse .opf file.
*/
private func readOpf() {
let opfPath = (bookBasePath as NSString).stringByAppendingPathComponent(book.opfResource.href)
Expand Down Expand Up @@ -134,6 +134,7 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {

// The book TOC
book.tableOfContents = findTableOfContents()
book.flatTableOfContents = createFlatTOC()

// Read metadata
book.metadata = readMetadata(xmlDoc.root["metadata"].children)
Expand All @@ -152,7 +153,7 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
}

/**
Reads and parses a .smil file
Reads and parses a .smil file
*/
private func readSmilFile(resource: FRResource){
let smilData = try? NSData(contentsOfFile: resource.fullHref, options: .DataReadingMappedAlways)
Expand Down Expand Up @@ -196,7 +197,7 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
}

/**
Read and parse the Table of Contents.
Read and parse the Table of Contents.
*/
private func findTableOfContents() -> [FRTocReference] {
let ncxPath = (resourcesBasePath as NSString).stringByAppendingPathComponent(book.ncxResource.href)
Expand Down Expand Up @@ -237,8 +238,31 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
return toc
}

// MARK: - Recursive add items to a list

func createFlatTOC() -> [FRTocReference] {
var tocItems = [FRTocReference]()

for item in book.tableOfContents {
tocItems.append(item)
tocItems.appendContentsOf(countTocChild(item))
}
return tocItems
}

func countTocChild(item: FRTocReference) -> [FRTocReference] {
var tocItems = [FRTocReference]()

if item.children.count > 0 {
for item in item.children {
tocItems.append(item)
}
}
return tocItems
}

/**
Read and parse <metadata>.
Read and parse <metadata>.
*/
private func readMetadata(tags: [AEXMLElement]) -> FRMetadata {
let metadata = FRMetadata()
Expand Down Expand Up @@ -305,7 +329,7 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
}

/**
Read and parse <spine>.
Read and parse <spine>.
*/
private func readSpine(tags: [AEXMLElement]) -> FRSpine {
let spine = FRSpine()
Expand All @@ -326,7 +350,7 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
}

/**
Add skip to backup file.
Add skip to backup file.
*/
private func addSkipBackupAttributeToItemAtURL(URL: NSURL) -> Bool {
assert(NSFileManager.defaultManager().fileExistsAtPath(URL.path!))
Expand Down
17 changes: 8 additions & 9 deletions Source/EPUBCore/FRMediaType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,13 @@ class FRMediaType: NSObject {
static var mediatypes = [XHTML, EPUB, NCX, OPF, JPG, PNG, GIF, CSS, SVG, TTF, TTF1, TTF2, OPENTYPE, WOFF, SMIL, XPGT, PLS, JAVASCRIPT, MP3, MP4, OGG]

/**
Gets the MediaType based on the file mimetype.
Gets the MediaType based on the file mimetype.

- Parameters:
- name: The mediaType name
- filename: The file name to extract the extension
- parameter name: The mediaType name
- parameter fileName: The file name to extract the extension

- Returns: A know mediatype or create a new one.
*/
- returns: A know mediatype or create a new one.
*/
static func mediaTypeByName(name: String, fileName: String) -> MediaType {
for mediatype in mediatypes {
if mediatype.name == name {
Expand All @@ -99,17 +98,17 @@ class FRMediaType: NSObject {
}

/**
Compare if the resource is a image.
Compare if the resource is a image.

- Returns: `true` if is a image and `false` if not
- returns: `true` if is a image and `false` if not
*/
static func isBitmapImage(mediaType: MediaType) -> Bool {
return mediaType == JPG || mediaType == PNG || mediaType == GIF
}


/**
Gets the MediaType based on the file extension.
Gets the MediaType based on the file extension.
*/
static func determineMediaType(fileName: String) -> MediaType? {
for mediatype in mediatypes {
Expand Down
6 changes: 6 additions & 0 deletions Source/EPUBCore/FRResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ class FRResource: NSObject {
return paths.joinWithSeparator("/")
}
}

// MARK: Equatable

func ==(lhs: FRResource, rhs: FRResource) -> Bool {
return lhs.id == rhs.id && lhs.href == rhs.href
}
14 changes: 7 additions & 7 deletions Source/EPUBCore/FRResources.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ class FRResources: NSObject {
var resources = [String: FRResource]()

/**
Adds a resource to the resources.
Adds a resource to the resources.
*/
func add(resource: FRResource) {
self.resources[resource.href] = resource
}


/**
Gets the first resource (random order) with the give mediatype.
Gets the first resource (random order) with the give mediatype.

Useful for looking up the table of contents as it's supposed to be the only resource with NCX mediatype.
Useful for looking up the table of contents as it's supposed to be the only resource with NCX mediatype.
*/
func findFirstResource(byMediaType mediaType: MediaType) -> FRResource? {
for resource in resources.values {
Expand All @@ -48,7 +48,7 @@ class FRResources: NSObject {
}

/**
Whether there exists a resource with the given href.
Whether there exists a resource with the given href.
*/
func containsByHref(href: String) -> Bool {
if href.isEmpty {
Expand All @@ -59,7 +59,7 @@ class FRResources: NSObject {
}

/**
Whether there exists a resource with the given id.
Whether there exists a resource with the given id.
*/
func containsById(id: String) -> Bool {
if id.isEmpty {
Expand All @@ -75,7 +75,7 @@ class FRResources: NSObject {
}

/**
Gets the resource with the given href.
Gets the resource with the given href.
*/
func getByHref(href: String) -> FRResource? {
if href.isEmpty {
Expand All @@ -85,7 +85,7 @@ class FRResources: NSObject {
}

/**
Gets the resource with the given href.
Gets the resource with the given href.
*/
func getById(id: String) -> FRResource? {
for resource in resources.values {
Expand Down
2 changes: 1 addition & 1 deletion Source/EPUBCore/FRSmils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct FRSmilFile {
// MARK: - data methods

/**
Returns a smil <par> tag which contains info about parallel audio and text to be played
Returns a smil <par> tag which contains info about parallel audio and text to be played
*/
func parallelAudioForFragment(fragment: String!) -> FRSmilElement! {
return findParElement(forTextSrc: fragment, inData: data)
Expand Down
8 changes: 3 additions & 5 deletions Source/EPUBCore/FRSpine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ struct Spine {
class FRSpine: NSObject {
var spineReferences = [Spine]()


func nextChapter(href:String) -> FRResource? {
func nextChapter(href: String) -> FRResource? {
var found = false;

for item in spineReferences {

if( found ){
if(found){
return item.resource
}

if( item.resource.href == href ){
if(item.resource.href == href) {
found = true
}
}
Expand Down
13 changes: 7 additions & 6 deletions Source/EPUBCore/FRTocReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ class FRTocReference: NSObject {
self.init(title: title, resource: resource, fragmentID: fragmentID, children: [FRTocReference]())
}

init(title:String, resource: FRResource?, fragmentID: String, children: [FRTocReference]) {
init(title: String, resource: FRResource?, fragmentID: String, children: [FRTocReference]) {
self.resource = resource
self.title = title
self.fragmentID = fragmentID
self.children = children
}

override func isEqual(object: AnyObject?) -> Bool {
let obj = object as! FRTocReference
return obj.title == self.title && obj.fragmentID == self.fragmentID
}
}

// MARK: Equatable

func ==(lhs: FRTocReference, rhs: FRTocReference) -> Bool {
return lhs.title == rhs.title && lhs.fragmentID == rhs.fragmentID
}
Loading

0 comments on commit 1d24122

Please sign in to comment.