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)
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
let operation = RemoveBookOperation(bookID: bookID)
GlobalQueue.shared.addOperation(operation)

View File

@ -89,27 +89,22 @@ class LocalBooksController: UITableViewController, NSFetchedResultsControllerDel
// MARK: Other Data Source
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
guard tableView.numberOfSections > 1 else {return nil}
guard let languageName = fetchedResultController.sections?[section].name else {return nil}
return languageName
}
override func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? {
let sectionIndexTitles = fetchedResultController.sectionIndexTitles
guard sectionIndexTitles.count > 2 else {return nil}
return sectionIndexTitles
}
override func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int {
return fetchedResultController.sectionForSectionIndexTitle(title, atIndex: index)
guard let stateRaw = fetchedResultController.sections?[section].name else {return nil}
switch stateRaw {
case "2":
return LocalizedStrings.local
case "3":
return LocalizedStrings.retainedByBookmarks
case "4":
return LocalizedStrings.purgeable
default:
return nil
}
}
// MARK: - Table View Delegate
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
}
@ -143,11 +138,11 @@ class LocalBooksController: UITableViewController, NSFetchedResultsControllerDel
let managedObjectContext = NSManagedObjectContext.mainQueueContext
lazy var fetchedResultController: NSFetchedResultsController = {
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)
fetchRequest.sortDescriptors = [langDescriptor, titleDescriptor]
fetchRequest.sortDescriptors = [stateDescriptor, titleDescriptor]
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.performFetch(deleteCache: false)
return fetchedResultsController
@ -197,5 +192,7 @@ class LocalBooksController: UITableViewController, NSFetchedResultsControllerDel
class LocalizedStrings{
static let local = NSLocalizedString("Local", 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 titleDescriptor = NSSortDescriptor(key: "title", ascending: true)
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")
fetchedResultsController.delegate = self
fetchedResultsController.performFetch(deleteCache: false)

View File

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

View File

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

View File

@ -73,10 +73,14 @@ class ScanLocalBookOperation: Operation {
for id in removedZimFileIDs {
guard let book = localBooks[id] else {continue}
if let _ = book.meta4URL {
book.state = .Cloud
if book.articles.filter({ $0.isBookmarked }).count > 0 {
book.state = .Retained
} 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 {
static let spaceNotEnough = NSLocalizedString("Space Not Enough", comment: "Library")
}

View File

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