This commit is contained in:
Chris Li 2016-09-15 10:26:03 -04:00
parent 1486353e96
commit 2acceecc8f
9 changed files with 113 additions and 31 deletions

View File

@ -0,0 +1,40 @@
//
// LibraryAlerts.swift
// Kiwix
//
// Created by Chris Li on 9/14/16.
// Copyright © 2016 Chris. All rights reserved.
//
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)
title = LocalizedStrings.Library.spaceNotEnough
message = NSLocalizedString("Please free up some space and try again.", comment: "Library, Space Alert")
addActionWithTitle(LocalizedStrings.cancel)
}
}

View File

@ -62,6 +62,8 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp
}
}
// MARK: - Configure
func configureViews() {
guard let book = book else {return}
@ -123,7 +125,12 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp
cellTitles[1] = book.spaceState == .NotEnough ? [Strings.spaceNotEnough] : [Strings.downloadNow]
}
} else {
cellTitles[1] = [Strings.cancel]
guard let downloadTask = book.downloadTask else {return}
if downloadTask.state == .Queued || downloadTask.state == .Downloading {
cellTitles[1] = [Strings.pause, Strings.cancel]
} else {
cellTitles[1] = [Strings.resume, Strings.cancel]
}
}
}
@ -140,7 +147,7 @@ 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:
case Strings.downloadNow, Strings.spaceNotEnough, Strings.cancel, Strings.remove, Strings.pause, Strings.resume:
let cell = tableView.dequeueReusableCellWithIdentifier("CenterTextCell", forIndexPath: indexPath)
cell.textLabel?.text = title
@ -208,23 +215,15 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp
let book = book else {return}
switch title {
case Strings.downloadNow:
func startDownload() {
if book.spaceState == .Caution {
let alert = SpaceCautionAlert(bookID: book.id)
self.presentViewController(alert, animated: true, completion: {
self.tableView.setEditing(false, animated: true)
})
} else {
guard let download = DownloadBookOperation(bookID: book.id) else {return}
Network.shared.queue.addOperation(download)
}
if book.spaceState == .Caution {
let cancel = UIAlertAction(title: Strings.cancel, style: .Cancel, handler: nil)
let download = UIAlertAction(title: Strings.SpaceAlert.downloadAnyway, style: .Destructive, handler: { (alert) in
startDownload()
})
let alertController = UIAlertController(title: Strings.SpaceAlert.spaceAlert, message: Strings.SpaceAlert.message, preferredStyle: .Alert)
[download, cancel].forEach({ alertController.addAction($0) })
presentViewController(alertController, animated: true, completion: nil)
} else {
startDownload()
}
case Strings.copyURL:
guard let url = book.url else {return}
UIPasteboard.generalPasteboard().string = url.absoluteString
@ -254,6 +253,7 @@ extension LocalizedStrings {
static let downloadNow = NSLocalizedString("Download Now", comment: comment)
static let spaceNotEnough = NSLocalizedString("Space Not Enough", comment: comment)
static let pause = NSLocalizedString("Pause", comment: comment)
static let resume = NSLocalizedString("Resume", comment: comment)
static let cancel = NSLocalizedString("Cancel", comment: comment)
static let remove = NSLocalizedString("Remove", comment: comment)
@ -270,12 +270,5 @@ extension LocalizedStrings {
private static let comment = "Library, Book Detail, Copy URL Alert"
static let succeed = NSLocalizedString("URL Copied Successfully", comment: comment)
}
class SpaceAlert {
private static let comment = "Library, Book Detail, Space Alert"
static let downloadAnyway = NSLocalizedString("Download Anyway", comment: comment)
static let spaceAlert = NSLocalizedString("Space Alert", comment: comment)
static let message = NSLocalizedString("This book will take up more than 80% of your free space after downloaded", comment: comment)
}
}
}

View File

@ -255,6 +255,41 @@ class CloudBooksController: UITableViewController, NSFetchedResultsControllerDel
header.textLabel?.font = UIFont.boldSystemFontOfSize(14)
}
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {}
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]?{
guard let book = fetchedResultController.objectAtIndexPath(indexPath) as? Book else {return nil}
switch book.spaceState {
case .Enough:
let action = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: LocalizedStrings.download, handler: { _ in
guard let download = DownloadBookOperation(bookID: book.id) else {return}
Network.shared.queue.addOperation(download)
})
action.backgroundColor = UIColor.defaultTint
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)
})
})
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)
GlobalQueue.shared.addOperation(alert)
self.tableView.setEditing(false, animated: true)
})
return [action]
}
}
// MARK: - Fetched Results Controller
let managedObjectContext = NSManagedObjectContext.mainQueueContext

View File

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

View File

@ -72,7 +72,8 @@ extension UIStoryboard {
}
extension UIColor {
class var defaultTint: UIColor {return UIColor(red: 0, green: 122/255, blue: 1, alpha: 1)}
class var themeColor: UIColor {
return UIColor(red: 71.0 / 255.0, green: 128.0 / 255.0, blue: 182.0 / 255.0, alpha: 1.0)
}

View File

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

View File

@ -42,6 +42,7 @@
971A10811D022F74007FC62C /* Pic_P.png in Resources */ = {isa = PBXBuildFile; fileRef = 971A107D1D022F74007FC62C /* Pic_P.png */; };
97219DBD1D383A00009FDFF1 /* BookmarkController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97219DBC1D383A00009FDFF1 /* BookmarkController.swift */; };
9722122B1D3FCCE200C0DCF2 /* MainControllerShowHide.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9722122A1D3FCCE200C0DCF2 /* MainControllerShowHide.swift */; };
972659191D8AE4B400D1DFFB /* Alerts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 972659181D8AE4B400D1DFFB /* Alerts.swift */; };
9734E54E1D289D060061C39B /* Welcome.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9734E54D1D289D060061C39B /* Welcome.storyboard */; };
973BCCEC1CEB3FA400F10B44 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973BCCEB1CEB3FA400F10B44 /* AppDelegate.swift */; };
973BCCF31CEB3FA400F10B44 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 973BCCF21CEB3FA400F10B44 /* Assets.xcassets */; };
@ -254,6 +255,7 @@
971C4F0B1D3FFFA60027B7D2 /* Kiwix.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = Kiwix.entitlements; path = "Kiwix-iOS/Kiwix.entitlements"; sourceTree = SOURCE_ROOT; };
97219DBC1D383A00009FDFF1 /* BookmarkController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BookmarkController.swift; path = "Kiwix-iOS/Controller/Bookmark/BookmarkController.swift"; sourceTree = SOURCE_ROOT; };
9722122A1D3FCCE200C0DCF2 /* MainControllerShowHide.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MainControllerShowHide.swift; path = "Kiwix-iOS/Controller/Main/MainControllerShowHide.swift"; sourceTree = SOURCE_ROOT; };
972659181D8AE4B400D1DFFB /* Alerts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Alerts.swift; sourceTree = "<group>"; };
9734E54D1D289D060061C39B /* Welcome.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Welcome.storyboard; path = "Kiwix-iOS/Storyboard/Welcome.storyboard"; sourceTree = SOURCE_ROOT; };
973BCCE91CEB3FA400F10B44 /* Kiwix.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Kiwix.app; sourceTree = BUILT_PRODUCTS_DIR; };
973BCCEB1CEB3FA400F10B44 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = "Kiwix-OSX/AppDelegate.swift"; sourceTree = SOURCE_ROOT; };
@ -822,6 +824,7 @@
978C58821C1CCDAF0077AE47 /* Controllers */ = {
isa = PBXGroup;
children = (
972659181D8AE4B400D1DFFB /* Alerts.swift */,
9749A1B21C430653000F2D1E /* Bookmark */,
97C005D41D64B369004352E8 /* Library */,
972B007D1C35DBAB00B5FDC5 /* Main */,
@ -1564,6 +1567,7 @@
97A127CB1D777CF100FB204D /* SearchController.swift in Sources */,
97A1FD261D6F71E200A80EE2 /* ZimReader.mm in Sources */,
97A1FD1C1D6F71D800A80EE2 /* KiwixURLProtocol.swift in Sources */,
972659191D8AE4B400D1DFFB /* Alerts.swift in Sources */,
97D6813F1D6F712800E5FA99 /* Article+CoreDataProperties.swift in Sources */,
97A1FD171D6F71CE00A80EE2 /* Extension.swift in Sources */,
971A103C1D022C2C007FC62C /* FontSizeTBVC.swift in Sources */,

View File

@ -11,7 +11,6 @@ import Operations
// MARK: - Alerts
class GetStartedAlert: AlertOperation<MainController> {
let comment = "First Time Launch Message"
init(presentationContext mainController: MainController) {

View File

@ -49,7 +49,17 @@ extension String {
}
class LocalizedStrings {
// Basic
static let download = NSLocalizedString("Download", comment: "Common")
class Library {
static let spaceNotEnough = NSLocalizedString("Space Not Enough", comment: "Common")
}
class var yes: String {return NSLocalizedString("Yes", comment: "Basic")}
class var no: String {return NSLocalizedString("No", comment: "Basic")}
class var on: String {return NSLocalizedString("On", comment: "Basic")}
@ -66,9 +76,9 @@ class LocalizedStrings {
class var history: String {return NSLocalizedString("History", comment: "Basic")}
// MARK: - OS X
class var General: String {return NSLocalizedString("General", comment: "OS X, Preference")}
class var Library: String {return NSLocalizedString("Library", comment: "OS X, Preference")}
class var ZimFiles: String {return NSLocalizedString("Zim Files", comment: "OS X, Preference")}
// class var General: String {return NSLocalizedString("General", comment: "OS X, Preference")}
// class var Library: String {return NSLocalizedString("Library", comment: "OS X, Preference")}
// class var ZimFiles: String {return NSLocalizedString("Zim Files", comment: "OS X, Preference")}
class Common {
private static let comment = "Common"