mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-25 21:05:09 -04:00
Core data book entity update
This commit is contained in:
parent
44d33f36ce
commit
8cb6f20c2c
@ -101,8 +101,7 @@ class BookDetailController: UITableViewController, CenterButtonCellDelegate, DZN
|
||||
switch title {
|
||||
case Strings.downloadNow:
|
||||
func startDownload() {
|
||||
guard let bookID = book.id,
|
||||
let download = DownloadBookOperation(bookID: bookID) else {return}
|
||||
guard let download = DownloadBookOperation(bookID: book.id) else {return}
|
||||
Network.shared.queue.addOperation(download)
|
||||
}
|
||||
|
||||
|
@ -107,13 +107,13 @@ class DownloadTasksController: UIViewController, UITableViewDelegate, UITableVie
|
||||
|
||||
func configureCell(cell: UITableViewCell, atIndexPath indexPath: NSIndexPath, animated: Bool = false) {
|
||||
guard let downloadTask = fetchedResultController.objectAtIndexPath(indexPath) as? DownloadTask,
|
||||
let book = downloadTask.book, let id = book.id,
|
||||
let book = downloadTask.book,
|
||||
let cell = cell as? DownloadBookCell else {return}
|
||||
|
||||
cell.titleLabel.text = book.title
|
||||
cell.favIcon.image = UIImage(data: book.favIcon ?? NSData())
|
||||
|
||||
if let progress = Network.shared.operations[id]?.progress {
|
||||
if let progress = Network.shared.operations[book.id]?.progress {
|
||||
cell.progressLabel.text = progress.fractionCompletedDescription
|
||||
cell.progressView.setProgress(Float(progress.fractionCompleted), animated: animated)
|
||||
cell.detailLabel.text = {
|
||||
@ -195,8 +195,8 @@ class DownloadTasksController: UIViewController, UITableViewDelegate, UITableVie
|
||||
actions.insert(pause, atIndex: 0)
|
||||
case .Paused:
|
||||
|
||||
if let book = downloadTask.book, let bookID = book.id,
|
||||
let resumeData = Preference.resumeData[bookID] {
|
||||
if let book = downloadTask.book,
|
||||
let resumeData = Preference.resumeData[book.id] {
|
||||
let resume = UITableViewRowAction(style: .Normal, title: "Resume") { (action, indexPath) in
|
||||
let task = Network.shared.session.downloadTaskWithResumeData(resumeData)
|
||||
let operation = DownloadBookOperation(downloadTask: task)
|
||||
|
@ -133,7 +133,7 @@ class LocalBooksController: UIViewController, UITableViewDelegate, UITableViewDa
|
||||
let delete = UITableViewRowAction(style: .Destructive, title: LocalizedStrings.delete) { (action, indexPath) -> Void in
|
||||
guard let book = self.fetchedResultController.objectAtIndexPath(indexPath) as? Book else {return}
|
||||
self.managedObjectContext.performBlock({ () -> Void in
|
||||
if let id = book.id, let zimURL = ZimMultiReader.sharedInstance.readers[id]?.fileURL {
|
||||
if let zimURL = ZimMultiReader.sharedInstance.readers[book.id]?.fileURL {
|
||||
FileManager.removeItem(atURL: zimURL)
|
||||
|
||||
let indexFolderURL = zimURL.URLByAppendingPathExtension("idx")
|
||||
|
@ -143,10 +143,9 @@ class SearchBooksVC: UIViewController, UITableViewDelegate, UITableViewDataSourc
|
||||
|
||||
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
|
||||
guard let mainVC = parentViewController?.parentViewController as? MainController,
|
||||
let book = fetchedResultController.objectAtIndexPath(indexPath) as? Book,
|
||||
let bookID = book.id else {return}
|
||||
let book = fetchedResultController.objectAtIndexPath(indexPath) as? Book else {return}
|
||||
mainVC.hideSearch(animated: true)
|
||||
mainVC.loadMainPage(bookID)
|
||||
mainVC.loadMainPage(book.id)
|
||||
tableView.deselectRowAtIndexPath(indexPath, animated: true)
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.7.1725</string>
|
||||
<string>1.7.1729</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.7.2229</string>
|
||||
<string>1.7.2244</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionMainStoryboard</key>
|
||||
|
@ -21,7 +21,7 @@ extension Book {
|
||||
@NSManaged var favIcon: NSData?
|
||||
@NSManaged var fileSize: Int64
|
||||
@NSManaged var globalCount: Int64
|
||||
@NSManaged var id: String?
|
||||
@NSManaged var id: String
|
||||
@NSManaged var isLocal: NSNumber?
|
||||
@NSManaged var hasPic: Bool
|
||||
@NSManaged var hasIndex: Bool
|
||||
|
@ -19,9 +19,10 @@ class Book: NSManagedObject {
|
||||
// MARK: - Add Book
|
||||
|
||||
class func add(metadata: [String: AnyObject], context: NSManagedObjectContext) -> Book? {
|
||||
guard let id = metadata["id"] as? String else {return nil}
|
||||
guard let book = insert(Book.self, context: context) else {return nil}
|
||||
|
||||
book.id = metadata["id"] as? String
|
||||
book.id = id
|
||||
book.title = metadata["title"] as? String
|
||||
book.creator = metadata["creator"] as? String
|
||||
book.publisher = metadata["publisher"] as? String
|
||||
@ -75,8 +76,7 @@ class Book: NSManagedObject {
|
||||
}
|
||||
|
||||
var resumeDataURL: NSURL? {
|
||||
guard let id = id,
|
||||
let folderURL = NSURL(fileURLWithPath: NSFileManager.libDirURL.path!).URLByAppendingPathComponent("DownloadTemp", isDirectory: true),
|
||||
guard let folderURL = NSURL(fileURLWithPath: NSFileManager.libDirURL.path!).URLByAppendingPathComponent("DownloadTemp", isDirectory: true),
|
||||
let folderPath = folderURL.path else {return nil}
|
||||
if !NSFileManager.defaultManager().fileExistsAtPath(folderPath) {
|
||||
_ = try? NSFileManager.defaultManager().createDirectoryAtURL(folderURL, withIntermediateDirectories: true, attributes: [NSURLIsExcludedFromBackupKey: true])
|
||||
@ -99,8 +99,7 @@ class Book: NSManagedObject {
|
||||
|
||||
var books = [ZimID: Book]()
|
||||
for book in localBooks {
|
||||
guard let id = book.id else {continue}
|
||||
books[id] = book
|
||||
books[book.id] = book
|
||||
}
|
||||
return books
|
||||
}
|
||||
@ -114,7 +113,6 @@ class Book: NSManagedObject {
|
||||
// MARK: - Manage
|
||||
|
||||
func removeResumeData() {
|
||||
guard let id = id else {return}
|
||||
Preference.resumeData[id] = nil
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,10 @@
|
||||
<attribute name="favIcon" optional="YES" attributeType="Binary" syncable="YES"/>
|
||||
<attribute name="fileSize" optional="YES" attributeType="Integer 64" minValueString="0" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
|
||||
<attribute name="globalCount" optional="YES" attributeType="Integer 64" minValueString="0" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
|
||||
<attribute name="hasIndex" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
|
||||
<attribute name="hasPic" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
|
||||
<attribute name="hasIndex" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
|
||||
<attribute name="hasPic" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
|
||||
<attribute name="id" attributeType="String" defaultValueString="Unknown" syncable="YES"/>
|
||||
<attribute name="includeInSearch" optional="YES" attributeType="Boolean" defaultValueString="YES" usesScalarValueType="YES" syncable="YES"/>
|
||||
<attribute name="includeInSearch" attributeType="Boolean" defaultValueString="YES" usesScalarValueType="YES" syncable="YES"/>
|
||||
<attribute name="isLocal" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="NO" syncable="YES"/>
|
||||
<attribute name="mediaCount" optional="YES" attributeType="Integer 64" minValueString="0" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
|
||||
<attribute name="meta4URL" optional="YES" attributeType="String" syncable="YES"/>
|
||||
@ -79,10 +79,10 @@
|
||||
<fetchRequest name="AllArticlesBookmarked" entity="Article" predicateString="isBookmarked == 1 AND book.downloadStateRaw == 1"/>
|
||||
<elements>
|
||||
<element name="Article" positionX="-108" positionY="-136" width="128" height="210"/>
|
||||
<element name="Book" positionX="-405" positionY="-129" width="128" height="343"/>
|
||||
<element name="Book" positionX="-405" positionY="-129" width="128" height="345"/>
|
||||
<element name="Collection" positionX="-144" positionY="63" width="128" height="75"/>
|
||||
<element name="DownloadTask" positionX="-108" positionY="84" width="128" height="105"/>
|
||||
<element name="Language" positionX="-110" positionY="199" width="128" height="103"/>
|
||||
<element name="Tag" positionX="124" positionY="-126" width="128" height="73"/>
|
||||
<element name="Collection" positionX="-144" positionY="63" width="128" height="75"/>
|
||||
</elements>
|
||||
</model>
|
@ -13,8 +13,7 @@ class FileManager {
|
||||
class func move(book: Book, fromURL: NSURL, suggestedFileName: String?) {
|
||||
let fileName: String = {
|
||||
if let suggestedFileName = suggestedFileName {return suggestedFileName}
|
||||
if let id = book.id {return "\(id).zim"}
|
||||
return NSDate().description + ".zim"
|
||||
return book.id
|
||||
}()
|
||||
let directory = NSFileManager.docDirURL
|
||||
createDirectory(directory, includeInICloudBackup: false)
|
||||
|
Loading…
x
Reference in New Issue
Block a user