Skip to content
This repository was archived by the owner on Aug 12, 2022. It is now read-only.

Commit 0c713d1

Browse files
committed
Use Book.id instead of publication identifier for the Bookmark DB, to work with publication without identifiers
1 parent c600cfc commit 0c713d1

File tree

10 files changed

+36
-28
lines changed

10 files changed

+36
-28
lines changed

r2-testapp-swift.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,7 @@
16721672
"$(inherited)",
16731673
"$(PROJECT_DIR)",
16741674
);
1675-
MARKETING_VERSION = 2.1.0;
1675+
MARKETING_VERSION = "2.2.0-alpha.1";
16761676
OTHER_LDFLAGS = "-lxml2";
16771677
OTHER_SWIFT_FLAGS = "-DLCP";
16781678
PRODUCT_BUNDLE_IDENTIFIER = org.readium.r2reader;
@@ -1709,7 +1709,7 @@
17091709
"$(inherited)",
17101710
"$(PROJECT_DIR)",
17111711
);
1712-
MARKETING_VERSION = 2.1.0;
1712+
MARKETING_VERSION = "2.2.0-alpha.1";
17131713
OTHER_LDFLAGS = "-lxml2";
17141714
OTHER_SWIFT_FLAGS = "-DLCP";
17151715
PRODUCT_BUNDLE_IDENTIFIER = org.readium.r2reader;

r2-testapp-swift.xcodeproj/xcshareddata/xcschemes/r2-testapp-swift (submodules-with-lcp).xcscheme

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
2929
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
3032
<MacroExpansion>
3133
<BuildableReference
3234
BuildableIdentifier = "primary"
@@ -36,8 +38,10 @@
3638
ReferencedContainer = "container:r2-testapp-swift.xcodeproj">
3739
</BuildableReference>
3840
</MacroExpansion>
39-
<Testables>
40-
</Testables>
41+
<AdditionalOptions>
42+
</AdditionalOptions>
43+
<CodeCoverageTargets>
44+
</CodeCoverageTargets>
4145
</TestAction>
4246
<LaunchAction
4347
buildConfiguration = "Debug"
@@ -59,6 +63,8 @@
5963
ReferencedContainer = "container:r2-testapp-swift.xcodeproj">
6064
</BuildableReference>
6165
</BuildableProductRunnable>
66+
<AdditionalOptions>
67+
</AdditionalOptions>
6268
</LaunchAction>
6369
<ProfileAction
6470
buildConfiguration = "Release"

r2-testapp-swift/Reader/CBZ/CBZViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ class CBZViewController: ReaderViewController {
3333
}
3434

3535
override var currentBookmark: Bookmark? {
36-
guard let publicationID = publication.metadata.identifier,
36+
guard
3737
let locator = navigator.currentLocation,
3838
let resourceIndex = publication.readingOrder.firstIndex(withHref: locator.href) else
3939
{
4040
return nil
4141
}
4242

4343
return Bookmark(
44-
publicationID: publicationID,
44+
bookID: book.id,
4545
resourceIndex: resourceIndex,
4646
locator: locator
4747
)

r2-testapp-swift/Reader/Common/Bookmark/Bookmark.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import R2Shared
1616
public class Bookmark {
1717

1818
public var id: Int64?
19-
public var publicationID: String
19+
public var bookID: Int64
2020
public var resourceIndex: Int
2121
public var locator: Locator
2222
public var creationDate: Date
2323

24-
public init(id: Int64? = nil, publicationID: String, resourceIndex: Int, locator: Locator, creationDate: Date = Date()) {
24+
public init(id: Int64? = nil, bookID: Int64, resourceIndex: Int, locator: Locator, creationDate: Date = Date()) {
2525
self.id = id
26-
self.publicationID = publicationID
26+
self.bookID = bookID
2727
self.resourceIndex = resourceIndex
2828
self.locator = locator
2929
self.creationDate = creationDate

r2-testapp-swift/Reader/Common/Bookmark/BookmarkDataSource.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ import R2Shared
1515

1616
class BookmarkDataSource: Loggable {
1717

18-
let publicationID :String?
18+
let bookID: Int64?
1919
private(set) var bookmarks = [Bookmark]()
2020

2121
init() {
22-
self.publicationID = nil
22+
self.bookID = nil
2323
self.reloadBookmarks()
2424
}
2525

26-
init(publicationID: String) {
27-
self.publicationID = publicationID
26+
init(bookID: Int64) {
27+
self.bookID = bookID
2828
self.reloadBookmarks()
2929
}
3030

3131
func reloadBookmarks() {
32-
if let list = try? BookmarkDatabase.shared.bookmarks.bookmarkList(for: self.publicationID) {
32+
if let list = try? BookmarkDatabase.shared.bookmarks.bookmarkList(for: self.bookID) {
3333
self.bookmarks = list
3434
self.bookmarks.sort { (b1, b2) -> Bool in
3535
if b1.resourceIndex == b2.resourceIndex {

r2-testapp-swift/Reader/Common/Bookmark/BookmarkDatabase.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class BookmarksTable {
4545
let tableName = Table("BOOKMARKS")
4646

4747
let bookmarkID = Expression<Int64>("id")
48-
let publicationID = Expression<String>("publicationID")
48+
let bookID = Expression<Int64>("bookID")
4949

5050
let resourceIndex = Expression<Int>("resourceIndex")
5151
let resourceHref = Expression<String>("resourceHref")
@@ -70,7 +70,7 @@ class BookmarksTable {
7070
_ = try? connection.run(tableName.create(temporary: false, ifNotExists: true) { t in
7171
t.column(bookmarkID, primaryKey: PrimaryKey.autoincrement)
7272
t.column(creationDate)
73-
t.column(publicationID)
73+
t.column(bookID)
7474
t.column(resourceHref)
7575
t.column(resourceIndex)
7676
t.column(resourceType)
@@ -83,7 +83,7 @@ class BookmarksTable {
8383
func insert(newBookmark: Bookmark) throws -> Int64? {
8484
let db = BookmarkDatabase.shared.connection
8585

86-
let bookmark = tableName.filter(self.publicationID == newBookmark.publicationID && self.resourceHref == newBookmark.locator.href && self.resourceIndex == newBookmark.resourceIndex && self.locations == (newBookmark.locator.locations.jsonString ?? ""))
86+
let bookmark = tableName.filter(self.bookID == newBookmark.bookID && self.resourceHref == newBookmark.locator.href && self.resourceIndex == newBookmark.resourceIndex && self.locations == (newBookmark.locator.locations.jsonString ?? ""))
8787

8888
// Check if empty.
8989
guard try db.count(bookmark) == 0 else {
@@ -92,7 +92,7 @@ class BookmarksTable {
9292

9393
let insertQuery = tableName.insert(
9494
creationDate <- newBookmark.creationDate,
95-
publicationID <- newBookmark.publicationID,
95+
bookID <- newBookmark.bookID,
9696
resourceHref <- newBookmark.locator.href,
9797
resourceIndex <- newBookmark.resourceIndex,
9898
resourceType <- newBookmark.locator.type,
@@ -121,7 +121,7 @@ class BookmarksTable {
121121
return true
122122
}
123123

124-
func bookmarkList(for publicationID:String?=nil, resourceIndex:Int?=nil) throws -> [Bookmark]? {
124+
func bookmarkList(for bookID: Int64? = nil, resourceIndex: Int? = nil) throws -> [Bookmark]? {
125125

126126
let db = BookmarkDatabase.shared.connection
127127
// Check if empty.
@@ -130,12 +130,12 @@ class BookmarksTable {
130130
}
131131

132132
let resultList = try { () -> AnySequence<Row> in
133-
if let fetchingID = publicationID {
133+
if let fetchingID = bookID {
134134
if let fetchingIndex = resourceIndex {
135-
let query = self.tableName.filter(self.publicationID == fetchingID && self.resourceIndex == fetchingIndex)
135+
let query = self.tableName.filter(self.bookID == fetchingID && self.resourceIndex == fetchingIndex)
136136
return try db.prepare(query)
137137
}
138-
let query = self.tableName.filter(self.publicationID == fetchingID)
138+
let query = self.tableName.filter(self.bookID == fetchingID)
139139
return try db.prepare(query)
140140
}
141141
return try db.prepare(self.tableName)
@@ -144,7 +144,7 @@ class BookmarksTable {
144144
return resultList.map { row in
145145
Bookmark(
146146
id: row[self.bookmarkID],
147-
publicationID: row[self.publicationID],
147+
bookID: row[self.bookID],
148148
resourceIndex: row[self.resourceIndex],
149149
locator: Locator(
150150
href: row[self.resourceHref],

r2-testapp-swift/Reader/Common/ReaderViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ReaderViewController: UIViewController, Loggable {
2828
let book: Book
2929
let drm: DRM?
3030

31-
lazy var bookmarksDataSource: BookmarkDataSource? = BookmarkDataSource(publicationID: publication.metadata.identifier ?? "")
31+
lazy var bookmarksDataSource: BookmarkDataSource? = BookmarkDataSource(bookID: book.id)
3232

3333
private(set) var stackView: UIStackView!
3434
private lazy var positionLabel = UILabel()

r2-testapp-swift/Reader/EPUB/EPUBViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ class EPUBViewController: ReaderViewController {
8888
}
8989

9090
override var currentBookmark: Bookmark? {
91-
guard let publicationID = publication.metadata.identifier,
91+
guard
9292
let locator = navigator.currentLocation,
9393
let resourceIndex = publication.readingOrder.firstIndex(withHref: locator.href) else
9494
{
9595
return nil
9696
}
97-
return Bookmark(publicationID: publicationID, resourceIndex: resourceIndex, locator: locator)
97+
return Bookmark(bookID: book.id, resourceIndex: resourceIndex, locator: locator)
9898
}
9999

100100
@objc func presentUserSettings() {

r2-testapp-swift/Reader/PDF/PDFViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ final class PDFViewController: ReaderViewController {
3131
}
3232

3333
override var currentBookmark: Bookmark? {
34-
guard let publicationID = publication.metadata.identifier,
34+
guard
3535
let locator = navigator.currentLocation,
3636
let resourceIndex = publication.readingOrder.firstIndex(withHref: locator.href) else
3737
{
3838
return nil
3939
}
4040

4141
return Bookmark(
42-
publicationID: publicationID,
42+
bookID: book.id,
4343
resourceIndex: resourceIndex,
4444
locator: locator
4545
)

r2-testapp-swift/r2-testapp-swift-Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,5 +286,7 @@
286286
</dict>
287287
</dict>
288288
</array>
289+
<key>UIFileSharingEnabled</key>
290+
<true/>
289291
</dict>
290292
</plist>

0 commit comments

Comments
 (0)