Cloud Book Alerts

This commit is contained in:
Chris Li 2016-09-15 11:06:59 -04:00
parent 2acceecc8f
commit 9884698d2d
6 changed files with 30 additions and 38 deletions

View File

@ -9,32 +9,27 @@
import UIKit import UIKit
import Operations 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<UIViewController> { class SpaceNotEnoughAlert: AlertOperation<UIViewController> {
init(controller: UIViewController) { init(context: UIViewController) {
super.init(presentAlertFrom: controller) super.init(presentAlertFrom: context)
title = LocalizedStrings.Library.spaceNotEnough title = LocalizedStrings.Library.spaceNotEnough
message = NSLocalizedString("Please free up some space and try again.", comment: "Library, Space Alert") message = NSLocalizedString("Please free up some space and try again.", comment: "Library, Space Alert")
addActionWithTitle(LocalizedStrings.cancel) addActionWithTitle(LocalizedStrings.cancel)
} }
} }
class SpaceCautionAlert: AlertOperation<UIViewController> {
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]
}
}

View File

@ -122,7 +122,7 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp
if isLocal { if isLocal {
cellTitles[1] = [Strings.remove] cellTitles[1] = [Strings.remove]
} else { } else {
cellTitles[1] = book.spaceState == .NotEnough ? [Strings.spaceNotEnough] : [Strings.downloadNow] cellTitles[1] = book.spaceState == .NotEnough ? [Strings.spaceNotEnough] : [LocalizedStrings.download]
} }
} else { } else {
guard let downloadTask = book.downloadTask else {return} 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 { override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let title = cellTitles[indexPath.section][indexPath.row] let title = cellTitles[indexPath.section][indexPath.row]
switch title { 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) let cell = tableView.dequeueReusableCellWithIdentifier("CenterTextCell", forIndexPath: indexPath)
cell.textLabel?.text = title cell.textLabel?.text = title
switch title { switch title {
case Strings.downloadNow: case LocalizedStrings.download:
if book?.spaceState == .Caution {cell.textLabel?.textColor = UIColor.orangeColor()} if book?.spaceState == .Caution {cell.textLabel?.textColor = UIColor.orangeColor()}
case Strings.spaceNotEnough: case Strings.spaceNotEnough:
cell.textLabel?.textColor = UIColor.grayColor() cell.textLabel?.textColor = UIColor.grayColor()
@ -214,12 +214,10 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp
let title = cell.textLabel?.text, let title = cell.textLabel?.text,
let book = book else {return} let book = book else {return}
switch title { switch title {
case Strings.downloadNow: case LocalizedStrings.download:
if book.spaceState == .Caution { if book.spaceState == .Caution {
let alert = SpaceCautionAlert(bookID: book.id) let alert = SpaceCautionAlert(context: self, bookID: book.id)
self.presentViewController(alert, animated: true, completion: { GlobalQueue.shared.addOperation(alert)
self.tableView.setEditing(false, animated: true)
})
} else { } else {
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)

View File

@ -273,16 +273,15 @@ class CloudBooksController: UITableViewController, NSFetchedResultsControllerDel
return [action] return [action]
case .Caution: case .Caution:
let action = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: LocalizedStrings.download, handler: { _ in let action = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: LocalizedStrings.download, handler: { _ in
let alert = SpaceCautionAlert(bookID: book.id) let alert = SpaceCautionAlert(context: self, bookID: book.id)
self.presentViewController(alert, animated: true, completion: { GlobalQueue.shared.addOperation(alert)
self.tableView.setEditing(false, animated: true) self.tableView.setEditing(false, animated: true)
})
}) })
action.backgroundColor = UIColor.orangeColor() action.backgroundColor = UIColor.orangeColor()
return [action] return [action]
case .NotEnough: case .NotEnough:
let action = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: LocalizedStrings.Library.spaceNotEnough, handler: { _ in 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) GlobalQueue.shared.addOperation(alert)
self.tableView.setEditing(false, animated: true) self.tableView.setEditing(false, animated: true)
}) })

View File

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

View File

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

View File

@ -53,7 +53,7 @@ class LocalizedStrings {
static let download = NSLocalizedString("Download", comment: "Common") static let download = NSLocalizedString("Download", comment: "Common")
class Library { class Library {
static let spaceNotEnough = NSLocalizedString("Space Not Enough", comment: "Common") static let spaceNotEnough = NSLocalizedString("Space Not Enough", comment: "Library")
} }