mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-27 13:59:04 -04:00
Remove Book operation
This commit is contained in:
parent
9884698d2d
commit
b4226ff9d1
@ -33,3 +33,18 @@ class SpaceCautionAlert: AlertOperation<UIViewController> {
|
||||
preferredAction = actions[0]
|
||||
}
|
||||
}
|
||||
|
||||
class RemoveBookConfirmationAlert: AlertOperation<UIViewController> {
|
||||
init(context: UIViewController, bookID: String) {
|
||||
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")
|
||||
addActionWithTitle(LocalizedStrings.remove, style: .Destructive) { _ in
|
||||
let operation = RemoveBookOperation(bookID: bookID)
|
||||
GlobalQueue.shared.addOperation(operation)
|
||||
}
|
||||
addActionWithTitle(LocalizedStrings.cancel)
|
||||
preferredAction = actions[0]
|
||||
}
|
||||
}
|
||||
|
@ -222,6 +222,9 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp
|
||||
guard let download = DownloadBookOperation(bookID: book.id) else {return}
|
||||
Network.shared.queue.addOperation(download)
|
||||
}
|
||||
case Strings.remove:
|
||||
let operation = RemoveBookConfirmationAlert(context: self, bookID: book.id)
|
||||
GlobalQueue.shared.addOperation(operation)
|
||||
case Strings.copyURL:
|
||||
guard let url = book.url else {return}
|
||||
UIPasteboard.generalPasteboard().string = url.absoluteString
|
||||
|
@ -129,22 +129,11 @@ class LocalBooksController: UIViewController, UITableViewDelegate, UITableViewDa
|
||||
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {}
|
||||
|
||||
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
|
||||
let delete = UITableViewRowAction(style: .Destructive, title: LocalizedStrings.delete) { (action, indexPath) -> Void in
|
||||
let delete = UITableViewRowAction(style: .Destructive, title: LocalizedStrings.remove) { (action, indexPath) -> Void in
|
||||
guard let book = self.fetchedResultController.objectAtIndexPath(indexPath) as? Book else {return}
|
||||
self.managedObjectContext.performBlock({ () -> Void in
|
||||
if let zimURL = ZimMultiReader.shared.readers[book.id]?.fileURL {
|
||||
FileManager.removeItem(atURL: zimURL)
|
||||
|
||||
let indexFolderURL = zimURL.URLByAppendingPathExtension("idx")
|
||||
FileManager.removeItem(atURL: indexFolderURL!)
|
||||
}
|
||||
|
||||
if let _ = book.url {
|
||||
book.isLocal = false
|
||||
} else {
|
||||
self.managedObjectContext.deleteObject(book)
|
||||
}
|
||||
})
|
||||
let operation = RemoveBookConfirmationAlert(context: self, bookID: book.id)
|
||||
GlobalQueue.shared.addOperation(operation)
|
||||
self.tableView.setEditing(false, animated: true)
|
||||
}
|
||||
return [delete]
|
||||
}
|
||||
|
@ -49,7 +49,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.580</string>
|
||||
<string>1.8.622</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.583</string>
|
||||
<string>1.8.625</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionMainStoryboard</key>
|
||||
|
@ -46,7 +46,7 @@ class DownloadBookOperation: URLSessionDownloadTaskOperation {
|
||||
}
|
||||
}
|
||||
|
||||
class DeleteBookOperation: Operation {
|
||||
class RemoveBookOperation: Operation {
|
||||
|
||||
let bookID: String
|
||||
|
||||
@ -55,6 +55,21 @@ class DeleteBookOperation: Operation {
|
||||
super.init()
|
||||
}
|
||||
|
||||
override func execute() {
|
||||
let context = NSManagedObjectContext.mainQueueContext
|
||||
context.performBlockAndWait {
|
||||
guard let zimFileURL = ZimMultiReader.shared.readers[self.bookID]?.fileURL else {return}
|
||||
_ = try? NSFileManager.defaultManager().removeItemAtURL(zimFileURL)
|
||||
|
||||
// Core data is updated by scan book operation
|
||||
// Article removal is handled by cascade relationship
|
||||
|
||||
guard let idxFolderURL = ZimMultiReader.shared.readers[self.bookID]?.idxFolderURL else {return}
|
||||
_ = try? NSFileManager.defaultManager().removeItemAtURL(idxFolderURL)
|
||||
}
|
||||
finish()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,6 @@ class ScanLocalBookOperation: Operation {
|
||||
for id in removedZimFileIDs {
|
||||
guard let book = localBooks[id] else {continue}
|
||||
if let _ = book.meta4URL {
|
||||
print(book.isLocal)
|
||||
book.isLocal = false
|
||||
} else {
|
||||
context.deleteObject(book)
|
||||
|
@ -12,7 +12,8 @@
|
||||
@interface ZimReader : NSObject
|
||||
|
||||
- (instancetype)initWithZIMFileURL:(NSURL *)url;
|
||||
@property NSURL *fileURL;
|
||||
@property (strong, nonatomic) NSURL *fileURL;
|
||||
@property (strong, nonatomic) NSURL *idxFolderURL;
|
||||
|
||||
#pragma mark - index
|
||||
- (BOOL)hasIndex;
|
||||
|
@ -46,8 +46,8 @@
|
||||
try {
|
||||
NSString *zimPath = [url absoluteString];
|
||||
zimPath = [zimPath stringByReplacingOccurrencesOfString:@".zimaa" withString:@".zim"];
|
||||
NSURL *xapianURl = [[NSURL fileURLWithPath:zimPath] URLByAppendingPathExtension:@"idx"];
|
||||
_db = new Xapian::Database([xapianURl fileSystemRepresentation]);
|
||||
self.idxFolderURL = [[NSURL fileURLWithPath:zimPath] URLByAppendingPathExtension:@"idx"];
|
||||
_db = new Xapian::Database([self.idxFolderURL fileSystemRepresentation]);
|
||||
} catch (const Xapian::DatabaseOpeningError &e) {}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user