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

Issue [#94] migrate to realm #95

Merged
merged 5 commits into from
Jul 12, 2016
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
96 changes: 96 additions & 0 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,15 @@
isa = PBXNativeTarget;
buildConfigurationList = 1A42C29B1C0E3883000F2137 /* Build configuration list for PBXNativeTarget "Example" */;
buildPhases = (
6BB4B87019CBF22A26D57251 /* 📦 Check Pods Manifest.lock */,
BFF78AC0EC7FAA2ADF7765C4 /* [CP] Check Pods Manifest.lock */,
1A42C2851C0E3882000F2137 /* Sources */,
1A42C2861C0E3882000F2137 /* Frameworks */,
1A42C2871C0E3882000F2137 /* Resources */,
B6A166DC30D64CDC32736E22 /* [CP] Embed Pods Frameworks */,
8F716768EB59E9B6D88C48D7 /* [CP] Copy Pods Resources */,
52EDD0255393518C859DA01C /* 📦 Embed Pods Frameworks */,
EF9B4ADBBC85CBF81E88F153 /* 📦 Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -178,12 +181,15 @@
isa = PBXNativeTarget;
buildConfigurationList = CA10C1381C572A4B0049165D /* Build configuration list for PBXNativeTarget "FolioReaderTests" */;
buildPhases = (
0642B6A6EF0631B5697FC382 /* 📦 Check Pods Manifest.lock */,
1D8126CC73301F2413345444 /* [CP] Check Pods Manifest.lock */,
CA10C12D1C572A4B0049165D /* Sources */,
CA10C12E1C572A4B0049165D /* Frameworks */,
CA10C12F1C572A4B0049165D /* Resources */,
C1392FF51E4FD15EBB5AA8DD /* [CP] Embed Pods Frameworks */,
652A7706A17894A2B0BA1503 /* [CP] Copy Pods Resources */,
E82F486563C1547E0775A59F /* 📦 Embed Pods Frameworks */,
064D38CE83FACC358B7C0EC8 /* 📦 Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -263,6 +269,36 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
0642B6A6EF0631B5697FC382 /* 📦 Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "📦 Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
064D38CE83FACC358B7C0EC8 /* 📦 Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "📦 Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-FolioReaderTests/Pods-FolioReaderTests-resources.sh\"\n";
showEnvVarsInLog = 0;
};
1D8126CC73301F2413345444 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -278,6 +314,21 @@
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
52EDD0255393518C859DA01C /* 📦 Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "📦 Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Example/Pods-Example-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
652A7706A17894A2B0BA1503 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -293,6 +344,21 @@
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-FolioReaderTests/Pods-FolioReaderTests-resources.sh\"\n";
showEnvVarsInLog = 0;
};
6BB4B87019CBF22A26D57251 /* 📦 Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "📦 Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
8F716768EB59E9B6D88C48D7 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -353,6 +419,36 @@
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-FolioReaderTests/Pods-FolioReaderTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
E82F486563C1547E0775A59F /* 📦 Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "📦 Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-FolioReaderTests/Pods-FolioReaderTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
EF9B4ADBBC85CBF81E88F153 /* 📦 Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "📦 Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Example/Pods-Example-resources.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down
24 changes: 16 additions & 8 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ PODS:
- AEXML
- FontBlaster
- JSQWebViewController
- RealmSwift
- SSZipArchive
- UIMenuItem-CXAImageSupport
- ZFDragableModalTransition
- FontBlaster (2.1.2)
- FontBlaster (2.1.4)
- JSQWebViewController (3.0.0)
- Nimble (4.0.1)
- Nimble (4.1.0)
- Quick (0.9.2)
- SSZipArchive (1.1)
- Realm (1.0.1):
- Realm/Headers (= 1.0.1)
- Realm/Headers (1.0.1)
- RealmSwift (1.0.1):
- Realm (= 1.0.1)
- SSZipArchive (1.3)
- UIMenuItem-CXAImageSupport (0.0.1)
- ZFDragableModalTransition (0.6)

Expand All @@ -26,15 +32,17 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
AEXML: 716fb0a8decba4a3517324a71fee3685b30233d2
FolioReaderKit: 38622e8f80681ed3ab888f0563d85929caa429a4
FontBlaster: 95ebf29a025dbeda4530300099c6f533e805682c
FolioReaderKit: e5e80a3b1d03f4c5b47e36bdb4117b3de73ad9af
FontBlaster: b780f709b8f705638d0c80a1ecdfb23b3077d0a6
JSQWebViewController: eaa6bd68d9e1426ae25ade99c9bbde4c6cdd4120
Nimble: 0f3c8b8b084cda391209c3c5efbb48bedeeb920a
Nimble: 97a0a4cae5124c117115634b2d055d8c97d0af19
Quick: 18d057bc66451eedd5d1c8dc99ba2a5db6e60226
SSZipArchive: de3d215ab73f87db627f81f2ce24f1731e3886c3
Realm: 2e15e39d35b08abb529e212ed5d8af107b5236c8
RealmSwift: d73ea2af08c3676dbdd5e4b669651a0f492162a4
SSZipArchive: 5525196ee195b473dcc4a0d4d2cba98bfa3eb1c1
UIMenuItem-CXAImageSupport: 2945e2af4487414caad801ed8ff6ac8db274e986
ZFDragableModalTransition: 0d294eaaba6edfcb9839595de765f9ca06a4b524

PODFILE CHECKSUM: 7bafcb0eb37bf78bf161a6ebcb80be176777e3a8

COCOAPODS: 1.0.1
COCOAPODS: 1.0.0
3 changes: 2 additions & 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/Images/*.png',
'Source/Resources/Fonts/**/*.{otf,ttf}'
]
s.preserve_paths = 'Source/**/*.xcdatamodeld'
Expand All @@ -37,5 +37,6 @@ Pod::Spec.new do |s|
s.dependency 'AEXML'
s.dependency 'FontBlaster'
s.dependency 'JSQWebViewController'
s.dependency 'RealmSwift'
# s.dependency 'SMSegmentView'
end
8 changes: 6 additions & 2 deletions Source/EPUBCore/FRHighlight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,16 @@ public class FRHighlight: NSObject {
var contentPre: String!
var contentPost: String!
var date: NSDate!
var page: NSNumber!
var page: Int!
var bookId: String!
var type: HighlightStyle!
var startOffset: Int = -1
var endOffset: Int! = -1

/**
Match a highlight on string.
*/
public static func matchHighlight(text: String!, andId id: String) -> FRHighlight? {
public static func matchHighlight(text: String!, andId id: String, startOffset: String, endOffset: 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 @@ -129,6 +131,8 @@ public class FRHighlight: NSObject {
highlight.contentPost = contentPost
highlight.page = currentPageNumber
highlight.bookId = (kBookId as NSString).stringByDeletingPathExtension
highlight.startOffset = Int(startOffset) ?? -1
highlight.endOffset = Int(endOffset) ?? -1

return highlight
}
Expand Down
8 changes: 4 additions & 4 deletions Source/FolioReaderHighlightList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ class FolioReaderHighlightList: UITableViewController {
text.addAttribute(NSFontAttributeName, value: UIFont(name: "Avenir-Light", size: 16)!, range: range)
text.addAttribute(NSForegroundColorAttributeName, value: textColor, range: range)

if highlight.type.integerValue == HighlightStyle.Underline.rawValue {
if highlight.type == HighlightStyle.Underline.rawValue {
text.addAttribute(NSBackgroundColorAttributeName, value: UIColor.clearColor(), range: range)
text.addAttribute(NSUnderlineColorAttributeName, value: HighlightStyle.colorForStyle(highlight.type.integerValue, nightMode: FolioReader.sharedInstance.nightMode), range: range)
text.addAttribute(NSUnderlineColorAttributeName, value: HighlightStyle.colorForStyle(highlight.type, nightMode: FolioReader.sharedInstance.nightMode), range: range)
text.addAttribute(NSUnderlineStyleAttributeName, value: NSNumber(integer: NSUnderlineStyle.StyleSingle.rawValue), range: range)
} else {
text.addAttribute(NSBackgroundColorAttributeName, value: HighlightStyle.colorForStyle(highlight.type.integerValue, nightMode: FolioReader.sharedInstance.nightMode), range: range)
text.addAttribute(NSBackgroundColorAttributeName, value: HighlightStyle.colorForStyle(highlight.type, nightMode: FolioReader.sharedInstance.nightMode), range: range)
}

// Text
Expand Down Expand Up @@ -143,7 +143,7 @@ class FolioReaderHighlightList: UITableViewController {
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let highlight = highlights[indexPath.row]

FolioReader.sharedInstance.readerCenter.changePageWith(page: highlight.page.integerValue, andFragment: highlight.highlightId)
FolioReader.sharedInstance.readerCenter.changePageWith(page: highlight.page, andFragment: highlight.highlightId)

dismissViewControllerAnimated(true, completion: nil)
}
Expand Down
8 changes: 6 additions & 2 deletions Source/FolioReaderKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ enum MediaOverlayStyle: Int {
* Main Library class with some useful constants and methods
*/
public class FolioReader : NSObject {
private override init() {}

static let sharedInstance = FolioReader()
static let defaults = NSUserDefaults.standardUserDefaults()
weak var readerCenter: FolioReaderCenter!
Expand All @@ -65,6 +63,12 @@ public class FolioReader : NSObject {
var isReaderOpen = false
var isReaderReady = false

private override init() {
let isMigrated = NSUserDefaults.standardUserDefaults().boolForKey("isMigrated")
if !isMigrated {
Highlight.migrateUserDataToRealm()
}
}

var nightMode: Bool {
get { return FolioReader.defaults.boolForKey(kNightMode) }
Expand Down
8 changes: 5 additions & 3 deletions Source/FolioReaderPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRecogni

if highlights.count > 0 {
for item in highlights {
let style = HighlightStyle.classForStyle(item.type.integerValue)
let style = HighlightStyle.classForStyle(item.type)
let tag = "<highlight id=\"\(item.highlightId)\" onclick=\"callHighlightURL(this);\" class=\"\(style)\">\(item.content)</highlight>"
let locator = item.contentPre + item.content + item.contentPost
let range: NSRange = html.rangeOfString(locator, options: .LiteralSearch)
Expand Down Expand Up @@ -551,6 +551,8 @@ extension UIWebView {
let json = try NSJSONSerialization.JSONObjectWithData(jsonData!, options: []) as! NSArray
let dic = json.firstObject as! [String: String]
let rect = CGRectFromString(dic["rect"]!)
let startOffset = dic["startOffset"]!
let endOffset = dic["endOffset"]!

// Force remove text selection
userInteractionEnabled = false
Expand All @@ -561,8 +563,8 @@ extension UIWebView {

// Persist
let html = js("getHTML()")
if let highlight = FRHighlight.matchHighlight(html, andId: dic["id"]!) {
Highlight.persistHighlight(highlight, completion: nil)
if let highlight = FRHighlight.matchHighlight(html, andId: dic["id"]!, startOffset: startOffset, endOffset: endOffset) {
Highlight.persistHighlight(highlight)
}
} catch {
print("Could not receive JSON")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="9057" systemVersion="15B42" minimumToolsVersion="Xcode 7.0">
<entity name="Highlight" representedClassName="Highlight" syncable="YES">
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="10171" systemVersion="15F34" minimumToolsVersion="Xcode 7.0">
<entity name="Highlight" representedClassName="" syncable="YES">
<attribute name="bookId" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="content" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="contentPost" optional="YES" attributeType="String" syncable="YES"/>
Expand Down
12 changes: 1 addition & 11 deletions Source/Models/Highlight+Properties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,7 @@
//

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
extension Highlight {

}
Loading