Skip to content
This repository was archived by the owner on Nov 26, 2020. It is now read-only.
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
16 changes: 8 additions & 8 deletions Source/EPUBCore/FRHighlight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

import UIKit

enum HighlightStyle: Int {
public enum HighlightStyle: Int {
case Yellow
case Green
case Blue
case Pink
case Underline

init () { self = .Yellow }
public init () { self = .Yellow }

/**
Return HighlightStyle for CSS class.
*/
static func styleForClass(className: String) -> HighlightStyle {
public static func styleForClass(className: String) -> HighlightStyle {
switch className {
case "highlight-yellow":
return .Yellow
Expand All @@ -40,7 +40,7 @@ enum HighlightStyle: Int {
/**
Return CSS class for HighlightStyle.
*/
static func classForStyle(style: Int) -> String {
public static func classForStyle(style: Int) -> String {
switch style {
case HighlightStyle.Yellow.rawValue:
return "highlight-yellow"
Expand All @@ -60,7 +60,7 @@ enum HighlightStyle: Int {
/**
Return CSS class for HighlightStyle.
*/
static func colorForStyle(style: Int, nightMode: Bool = false) -> UIColor {
public static func colorForStyle(style: Int, nightMode: Bool = false) -> UIColor {
switch style {
case HighlightStyle.Yellow.rawValue:
return UIColor(red: 255/255, green: 235/255, blue: 107/255, alpha: nightMode ? 0.9 : 1)
Expand All @@ -78,7 +78,7 @@ enum HighlightStyle: Int {
}
}

class FRHighlight: NSObject {
public class FRHighlight: NSObject {
var id: String!
var content: String!
var contentPre: String!
Expand All @@ -91,7 +91,7 @@ class FRHighlight: NSObject {
/**
Match a highlight on string.
*/
static func matchHighlight(text: String!, andId id: String) -> FRHighlight? {
public static func matchHighlight(text: String!, andId id: String) -> FRHighlight? {
let pattern = "<highlight id=\"\(id)\" onclick=\".*?\" class=\"(.*?)\">((.|\\s)*?)</highlight>"
let regex = try! NSRegularExpression(pattern: pattern, options: [])
let matches = regex.matchesInString(text, options: [], range: NSRange(location: 0, length: text.utf16.count))
Expand Down Expand Up @@ -135,7 +135,7 @@ class FRHighlight: NSObject {
return mapped.first
}

static func removeById(highlightId: String) -> String? {
public static func removeById(highlightId: String) -> String? {
let currentPage = FolioReader.sharedInstance.readerCenter.currentPage

if let removedId = currentPage.webView.js("removeHighlightById('\(highlightId)')") {
Expand Down
2 changes: 1 addition & 1 deletion Source/FolioReaderFontsMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

class FolioReaderFontsMenu: UIViewController, SMSegmentViewDelegate {
class FolioReaderFontsMenu: UIViewController, SMSegmentViewDelegate, UIGestureRecognizerDelegate {

var menuView: UIView!

Expand Down
2 changes: 1 addition & 1 deletion Source/FolioReaderKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ internal extension UIImage {
}
}

extension UIViewController: UIGestureRecognizerDelegate {
internal extension UIViewController {

func setCloseButton() {
self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(readerImageNamed: "icon-close"), style: UIBarButtonItemStyle.Plain, target: self, action:#selector(UIViewController.dismiss))
Expand Down
2 changes: 1 addition & 1 deletion Source/FolioReaderPlayerMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

class FolioReaderPlayerMenu: UIViewController, SMSegmentViewDelegate {
class FolioReaderPlayerMenu: UIViewController, SMSegmentViewDelegate, UIGestureRecognizerDelegate {

var menuView: UIView!
var playPauseBtn: UIButton!
Expand Down
23 changes: 23 additions & 0 deletions Source/Models/Highlight+Properties.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Highlight+Properties.swift
// FolioReaderKit
//
// Created by Heberti Almeida on 06/07/16.
// Copyright (c) 2015 Folio Reader. All rights reserved.
//

import Foundation
import CoreData

public extension Highlight {

@NSManaged public var bookId: String
@NSManaged public var content: String
@NSManaged public var contentPost: String
@NSManaged public var contentPre: String
@NSManaged public var date: NSDate
@NSManaged public var highlightId: String
@NSManaged public var page: NSNumber
@NSManaged public var type: NSNumber

}
73 changes: 48 additions & 25 deletions Source/Models/Highlight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,53 @@
import Foundation
import CoreData

@objc(Highlight)
class Highlight: NSManagedObject {

@NSManaged var bookId: String
@NSManaged var content: String
@NSManaged var contentPost: String
@NSManaged var contentPre: String
@NSManaged var date: NSDate
@NSManaged var highlightId: String
@NSManaged var page: NSNumber
@NSManaged var type: NSNumber

}

public typealias Completion = (error: NSError?) -> ()
let coreDataManager = CoreDataManager()

extension Highlight {
@objc(Highlight)
public class Highlight: NSManagedObject {

public func persist(completion: Completion?) {
var highlight: Highlight?

do {
let fetchRequest = NSFetchRequest(entityName: "Highlight")
fetchRequest.predicate = NSPredicate(format:"highlightId = %@", highlightId)
highlight = try coreDataManager.managedObjectContext.executeFetchRequest(fetchRequest).last as? Highlight
} catch let error as NSError {
print(error)
highlight = nil
}

if highlight != nil {
highlight!.content = content
highlight!.contentPre = contentPre
highlight!.contentPost = contentPost
highlight!.date = date
highlight!.type = type
} else {
highlight = NSEntityDescription.insertNewObjectForEntityForName("Highlight", inManagedObjectContext: coreDataManager.managedObjectContext) as? Highlight

highlight!.bookId = bookId
highlight!.content = content
highlight!.contentPre = contentPre
highlight!.contentPost = contentPost
highlight!.date = date
highlight!.highlightId = highlightId
highlight!.page = page
highlight!.type = type
}

// Save
do {
try coreDataManager.managedObjectContext.save()
completion?(error: nil)
} catch let error as NSError {
completion?(error: error)
}
}

static func persistHighlight(object: FRHighlight, completion: Completion?) {
public static func persistHighlight(object: FRHighlight, completion: Completion?) {
var highlight: Highlight?

do {
Expand Down Expand Up @@ -63,17 +90,13 @@ extension Highlight {
// Save
do {
try coreDataManager.managedObjectContext.save()
if (completion != nil) {
completion!(error: nil)
}
completion?(error: nil)
} catch let error as NSError {
if (completion != nil) {
completion!(error: error)
}
completion?(error: error)
}
}

static func removeById(highlightId: String) {
public static func removeById(highlightId: String) {
var highlight: Highlight?

do {
Expand All @@ -88,7 +111,7 @@ extension Highlight {
}
}

static func updateById(highlightId: String, type: HighlightStyle) {
public static func updateById(highlightId: String, type: HighlightStyle) {
var highlight: Highlight?

do {
Expand All @@ -103,7 +126,7 @@ extension Highlight {
}
}

static func allByBookId(bookId: String, andPage page: NSNumber? = nil) -> [Highlight] {
public static func allByBookId(bookId: String, andPage page: NSNumber? = nil) -> [Highlight] {
var highlights: [Highlight]?
let predicate = (page != nil) ? NSPredicate(format: "bookId = %@ && page = %@", bookId, page!) : NSPredicate(format: "bookId = %@", bookId)

Expand Down