mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-28 14:35:03 -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]
|
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}
|
guard let download = DownloadBookOperation(bookID: book.id) else {return}
|
||||||
Network.shared.queue.addOperation(download)
|
Network.shared.queue.addOperation(download)
|
||||||
}
|
}
|
||||||
|
case Strings.remove:
|
||||||
|
let operation = RemoveBookConfirmationAlert(context: self, bookID: book.id)
|
||||||
|
GlobalQueue.shared.addOperation(operation)
|
||||||
case Strings.copyURL:
|
case Strings.copyURL:
|
||||||
guard let url = book.url else {return}
|
guard let url = book.url else {return}
|
||||||
UIPasteboard.generalPasteboard().string = url.absoluteString
|
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, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {}
|
||||||
|
|
||||||
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
|
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}
|
guard let book = self.fetchedResultController.objectAtIndexPath(indexPath) as? Book else {return}
|
||||||
self.managedObjectContext.performBlock({ () -> Void in
|
let operation = RemoveBookConfirmationAlert(context: self, bookID: book.id)
|
||||||
if let zimURL = ZimMultiReader.shared.readers[book.id]?.fileURL {
|
GlobalQueue.shared.addOperation(operation)
|
||||||
FileManager.removeItem(atURL: zimURL)
|
self.tableView.setEditing(false, animated: true)
|
||||||
|
|
||||||
let indexFolderURL = zimURL.URLByAppendingPathExtension("idx")
|
|
||||||
FileManager.removeItem(atURL: indexFolderURL!)
|
|
||||||
}
|
|
||||||
|
|
||||||
if let _ = book.url {
|
|
||||||
book.isLocal = false
|
|
||||||
} else {
|
|
||||||
self.managedObjectContext.deleteObject(book)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
return [delete]
|
return [delete]
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.8.580</string>
|
<string>1.8.622</string>
|
||||||
<key>ITSAppUsesNonExemptEncryption</key>
|
<key>ITSAppUsesNonExemptEncryption</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.8.583</string>
|
<string>1.8.625</string>
|
||||||
<key>NSExtension</key>
|
<key>NSExtension</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>NSExtensionMainStoryboard</key>
|
<key>NSExtensionMainStoryboard</key>
|
||||||
|
@ -46,7 +46,7 @@ class DownloadBookOperation: URLSessionDownloadTaskOperation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DeleteBookOperation: Operation {
|
class RemoveBookOperation: Operation {
|
||||||
|
|
||||||
let bookID: String
|
let bookID: String
|
||||||
|
|
||||||
@ -55,6 +55,21 @@ class DeleteBookOperation: Operation {
|
|||||||
super.init()
|
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 {
|
for id in removedZimFileIDs {
|
||||||
guard let book = localBooks[id] else {continue}
|
guard let book = localBooks[id] else {continue}
|
||||||
if let _ = book.meta4URL {
|
if let _ = book.meta4URL {
|
||||||
print(book.isLocal)
|
|
||||||
book.isLocal = false
|
book.isLocal = false
|
||||||
} else {
|
} else {
|
||||||
context.deleteObject(book)
|
context.deleteObject(book)
|
||||||
|
@ -12,7 +12,8 @@
|
|||||||
@interface ZimReader : NSObject
|
@interface ZimReader : NSObject
|
||||||
|
|
||||||
- (instancetype)initWithZIMFileURL:(NSURL *)url;
|
- (instancetype)initWithZIMFileURL:(NSURL *)url;
|
||||||
@property NSURL *fileURL;
|
@property (strong, nonatomic) NSURL *fileURL;
|
||||||
|
@property (strong, nonatomic) NSURL *idxFolderURL;
|
||||||
|
|
||||||
#pragma mark - index
|
#pragma mark - index
|
||||||
- (BOOL)hasIndex;
|
- (BOOL)hasIndex;
|
||||||
|
@ -46,8 +46,8 @@
|
|||||||
try {
|
try {
|
||||||
NSString *zimPath = [url absoluteString];
|
NSString *zimPath = [url absoluteString];
|
||||||
zimPath = [zimPath stringByReplacingOccurrencesOfString:@".zimaa" withString:@".zim"];
|
zimPath = [zimPath stringByReplacingOccurrencesOfString:@".zimaa" withString:@".zim"];
|
||||||
NSURL *xapianURl = [[NSURL fileURLWithPath:zimPath] URLByAppendingPathExtension:@"idx"];
|
self.idxFolderURL = [[NSURL fileURLWithPath:zimPath] URLByAppendingPathExtension:@"idx"];
|
||||||
_db = new Xapian::Database([xapianURl fileSystemRepresentation]);
|
_db = new Xapian::Database([self.idxFolderURL fileSystemRepresentation]);
|
||||||
} catch (const Xapian::DatabaseOpeningError &e) {}
|
} catch (const Xapian::DatabaseOpeningError &e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user