Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d261c54
Initial SwiftUI, tab bar with basic content
stevenzeck May 16, 2022
05874e9
Add license info to new files, clean up About tab contents
stevenzeck May 17, 2022
7359773
Start book cover and bookshelf
stevenzeck May 20, 2022
06703aa
Display books from db
stevenzeck May 21, 2022
6df9aa5
Add add icon button to toolbars
stevenzeck May 24, 2022
77a749f
Use db for OPDS feeds
stevenzeck May 25, 2022
571a211
Switch to using ViewModel
stevenzeck May 26, 2022
30de323
Use async/await for database
stevenzeck Jun 1, 2022
c248ee9
Add new function to parse OPDS URL async
stevenzeck Jun 2, 2022
49f7581
Show sheet for adding a book
stevenzeck Jun 3, 2022
2ad2236
Sheet for adding OPDS feed, file cleanup
stevenzeck Jun 3, 2022
ee4622a
Refactor dependency management with `Container`
mickael-menu Jun 3, 2022
6b184d3
Start making suggested changes
stevenzeck Jun 5, 2022
f8750b0
Make suggested changes
stevenzeck Jun 5, 2022
ac903cc
Add initial SQL database migration
mickael-menu Jun 6, 2022
fdbb68f
Fix file headers
mickael-menu Jun 6, 2022
daedf2b
Bump deployment targets
mickael-menu Jun 6, 2022
72636b1
Update Carthage project
mickael-menu Jun 6, 2022
58a9ec7
Fix deployment target
mickael-menu Jun 6, 2022
24caa2f
Revert preloading catalogs with UIKit
mickael-menu Jun 7, 2022
d56bc89
Change buttons for sheet, add catalog from URL
stevenzeck Jun 8, 2022
29fb01f
Change button placement on add book sheet
stevenzeck Jun 9, 2022
6d4cd9a
Make suggested changes
stevenzeck Jun 10, 2022
7a5f2ee
Refactor button creation
mickael-menu Jun 11, 2022
5cc16b7
Merge branch 'swiftui' of github.com:readium/swift-toolkit into swiftui
mickael-menu Jun 11, 2022
d7cc9f5
Fix database async accesses
mickael-menu Jun 11, 2022
1f01c96
Minor API renames
mickael-menu Jun 11, 2022
45c3651
Refactor usage of `ValueObservation`
mickael-menu Jun 11, 2022
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
39 changes: 0 additions & 39 deletions Sources/OPDS/Deprecated.swift

This file was deleted.

24 changes: 23 additions & 1 deletion Sources/OPDS/OPDSParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,27 @@ public class OPDSParser {
}
}.resume()
}


#if compiler(>=5.5) && canImport(_Concurrency)

/// Asynchronously Parse an OPDS feed or publication.
/// Feed can be v1 (XML) or v2 (JSON).
/// - parameter url: The feed URL
@available(iOS 13.0, *)
public static func parseURL(url: URL) async throws -> ParseData {
try await withCheckedThrowingContinuation { continuation in
parseURL(url: url) { data, error in
if let error = error {
continuation.resume(with: .failure(error))
} else if let data = data {
continuation.resume(with: .success(data))
} else {
continuation.resume(with: .failure(OPDSParserError.documentNotValid))
}
}
}
}

#endif

}
3,239 changes: 3,127 additions & 112 deletions Support/Carthage/.xcodegen

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions Support/Carthage/Readium.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
5A40B83CF103A9102DF233E2 /* LoggerStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72922E22040CEFB3B7BBCDAF /* LoggerStub.swift */; };
5B166084DFB7FF0DFD1D111B /* OPDSPrice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C22408FE1FA81400DE8D5F7 /* OPDSPrice.swift */; };
5B38F9D78BD04D7385E4B3E4 /* UserRights.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567C115FF0939F69AD83AE82 /* UserRights.swift */; };
5BF07D73985075F71E70F5D3 /* Deprecated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1225F795A69CCB10692A56B5 /* Deprecated.swift */; };
5C051B93B795D76666F4344B /* Metadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01B24895126F2A744A8E9E61 /* Metadata.swift */; };
5C8ED4151A6C7EF6608A03F8 /* AudioSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9ECD1D0BE2C4BB5B58E32BFD /* AudioSession.swift */; };
5C9617AE1B5678A95ABFF1AA /* Link.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF92954C8C8C3EC50C835CBA /* Link.swift */; };
Expand Down Expand Up @@ -350,7 +349,6 @@
10CFCE63856A801FB14A0633 /* Deferred.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Deferred.swift; sourceTree = "<group>"; };
10FB29EDCCE5910C869295F1 /* Either.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Either.swift; sourceTree = "<group>"; };
11252900E9B0827C0FD2FA4B /* Database.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Database.swift; sourceTree = "<group>"; };
1225F795A69CCB10692A56B5 /* Deprecated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Deprecated.swift; sourceTree = "<group>"; };
125BAF5FDFA097BA5CC63539 /* StringExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = "<group>"; };
15980B67505AAF10642B56C8 /* LicenseContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LicenseContainer.swift; sourceTree = "<group>"; };
17D22986A3ADE9E883691EE2 /* Deferred.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Deferred.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1043,7 +1041,6 @@
6AC2BCCC17BAA1F2AD19B5FF /* OPDS */ = {
isa = PBXGroup;
children = (
1225F795A69CCB10692A56B5 /* Deprecated.swift */,
34B5C938E4973406F110F2E6 /* OPDS1Parser.swift */,
9935832F8ECA0AB7A7A486FC /* OPDS2Parser.swift */,
07B5469E40752E598C070E5B /* OPDSParser.swift */,
Expand Down Expand Up @@ -2034,7 +2031,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
5BF07D73985075F71E70F5D3 /* Deprecated.swift in Sources */,
7AEDE3769227C2BDE4876333 /* OPDS1Parser.swift in Sources */,
238F9288A061E26BC1674C4F /* OPDS2Parser.swift in Sources */,
346C4DA09157847639648F56 /* OPDSParser.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/Carthage/project+lcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "15.0"
sources:
- path: Sources
dependencies:
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/Carthage/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "15.0"
sources:
- path: Sources
dependencies:
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/CocoaPods/project+lcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "15.0"
sources:
- path: Sources
settings:
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/CocoaPods/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "15.0"
sources:
- path: Sources
2 changes: 1 addition & 1 deletion TestApp/Integrations/Local/project+lcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "15.0"
sources:
- path: Sources
dependencies:
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/Local/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "15.0"
sources:
- path: Sources
dependencies:
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/SPM/project+lcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "15.0"
sources:
- path: Sources
dependencies:
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/SPM/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ targets:
TestApp:
type: application
platform: iOS
deploymentTarget: "14.0"
deploymentTarget: "15.0"
sources:
- path: Sources
dependencies:
Expand Down
5 changes: 4 additions & 1 deletion TestApp/Sources/App/AppModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ final class AppModule {
}

let httpClient = DefaultHTTPClient()
let db = try Database(file: Paths.library.appendingPathComponent("database.db"))
let db = try Database(
file: Paths.library.appendingPathComponent("database.db"),
migrations: [InitialMigration()]
)
let books = BookRepository(db: db)
let bookmarks = BookmarkRepository(db: db)
let highlights = HighlightRepository(db: db)
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import Combine
import UIKit

@UIApplicationMain
//@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
Expand Down
48 changes: 48 additions & 0 deletions TestApp/Sources/Container.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// Copyright 2022 Readium Foundation. All rights reserved.
// Use of this source code is governed by the BSD-style license
// available in the top-level LICENSE file of the project.
//

import Foundation

class Container {

private let db: Database

init() throws {
self.db = try Database(
file: Paths.library.appendingPathComponent("database.db"),
migrations: [InitialMigration()]
)
}

// Bookshelf

private lazy var bookRepository = BookRepository(db: db)

func bookshelf() -> Bookshelf {
Bookshelf(viewModel: BookshelfViewModel(bookRepository: bookRepository))
}

// Catalogs

private lazy var catalogRepository = CatalogRepository(db: db)

func catalogs() -> Catalogs {
Catalogs(
viewModel: CatalogsViewModel(catalogRepository: catalogRepository),
catalogDetail: catalogDetail(with:)
)
}

func catalogDetail(with catalog: Catalog) -> CatalogDetail {
CatalogDetail(viewModel: CatalogDetailViewModel(catalog: catalog))
}

// About

func about() -> About {
About()
}
}
20 changes: 13 additions & 7 deletions TestApp/Sources/Data/Book.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import GRDB
import R2Shared

struct Book: Codable {
struct Book: Codable, Hashable, Identifiable {
struct Id: EntityId { let rawValue: Int64 }

let id: Id?
Expand Down Expand Up @@ -67,29 +67,35 @@ final class BookRepository {
self.db = db
}

func all() -> AnyPublisher<[Book], Error> {
func save(_ book: inout Book) async throws {
book = try await db.write { [book] db in
try book.saved(db)
}
}

func all() -> AnyPublisher<[Book], Never> {
db.observe { db in
try Book.order(Book.Columns.created).fetchAll(db)
}
}

func add(_ book: Book) -> AnyPublisher<Book.Id, Error> {
return db.write { db in
return db.writePublisher { db in
try book.insert(db)
return Book.Id(rawValue: db.lastInsertedRowID)
}.eraseToAnyPublisher()
}

func remove(_ id: Book.Id) -> AnyPublisher<Void, Error> {
db.write { db in try Book.deleteOne(db, key: id) }
db.writePublisher { db in try Book.deleteOne(db, key: id) }
}

func saveProgress(for id: Book.Id, locator: Locator) -> AnyPublisher<Void, Error> {
func saveProgress(for id: Book.Id, locator: Locator) async throws {
guard let json = locator.jsonString else {
return .just(())
return
}

return db.write { db in
try await db.write { db in
try db.execute(literal: """
UPDATE book
SET locator = \(json), progression = \(locator.locations.totalProgression ?? 0)
Expand Down
6 changes: 3 additions & 3 deletions TestApp/Sources/Data/Bookmark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class BookmarkRepository {
self.db = db
}

func all(for bookId: Book.Id) -> AnyPublisher<[Bookmark], Error> {
func all(for bookId: Book.Id) -> AnyPublisher<[Bookmark], Never> {
db.observe { db in
try Bookmark
.filter(Bookmark.Columns.bookId == bookId)
Expand All @@ -54,14 +54,14 @@ final class BookmarkRepository {
}

func add(_ bookmark: Bookmark) -> AnyPublisher<Bookmark.Id, Error> {
return db.write { db in
return db.writePublisher { db in
try bookmark.insert(db)
return Bookmark.Id(rawValue: db.lastInsertedRowID)
}.eraseToAnyPublisher()
}

func remove(_ id: Bookmark.Id) -> AnyPublisher<Void, Error> {
db.write { db in try Bookmark.deleteOne(db, key: id) }
db.writePublisher { db in try Bookmark.deleteOne(db, key: id) }
}
}

Expand Down
52 changes: 52 additions & 0 deletions TestApp/Sources/Data/Catalog.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// Copyright 2022 Readium Foundation. All rights reserved.
// Use of this source code is governed by the BSD-style license
// available in the top-level LICENSE file of the project.
//

import Combine
import Foundation
import GRDB

/// Represents an OPDS catalog.
struct Catalog: Codable, Hashable, Identifiable {
struct Id: EntityId { let rawValue: Int64 }

var id: Id?
var title: String
var url: String
var created: Date

init(id: Id? = nil, title: String, url: String, created: Date = Date()) {
self.id = id
self.title = title
self.url = url
self.created = created
}
}

extension Catalog: TableRecord, FetchableRecord, PersistableRecord {
enum Columns: String, ColumnExpression {
case id, title, url, created
}
}

final class CatalogRepository {
private let db: Database

init(db: Database) {
self.db = db
}

func all() -> AnyPublisher<[Catalog]?, Never> {
db.observe {
try Catalog.order(Catalog.Columns.title).fetchAll($0)
}
}

func save(_ catalog: inout Catalog) async throws {
catalog = try await db.write { [catalog] db in
try catalog.saved(db)
}
}
}
Loading