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 #125 from FolioReader/feature/share-image-quotes
Browse files Browse the repository at this point in the history
Feature/share image quotes, closes #109
  • Loading branch information
hebertialmeida authored Sep 1, 2016
2 parents 8927772 + 0348bc1 commit f37cd05
Show file tree
Hide file tree
Showing 21 changed files with 741 additions and 65 deletions.
6 changes: 6 additions & 0 deletions Example/Example/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
21 changes: 21 additions & 0 deletions Example/Example/Assets.xcassets/demo-bg.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "demo-bg.jpeg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ class ViewController: UIViewController {
// config.menuTextColor = UIColor.brownColor()
// config.menuBackgroundColor = UIColor.lightGrayColor()

// Custom sharing quote background
let customImageQuote = QuoteImage(withImage: UIImage(named: "demo-bg")!, alpha: 0.6, backgroundColor: UIColor.blackColor())
let customQuote = QuoteImage(withColor: UIColor(red:0.30, green:0.26, blue:0.20, alpha:1.0), alpha: 1.0, textColor: UIColor(red:0.86, green:0.73, blue:0.70, alpha:1.0))

config.quoteCustomBackgrounds = [customImageQuote, customQuote]

// Epub file
let epubName = epubSampleFiles[sampleNum-1];
let bookPath = NSBundle.mainBundle().pathForResource(epubName, ofType: "epub")
FolioReader.presentReader(parentViewController: self, withEpubPath: bookPath!, andConfig: config, shouldRemoveEpub: false)
Expand Down
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ target '<Your Target Name>' do
end
```

Or if trying the demo, move to the example directory

```bash
$ cd Example
```

Then, run the following command:

```bash
Expand Down Expand Up @@ -139,7 +133,7 @@ func applicationWillTerminate(application: UIApplication) {
![Time left](https://raw.githubusercontent.com/FolioReader/FolioReaderKit/assets/media-overlays.gif)

## Documentation
For now the best documentation is the sample project. I ~~will write a better~~ am working to improve the code documentation, this is the current progress: [![CocoaPods](https://img.shields.io/cocoapods/metrics/doc-percent/FolioReaderKit.svg?maxAge=100)](http://cocoadocs.org/docsets/FolioReaderKit)
For now the best documentation is the sample project. I ~~will write a better~~ am working to improve the code documentation, this is the current progress: [![CocoaPods](https://img.shields.io/cocoapods/metrics/doc-percent/FolioReaderKit.svg?maxAge=2592000)](http://cocoadocs.org/docsets/FolioReaderKit)

You have a problem that cannot be solved by having a look at the example project? No problem, let's talk:
[![Join the chat at https://gitter.im/FolioReader/FolioReaderKit](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/FolioReader/FolioReaderKit?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Expand Down
2 changes: 1 addition & 1 deletion Source/EPUBCore/FRBook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import UIKit

class FRBook: NSObject {
public class FRBook: NSObject {
var resources = FRResources()
var metadata = FRMetadata()
var spine = FRSpine()
Expand Down
8 changes: 4 additions & 4 deletions Source/FolioReaderAudioPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
import AVFoundation
import MediaPlayer

class FolioReaderAudioPlayer: NSObject {
public class FolioReaderAudioPlayer: NSObject {
var isTextToSpeech = false
var synthesizer: AVSpeechSynthesizer!
var playing = false
Expand Down Expand Up @@ -503,11 +503,11 @@ class FolioReaderAudioPlayer: NSObject {
// MARK: AVSpeechSynthesizerDelegate

extension FolioReaderAudioPlayer: AVSpeechSynthesizerDelegate {
func speechSynthesizer(synthesizer: AVSpeechSynthesizer, didCancelSpeechUtterance utterance: AVSpeechUtterance) {
public func speechSynthesizer(synthesizer: AVSpeechSynthesizer, didCancelSpeechUtterance utterance: AVSpeechUtterance) {
completionHandler()
}

func speechSynthesizer(synthesizer: AVSpeechSynthesizer, didFinishSpeechUtterance utterance: AVSpeechUtterance) {
public func speechSynthesizer(synthesizer: AVSpeechSynthesizer, didFinishSpeechUtterance utterance: AVSpeechUtterance) {
if isPlaying() {
readCurrentSentence()
}
Expand All @@ -517,7 +517,7 @@ extension FolioReaderAudioPlayer: AVSpeechSynthesizerDelegate {
// MARK: AVAudioPlayerDelegate

extension FolioReaderAudioPlayer: AVAudioPlayerDelegate {
func audioPlayerDidFinishPlaying(player: AVAudioPlayer, successfully flag: Bool) {
public func audioPlayerDidFinishPlaying(player: AVAudioPlayer, successfully flag: Bool) {
_playFragment(nextAudioFragment())
}
}
78 changes: 46 additions & 32 deletions Source/FolioReaderCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ var pageScrollDirection = ScrollDirection()
var isScrolling = false


class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
public class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {

var collectionView: UICollectionView!
let collectionViewLayout = UICollectionViewFlowLayout()
var loadingView: UIActivityIndicatorView!
Expand All @@ -30,7 +30,6 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio
var currentPage: FolioReaderPage?
var animator: ZFModalTransitionAnimator!
var pageIndicatorView: FolioReaderPageIndicator!
var bookShareLink: String?
var pageIndicatorHeight: CGFloat = 20

var recentlyScrolled = false
Expand All @@ -47,7 +46,7 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio

// MARK: - View life cicle

override func viewDidLoad() {
override public func viewDidLoad() {
super.viewDidLoad()

screenBounds = UIScreen.mainScreen().bounds
Expand Down Expand Up @@ -102,7 +101,7 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio
view.addSubview(loadingView)
}

override func viewWillAppear(animated: Bool) {
override public func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)

// Update pages
Expand Down Expand Up @@ -152,7 +151,6 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio

func reloadData() {
loadingView.stopAnimating()
bookShareLink = readerConfig.localizedShareWebLink
totalPages = book.spine.spineReferences.count

collectionView.reloadData()
Expand Down Expand Up @@ -277,15 +275,15 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio

// MARK: UICollectionViewDataSource

func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
public func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
public func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return totalPages
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
public func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! FolioReaderPage

cell.pageNumber = indexPath.row+1
Expand Down Expand Up @@ -373,7 +371,7 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio

// MARK: - Device rotation

override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
override public func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
guard FolioReader.isReaderReady else { return }

setPageSize(toInterfaceOrientation)
Expand Down Expand Up @@ -413,7 +411,7 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio
})
}

override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
override public func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
guard FolioReader.isReaderReady else { return }
guard let currentPage = currentPage else { return }

Expand All @@ -436,7 +434,7 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio
currentPage.webView.scrollView.setContentOffset(pageOffsetPoint, animated: true)
}

override func willAnimateRotationToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
override public func willAnimateRotationToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
guard FolioReader.isReaderReady else { return }

if currentPageNumber+1 >= totalPages {
Expand Down Expand Up @@ -743,15 +741,14 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio
guard let currentPage = currentPage else { return }

if let chapterText = currentPage.webView.js("getBodyText()") {

let htmlText = chapterText.stringByReplacingOccurrencesOfString("[\\n\\r]+", withString: "<br />", options: .RegularExpressionSearch)

var subject = readerConfig.localizedShareChapterSubject
var html = ""
var text = ""
var bookTitle = ""
var chapterName = ""
var authorName = ""
var shareItems = [AnyObject]()

// Get book title
if let title = book.title() {
Expand All @@ -775,16 +772,20 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio
html += "<center><p style=\"color:gray\">"+readerConfig.localizedShareAllExcerptsFrom+"</p>"
html += "<b>\(bookTitle)</b><br />"
html += readerConfig.localizedShareBy+" <i>\(authorName)</i><br />"
if (bookShareLink != nil) { html += "<a href=\"\(bookShareLink!)\">\(bookShareLink!)</a>" }
html += "</center></body></html>"
text = "\(chapterName)\n\n\(chapterText)\n\n\(bookTitle) \nby \(authorName)"
if (bookShareLink != nil) { text += " \n\(bookShareLink!)" }

if let bookShareLink = readerConfig.localizedShareWebLink {
html += "<a href=\"\(bookShareLink.absoluteString)\">\(bookShareLink.absoluteString)</a>"
shareItems.append(bookShareLink)
}

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

let act = FolioReaderSharingProvider(subject: subject, text: text, html: html)
let shareItems = [act, ""]
shareItems.insertContentsOf([act, ""], at: 0)

let activityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
activityViewController.excludedActivityTypes = [UIActivityTypePrint, UIActivityTypePostToVimeo, UIActivityTypePostToFacebook]
activityViewController.excludedActivityTypes = [UIActivityTypePrint, UIActivityTypePostToVimeo]

// Pop style on iPad
if let actv = activityViewController.popoverPresentationController {
Expand All @@ -799,13 +800,13 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio
Sharing highlight method.
*/
func shareHighlight(string: String, rect: CGRect) {

var subject = readerConfig.localizedShareHighlightSubject
var html = ""
var text = ""
var bookTitle = ""
var chapterName = ""
var authorName = ""
var shareItems = [AnyObject]()

// Get book title
if let title = book.title() {
Expand All @@ -830,16 +831,20 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio
html += "<center><p style=\"color:gray\">"+readerConfig.localizedShareAllExcerptsFrom+"</p>"
html += "<b>\(bookTitle)</b><br />"
html += readerConfig.localizedShareBy+" <i>\(authorName)</i><br />"
if (bookShareLink != nil) { html += "<a href=\"\(bookShareLink!)\">\(bookShareLink!)</a>" }
html += "</center></body></html>"
text = "\(chapterName)\n\n\(string)\n\n\(bookTitle) \nby \(authorName)"
if (bookShareLink != nil) { text += " \n\(bookShareLink!)" }

if let bookShareLink = readerConfig.localizedShareWebLink {
html += "<a href=\"\(bookShareLink.absoluteString)\">\(bookShareLink.absoluteString)</a>"
shareItems.append(bookShareLink)
}

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

let act = FolioReaderSharingProvider(subject: subject, text: text, html: html)
let shareItems = [act, ""]
shareItems.insertContentsOf([act, ""], at: 0)

let activityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
activityViewController.excludedActivityTypes = [UIActivityTypePrint, UIActivityTypePostToVimeo, UIActivityTypePostToFacebook]
activityViewController.excludedActivityTypes = [UIActivityTypePrint, UIActivityTypePostToVimeo]

// Pop style on iPad
if let actv = activityViewController.popoverPresentationController {
Expand All @@ -852,7 +857,7 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio

// MARK: - ScrollView Delegate

func scrollViewWillBeginDragging(scrollView: UIScrollView) {
public func scrollViewWillBeginDragging(scrollView: UIScrollView) {
isScrolling = true
clearRecentlyScrolled()
recentlyScrolled = true
Expand All @@ -866,7 +871,7 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio
scrollScrubber.scrollViewWillBeginDragging(scrollView)
}

func scrollViewDidScroll(scrollView: UIScrollView) {
public func scrollViewDidScroll(scrollView: UIScrollView) {

if !navigationController!.navigationBarHidden {
toggleBars()
Expand Down Expand Up @@ -904,7 +909,7 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio
pageScrollDirection = scrollView.contentOffset.forDirection() < pointNow.forDirection() ? .negative() : .positive()
}

func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
public func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
isScrolling = false

if (readerConfig.scrollDirection == .horizontalWithVerticalContent),
Expand All @@ -920,7 +925,7 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio
scrollScrubber.scrollViewDidEndDecelerating(scrollView)
}

func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) {
public func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) {
recentlyScrolledTimer = NSTimer(timeInterval:recentlyScrolledDelay, target: self, selector: #selector(FolioReaderCenter.clearRecentlyScrolled), userInfo: nil, repeats: false)
NSRunLoop.currentRunLoop().addTimer(recentlyScrolledTimer, forMode: NSRunLoopCommonModes)
}
Expand All @@ -933,7 +938,7 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio
recentlyScrolled = false
}

func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) {
public func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) {
scrollScrubber.scrollViewDidEndScrollingAnimation(scrollView)
}

Expand Down Expand Up @@ -1007,6 +1012,15 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio
menu.transitioningDelegate = animator
presentViewController(menu, animated: true, completion: nil)
}

/**
Present Quote Share
*/
func presentQuoteShare(string: String) {
let quoteShare = FolioReaderQuoteShare(initWithText: string)
let nav = UINavigationController(rootViewController: quoteShare)
presentViewController(nav, animated: true, completion: nil)
}
}

// MARK: FolioPageDelegate
Expand Down
18 changes: 17 additions & 1 deletion Source/FolioReaderConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ public class FolioReaderConfig: NSObject {
/// Enable TTS (Text To Speech)
public var enableTTS = true

// MARK: Quote image share

/// Custom Quote logo
public var quoteCustomLogoImage = UIImage(readerImageNamed: "icon-logo")

/// Add custom backgrounds and font colors to Quote Images
public var quoteCustomBackgrounds = [QuoteImage]()

/// Enable or disable default Quote Image backgrounds
public var quotePreserveDefaultBackgrounds = true

// MARK: Localized strings

/// Localizes Highlight title
Expand All @@ -113,9 +124,14 @@ public class FolioReaderConfig: NSObject {
public var localizedReaderManyMinutes = NSLocalizedString("minutes", comment: "")
public var localizedReaderOneMinute = NSLocalizedString("1 minute", comment: "")
public var localizedReaderLessThanOneMinute = NSLocalizedString("Less than a minute", comment: "")
public var localizedShareWebLink: String? = nil
public var localizedShareWebLink: NSURL? = nil
public var localizedShareChapterSubject = NSLocalizedString("Check out this chapter from", comment: "")
public var localizedShareHighlightSubject = NSLocalizedString("Notes from", comment: "")
public var localizedShareAllExcerptsFrom = NSLocalizedString("All excerpts from", comment: "")
public var localizedShareBy = NSLocalizedString("by", comment: "")
public var localizedCancel = NSLocalizedString("Cancel", comment: "")
public var localizedChooseExisting = NSLocalizedString("Choose existing", comment: "")
public var localizedTakePhoto = NSLocalizedString("Take Photo", comment: "")
public var localizedShareImageQuote = NSLocalizedString("Share image quote", comment: "")
public var localizedShareTextQuote = NSLocalizedString("Share text quote", comment: "")
}
1 change: 1 addition & 0 deletions Source/FolioReaderContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public class FolioReaderContainer: UIViewController {
self.centerViewController.reloadData()

FolioReader.isReaderReady = true
FolioReader.sharedInstance.delegate?.folioReader?(FolioReader.sharedInstance, didFinishedLoading: book)
})
}
})
Expand Down
Loading

0 comments on commit f37cd05

Please sign in to comment.