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 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> {
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<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 {
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)

View File

@ -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)
})

View File

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

View File

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

View File

@ -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")
}