Book state migrate and update

This commit is contained in:
Chris Li 2016-09-22 15:34:01 -04:00
parent d081c5b1d7
commit bd17336c8f
8 changed files with 29 additions and 28 deletions

View File

@ -38,7 +38,7 @@ class RemoveBookConfirmationAlert: AlertOperation<UIViewController> {
super.init(presentAlertFrom: context) super.init(presentAlertFrom: context)
title = NSLocalizedString("Remove this book?", comment: "Library, Delete Alert") title = NSLocalizedString("Remove this book?", comment: "Library, Delete Alert")
message = NSLocalizedString("This operation is not recoverable. All bookmarks in this book will also be removed!", comment: "Library, Delete Alert") message = NSLocalizedString("Only the zim file will be removed. All bookmarks related to this book will still be kept.", comment: "Library, Delete Alert")
addActionWithTitle(LocalizedStrings.remove, style: .Destructive) { _ in addActionWithTitle(LocalizedStrings.remove, style: .Destructive) { _ in
let operation = RemoveBookOperation(bookID: bookID) let operation = RemoveBookOperation(bookID: bookID)
GlobalQueue.shared.addOperation(operation) GlobalQueue.shared.addOperation(operation)

View File

@ -89,27 +89,22 @@ class LocalBooksController: UITableViewController, NSFetchedResultsControllerDel
// MARK: Other Data Source // MARK: Other Data Source
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
guard tableView.numberOfSections > 1 else {return nil} guard let stateRaw = fetchedResultController.sections?[section].name else {return nil}
guard let languageName = fetchedResultController.sections?[section].name else {return nil} switch stateRaw {
return languageName case "2":
} return LocalizedStrings.local
case "3":
override func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? { return LocalizedStrings.retainedByBookmarks
let sectionIndexTitles = fetchedResultController.sectionIndexTitles case "4":
guard sectionIndexTitles.count > 2 else {return nil} return LocalizedStrings.purgeable
return sectionIndexTitles default:
} return nil
}
override func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int {
return fetchedResultController.sectionForSectionIndexTitle(title, atIndex: index)
} }
// MARK: - Table View Delegate // MARK: - Table View Delegate
override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
guard tableView.numberOfSections > 1 else {return 0.0}
guard let headerText = self.tableView(tableView, titleForHeaderInSection: section) else {return 0.0}
guard headerText != "" else {return 0.0}
return 20.0 return 20.0
} }
@ -143,11 +138,11 @@ class LocalBooksController: UITableViewController, NSFetchedResultsControllerDel
let managedObjectContext = NSManagedObjectContext.mainQueueContext let managedObjectContext = NSManagedObjectContext.mainQueueContext
lazy var fetchedResultController: NSFetchedResultsController = { lazy var fetchedResultController: NSFetchedResultsController = {
let fetchRequest = NSFetchRequest(entityName: "Book") let fetchRequest = NSFetchRequest(entityName: "Book")
let langDescriptor = NSSortDescriptor(key: "language.name", ascending: true) let stateDescriptor = NSSortDescriptor(key: "stateRaw", ascending: true)
let titleDescriptor = NSSortDescriptor(key: "title", ascending: true) let titleDescriptor = NSSortDescriptor(key: "title", ascending: true)
fetchRequest.sortDescriptors = [langDescriptor, titleDescriptor] fetchRequest.sortDescriptors = [stateDescriptor, titleDescriptor]
fetchRequest.predicate = NSPredicate(format: "stateRaw >= 2") fetchRequest.predicate = NSPredicate(format: "stateRaw >= 2")
let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext, sectionNameKeyPath: "language.name", cacheName: "LocalFRC" + NSBundle.buildVersion) let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext, sectionNameKeyPath: "stateRaw", cacheName: "LocalFRC" + NSBundle.buildVersion)
fetchedResultsController.delegate = self fetchedResultsController.delegate = self
fetchedResultsController.performFetch(deleteCache: false) fetchedResultsController.performFetch(deleteCache: false)
return fetchedResultsController return fetchedResultsController
@ -197,5 +192,7 @@ class LocalBooksController: UITableViewController, NSFetchedResultsControllerDel
class LocalizedStrings{ class LocalizedStrings{
static let local = NSLocalizedString("Local", comment: "Library, local tab") static let local = NSLocalizedString("Local", comment: "Library, local tab")
static let remove = NSLocalizedString("Remove", comment: "Library, local tab") static let remove = NSLocalizedString("Remove", comment: "Library, local tab")
static let retainedByBookmarks = NSLocalizedString("Retained by Bookmarks", comment: "Library, local tab")
static let purgeable = NSLocalizedString("Purgeable", comment: "Library, local tab")
} }
} }

View File

@ -75,7 +75,7 @@ class SearchBooksController: UIViewController, UITableViewDelegate, UITableViewD
let langDescriptor = NSSortDescriptor(key: "language.name", ascending: true) let langDescriptor = NSSortDescriptor(key: "language.name", ascending: true)
let titleDescriptor = NSSortDescriptor(key: "title", ascending: true) let titleDescriptor = NSSortDescriptor(key: "title", ascending: true)
fetchRequest.sortDescriptors = [langDescriptor, titleDescriptor] fetchRequest.sortDescriptors = [langDescriptor, titleDescriptor]
fetchRequest.predicate = NSPredicate(format: "isLocal == true") fetchRequest.predicate = NSPredicate(format: "stateRaw == 2")
let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext, sectionNameKeyPath: "language.name", cacheName: "ScopeFRC") let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext, sectionNameKeyPath: "language.name", cacheName: "ScopeFRC")
fetchedResultsController.delegate = self fetchedResultsController.delegate = self
fetchedResultsController.performFetch(deleteCache: false) fetchedResultsController.performFetch(deleteCache: false)

View File

@ -49,7 +49,7 @@
</dict> </dict>
</array> </array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1.8.1070</string> <string>1.8.1089</string>
<key>ITSAppUsesNonExemptEncryption</key> <key>ITSAppUsesNonExemptEncryption</key>
<false/> <false/>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>

View File

@ -21,7 +21,7 @@
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1.8.1074</string> <string>1.8.1093</string>
<key>NSExtension</key> <key>NSExtension</key>
<dict> <dict>
<key>NSExtensionMainStoryboard</key> <key>NSExtensionMainStoryboard</key>

View File

@ -73,10 +73,14 @@ class ScanLocalBookOperation: Operation {
for id in removedZimFileIDs { for id in removedZimFileIDs {
guard let book = localBooks[id] else {continue} guard let book = localBooks[id] else {continue}
if let _ = book.meta4URL { if book.articles.filter({ $0.isBookmarked }).count > 0 {
book.state = .Cloud book.state = .Retained
} else { } else {
context.deleteObject(book) if let _ = book.meta4URL {
book.state = .Cloud
} else {
context.deleteObject(book)
}
} }
} }

View File

@ -54,6 +54,7 @@ class LocalizedStrings {
class Library { class Library {
static let spaceNotEnough = NSLocalizedString("Space Not Enough", comment: "Library") static let spaceNotEnough = NSLocalizedString("Space Not Enough", comment: "Library")
} }

View File

@ -88,8 +88,7 @@ class ZimMultiReader: NSObject, DirectoryMonitorDelegate {
// MARK: - Loading System // MARK: - Loading System
func data(host: String, contentURLString: String) -> [String: AnyObject]? { func data(id: String, contentURLString: String) -> [String: AnyObject]? {
let id = pidMap[host] ?? host
guard let reader = readers[id] else {return nil} guard let reader = readers[id] else {return nil}
return reader.dataWithContentURLString(contentURLString) as? [String: AnyObject] return reader.dataWithContentURLString(contentURLString) as? [String: AnyObject]
} }