From 9884698d2d198b4a9d091bf1ad0d3e0e6678c18a Mon Sep 17 00:00:00 2001 From: Chris Li Date: Thu, 15 Sep 2016 11:06:59 -0400 Subject: [PATCH] Cloud Book Alerts --- Kiwix-iOS/Controller/Alerts.swift | 39 ++++++++----------- .../Library/BookDetailController.swift | 14 +++---- .../Library/CloudBooksController.swift | 9 ++--- Kiwix-iOS/Info.plist | 2 +- Kiwix-iOSWidgets/Bookmarks/Info.plist | 2 +- Kiwix/Tools/StringTools.swift | 2 +- 6 files changed, 30 insertions(+), 38 deletions(-) diff --git a/Kiwix-iOS/Controller/Alerts.swift b/Kiwix-iOS/Controller/Alerts.swift index ed2e5383..c044f2c9 100644 --- a/Kiwix-iOS/Controller/Alerts.swift +++ b/Kiwix-iOS/Controller/Alerts.swift @@ -9,32 +9,27 @@ import UIKit import Operations -class SpaceCautionAlert: UIAlertController { - convenience init(bookID: String) { - self.init() - - let comment = "Library, Space Alert" - let title = NSLocalizedString("Space Alert", comment: comment) - let message = NSLocalizedString("This book will take up more than 80% of your free space after downloaded.", comment: comment) - self.init(title: title, message: message, preferredStyle: .Alert) - - let cancel = UIAlertAction(title: LocalizedStrings.Common.cancel, style: .Cancel, handler: nil) - let download = UIAlertAction(title: NSLocalizedString("Download Anyway", comment: comment), style: .Destructive, handler: { (_) in - guard let download = DownloadBookOperation(bookID: bookID) else {return} - Network.shared.queue.addOperation(download) - }) - addAction(cancel) - addAction(download) - preferredAction = download - } -} - class SpaceNotEnoughAlert: AlertOperation { - init(controller: UIViewController) { - super.init(presentAlertFrom: controller) + init(context: UIViewController) { + super.init(presentAlertFrom: context) title = LocalizedStrings.Library.spaceNotEnough message = NSLocalizedString("Please free up some space and try again.", comment: "Library, Space Alert") addActionWithTitle(LocalizedStrings.cancel) } } + +class SpaceCautionAlert: AlertOperation { + init(context: UIViewController, bookID: String) { + super.init(presentAlertFrom: context) + + title = NSLocalizedString("Space Alert", comment: "Library, Space Alert") + message = NSLocalizedString("This book will take up more than 80% of your free space after downloaded.", comment: "Library, Space Alert") + addActionWithTitle(NSLocalizedString("Download Anyway", comment: "Library, Space Alert"), style: .Destructive) { _ in + guard let download = DownloadBookOperation(bookID: bookID) else {return} + Network.shared.queue.addOperation(download) + } + addActionWithTitle(LocalizedStrings.cancel) + preferredAction = actions[0] + } +} diff --git a/Kiwix-iOS/Controller/Library/BookDetailController.swift b/Kiwix-iOS/Controller/Library/BookDetailController.swift index 889a25f4..23bbf830 100644 --- a/Kiwix-iOS/Controller/Library/BookDetailController.swift +++ b/Kiwix-iOS/Controller/Library/BookDetailController.swift @@ -122,7 +122,7 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp if isLocal { cellTitles[1] = [Strings.remove] } else { - cellTitles[1] = book.spaceState == .NotEnough ? [Strings.spaceNotEnough] : [Strings.downloadNow] + cellTitles[1] = book.spaceState == .NotEnough ? [Strings.spaceNotEnough] : [LocalizedStrings.download] } } else { guard let downloadTask = book.downloadTask else {return} @@ -147,12 +147,12 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let title = cellTitles[indexPath.section][indexPath.row] switch title { - case Strings.downloadNow, Strings.spaceNotEnough, Strings.cancel, Strings.remove, Strings.pause, Strings.resume: + case LocalizedStrings.download, Strings.spaceNotEnough, Strings.cancel, Strings.remove, Strings.pause, Strings.resume: let cell = tableView.dequeueReusableCellWithIdentifier("CenterTextCell", forIndexPath: indexPath) cell.textLabel?.text = title switch title { - case Strings.downloadNow: + case LocalizedStrings.download: if book?.spaceState == .Caution {cell.textLabel?.textColor = UIColor.orangeColor()} case Strings.spaceNotEnough: cell.textLabel?.textColor = UIColor.grayColor() @@ -214,12 +214,10 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp let title = cell.textLabel?.text, let book = book else {return} switch title { - case Strings.downloadNow: + case LocalizedStrings.download: if book.spaceState == .Caution { - let alert = SpaceCautionAlert(bookID: book.id) - self.presentViewController(alert, animated: true, completion: { - self.tableView.setEditing(false, animated: true) - }) + let alert = SpaceCautionAlert(context: self, bookID: book.id) + GlobalQueue.shared.addOperation(alert) } else { guard let download = DownloadBookOperation(bookID: book.id) else {return} Network.shared.queue.addOperation(download) diff --git a/Kiwix-iOS/Controller/Library/CloudBooksController.swift b/Kiwix-iOS/Controller/Library/CloudBooksController.swift index 93338d8f..5c49c95e 100644 --- a/Kiwix-iOS/Controller/Library/CloudBooksController.swift +++ b/Kiwix-iOS/Controller/Library/CloudBooksController.swift @@ -273,16 +273,15 @@ class CloudBooksController: UITableViewController, NSFetchedResultsControllerDel return [action] case .Caution: let action = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: LocalizedStrings.download, handler: { _ in - let alert = SpaceCautionAlert(bookID: book.id) - self.presentViewController(alert, animated: true, completion: { - self.tableView.setEditing(false, animated: true) - }) + let alert = SpaceCautionAlert(context: self, bookID: book.id) + GlobalQueue.shared.addOperation(alert) + self.tableView.setEditing(false, animated: true) }) action.backgroundColor = UIColor.orangeColor() return [action] case .NotEnough: let action = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: LocalizedStrings.Library.spaceNotEnough, handler: { _ in - let alert = SpaceNotEnoughAlert(controller: self) + let alert = SpaceNotEnoughAlert(context: self) GlobalQueue.shared.addOperation(alert) self.tableView.setEditing(false, animated: true) }) diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index b0cba5a7..60fdf892 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -49,7 +49,7 @@ CFBundleVersion - 1.8.569 + 1.8.580 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/Kiwix-iOSWidgets/Bookmarks/Info.plist b/Kiwix-iOSWidgets/Bookmarks/Info.plist index f0f635ba..ec95c813 100644 --- a/Kiwix-iOSWidgets/Bookmarks/Info.plist +++ b/Kiwix-iOSWidgets/Bookmarks/Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 1.8.572 + 1.8.583 NSExtension NSExtensionMainStoryboard diff --git a/Kiwix/Tools/StringTools.swift b/Kiwix/Tools/StringTools.swift index 50bce00e..71f85359 100644 --- a/Kiwix/Tools/StringTools.swift +++ b/Kiwix/Tools/StringTools.swift @@ -53,7 +53,7 @@ class LocalizedStrings { static let download = NSLocalizedString("Download", comment: "Common") class Library { - static let spaceNotEnough = NSLocalizedString("Space Not Enough", comment: "Common") + static let spaceNotEnough = NSLocalizedString("Space Not Enough", comment: "Library") }