Skip to content

Commit

Permalink
Merge pull request #1161 from NYPL-Simplified/release/3.5.0
Browse files Browse the repository at this point in the history
Merge 3.5.0 release into master
  • Loading branch information
ettore authored Aug 7, 2020
2 parents 2b75b03 + 7ae0fe2 commit aeb0731
Show file tree
Hide file tree
Showing 36 changed files with 1,900 additions and 483 deletions.
3 changes: 2 additions & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
binary "Crashlytics.json"
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAnalyticsBinary.json"
github "NYPL-Simplified/CardCreator-iOS" ~> 1.1.2
github "NYPL-Simplified/CardCreator-iOS" ~> 1.2
github "NYPL-Simplified/NYPLAEToolkit" "master"
github "NYPL-Simplified/NYPLAudiobookToolkit" "master"
github "PureLayout/PureLayout" ~> 3.1.2
github "TheLevelUp/ZXingObjC" ~> 3.3
github "stephencelis/SQLite.swift" ~> 0.11.5
github "NYPL-Simplified/PDFRendererProvider-iOS" "master"
github "NYPL-Simplified/audiobook-ios-overdrive" "master"
7 changes: 4 additions & 3 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
binary "Crashlytics.json" "3.14.0"
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAnalyticsBinary.json" "6.24.0"
github "NYPL-Simplified/CardCreator-iOS" "v1.1.2"
github "NYPL-Simplified/NYPLAEToolkit" "038b7de4fcc777542eedffdb6427087c3f5799a7"
github "NYPL-Simplified/NYPLAudiobookToolkit" "d43d64389810a519ba3cdf8fbc63bd59e2635d3d"
github "NYPL-Simplified/CardCreator-iOS" "v1.2"
github "NYPL-Simplified/NYPLAEToolkit" "bc5be6813632a7c634864279f2167acb720b219b"
github "NYPL-Simplified/NYPLAudiobookToolkit" "e6f0579f7a083d53869a89d0de8c508951078eff"
github "NYPL-Simplified/PDFRendererProvider-iOS" "b0ee13aa74e0d88193a401c29624dda8120a340d"
github "NYPL-Simplified/audiobook-ios-overdrive" "57ef24851243b63bd6a464716ecda6efadd26d73"
github "PureLayout/PureLayout" "v3.1.6"
github "TheLevelUp/ZXingObjC" "3.6.4"
github "stephencelis/SQLite.swift" "0.11.6"
712 changes: 703 additions & 9 deletions Simplified.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1140"
version = "1.7">
<BuildAction
parallelizeBuildables = "NO"
Expand Down Expand Up @@ -98,6 +98,11 @@
value = "99999"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "DYLD_PRINT_STATISTICS"
value = "1"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
<AdditionalOption
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7347F036245A4DE200558D7F"
BuildableName = "SimplyE.app"
BlueprintName = "SimplyECardCreator"
ReferencedContainer = "container:Simplified.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7347F036245A4DE200558D7F"
BuildableName = "SimplyE.app"
BlueprintName = "SimplyECardCreator"
ReferencedContainer = "container:Simplified.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7347F036245A4DE200558D7F"
BuildableName = "SimplyE.app"
BlueprintName = "SimplyECardCreator"
ReferencedContainer = "container:Simplified.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
76 changes: 48 additions & 28 deletions Simplified/AccountsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,13 @@ private let prodUrlHash = prodUrl.absoluteString.md5().base64EncodedStringUrlSaf
/// Initialized with JSON.
@objcMembers final class AccountsManager: NSObject
{
struct LoadOptions: OptionSet {
let rawValue: Int

// Cache control
static let preferCache = LoadOptions(rawValue: 1 << 0)
static let cacheOnly = LoadOptions(rawValue: 1 << 1)
static let noCache = LoadOptions(rawValue: 1 << 2)

static let online: LoadOptions = []
static let strict_online: LoadOptions = [.noCache]
static let offline: LoadOptions = [.preferCache]
static let strict_offline: LoadOptions = [.preferCache, .cacheOnly]
}

static let NYPLAccountUUIDs = [
"urn:uuid:065c0c11-0d0f-42a3-82e4-277b18786949",
"urn:uuid:edef2358-9f6a-4ce6-b64f-9b351ec68ac4",
"urn:uuid:56906f26-2c9a-4ae9-bd02-552557720b99"
"urn:uuid:065c0c11-0d0f-42a3-82e4-277b18786949", //NYPL proper
"urn:uuid:edef2358-9f6a-4ce6-b64f-9b351ec68ac4", //Brooklyn
"urn:uuid:56906f26-2c9a-4ae9-bd02-552557720b99" //Simplified Instant Classics
]

static let NYPLAccountUUID = NYPLAccountUUIDs[0]

static let shared = AccountsManager()

Expand All @@ -39,11 +27,17 @@ private let prodUrlHash = prodUrl.absoluteString.md5().base64EncodedStringUrlSaf
return shared
}

var accountSet: String
private var accountSet: String
private var accountSets = [String: [Account]]()
private var accountSetsWorkQueue = DispatchQueue(label: "org.nypl.labs.SimplyE.AccountsManager.workQueue", attributes: .concurrent)

var accountsHaveLoaded: Bool {
if let accounts = accountSets[accountSet] {
var accounts: [Account]?
accountSetsWorkQueue.sync {
accounts = accountSets[accountSet]
}

if let accounts = accounts {
return !accounts.isEmpty
}
return false
Expand Down Expand Up @@ -139,7 +133,9 @@ private let prodUrlHash = prodUrl.absoluteString.md5().base64EncodedStringUrlSaf
let catalogsFeed = try OPDS2CatalogsFeed.fromData(data)
let hadAccount = self.currentAccount != nil

self.accountSets[key] = catalogsFeed.catalogs.map { Account(publication: $0) }
accountSetsWorkQueue.sync(flags: .barrier) {
accountSets[key] = catalogsFeed.catalogs.map { Account(publication: $0) }
}

// note: `currentAccount` computed property feeds off of `accountSets`, so
// changing the `accountsSets` dictionary will also change `currentAccount`
Expand Down Expand Up @@ -217,39 +213,63 @@ private let prodUrlHash = prodUrl.absoluteString.md5().base64EncodedStringUrlSaf
NotificationCenter.default.post(name: NSNotification.Name.NYPLCatalogDidLoad, object: nil)
}
case .failure(let error):
NYPLErrorLogger.logError(error,
message: "Catalog failed to load from \(targetUrl)")
NYPLErrorLogger.logError(
withCode: .libraryListLoadFail,
context: NYPLErrorLogger.Context.accountManagement.rawValue,
message: "Libraries list failed to load from \(targetUrl)",
metadata: [
NSUnderlyingErrorKey: error,
])
self.callAndClearLoadingCompletionHandlers(key: hash, false)
}
}
}

func account(_ uuid:String) -> Account? {
// get accountSets dictionary first for thread-safety
var accountSetsCopy = [String: [Account]]()
var accountSetKey = ""
accountSetsWorkQueue.sync {
accountSetsCopy = self.accountSets
accountSetKey = self.accountSet
}

// Check primary account set first
if let accounts = self.accountSets[self.accountSet] {
if let accounts = accountSetsCopy[accountSetKey] {
if let account = accounts.filter({ $0.uuid == uuid }).first {
return account
}
}

// Check existing account lists
for accountEntry in self.accountSets {
if accountEntry.key == self.accountSet {
for accountEntry in accountSetsCopy {
if accountEntry.key == accountSetKey {
continue
}
if let account = accountEntry.value.filter({ $0.uuid == uuid }).first {
return account
}
}

return nil
}

func accounts(_ key: String? = nil) -> [Account] {
let k = key != nil ? key! : self.accountSet
return self.accountSets[k] ?? []
var accounts: [Account]? = []

accountSetsWorkQueue.sync {
let k = key ?? self.accountSet
accounts = self.accountSets[k]
}

return accounts ?? []
}

func updateAccountSet(completion: @escaping (Bool) -> () = { _ in }) {
self.accountSet = NYPLSettings.shared.useBetaLibraries ? betaUrlHash : prodUrlHash
accountSetsWorkQueue.sync(flags: .barrier) {
self.accountSet = NYPLSettings.shared.useBetaLibraries ? betaUrlHash : prodUrlHash
}

if self.accounts().isEmpty {
loadCatalogs(completion: completion)
}
Expand Down
Loading

0 comments on commit aeb0731

Please sign in to comment.