From 2acceecc8f6f48723ae778c507a7b1c5fd1c8fdb Mon Sep 17 00:00:00 2001 From: Chris Li Date: Thu, 15 Sep 2016 10:26:03 -0400 Subject: [PATCH] commit --- Kiwix-iOS/Controller/Alerts.swift | 40 +++++++++++++++++++ .../Library/BookDetailController.swift | 39 ++++++++---------- .../Library/CloudBooksController.swift | 35 ++++++++++++++++ Kiwix-iOS/Info.plist | 2 +- Kiwix-iOS/iOSExtensions.swift | 3 +- Kiwix-iOSWidgets/Bookmarks/Info.plist | 2 +- Kiwix.xcodeproj/project.pbxproj | 4 ++ Kiwix/Operations/UIOperations.swift | 1 - Kiwix/Tools/StringTools.swift | 18 +++++++-- 9 files changed, 113 insertions(+), 31 deletions(-) create mode 100644 Kiwix-iOS/Controller/Alerts.swift diff --git a/Kiwix-iOS/Controller/Alerts.swift b/Kiwix-iOS/Controller/Alerts.swift new file mode 100644 index 00000000..ed2e5383 --- /dev/null +++ b/Kiwix-iOS/Controller/Alerts.swift @@ -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 { + 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) + } +} diff --git a/Kiwix-iOS/Controller/Library/BookDetailController.swift b/Kiwix-iOS/Controller/Library/BookDetailController.swift index 26920652..889a25f4 100644 --- a/Kiwix-iOS/Controller/Library/BookDetailController.swift +++ b/Kiwix-iOS/Controller/Library/BookDetailController.swift @@ -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) - } } } diff --git a/Kiwix-iOS/Controller/Library/CloudBooksController.swift b/Kiwix-iOS/Controller/Library/CloudBooksController.swift index a41f6745..93338d8f 100644 --- a/Kiwix-iOS/Controller/Library/CloudBooksController.swift +++ b/Kiwix-iOS/Controller/Library/CloudBooksController.swift @@ -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 diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index 8bd91af2..b0cba5a7 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -49,7 +49,7 @@ CFBundleVersion - 1.8.454 + 1.8.569 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/Kiwix-iOS/iOSExtensions.swift b/Kiwix-iOS/iOSExtensions.swift index 94d8057e..e0014771 100644 --- a/Kiwix-iOS/iOSExtensions.swift +++ b/Kiwix-iOS/iOSExtensions.swift @@ -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) } diff --git a/Kiwix-iOSWidgets/Bookmarks/Info.plist b/Kiwix-iOSWidgets/Bookmarks/Info.plist index 0542bb98..f0f635ba 100644 --- a/Kiwix-iOSWidgets/Bookmarks/Info.plist +++ b/Kiwix-iOSWidgets/Bookmarks/Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 1.8.457 + 1.8.572 NSExtension NSExtensionMainStoryboard diff --git a/Kiwix.xcodeproj/project.pbxproj b/Kiwix.xcodeproj/project.pbxproj index 4d658453..ff96f3c7 100644 --- a/Kiwix.xcodeproj/project.pbxproj +++ b/Kiwix.xcodeproj/project.pbxproj @@ -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 = ""; }; 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 */, diff --git a/Kiwix/Operations/UIOperations.swift b/Kiwix/Operations/UIOperations.swift index 0d486591..3c266814 100644 --- a/Kiwix/Operations/UIOperations.swift +++ b/Kiwix/Operations/UIOperations.swift @@ -11,7 +11,6 @@ import Operations // MARK: - Alerts - class GetStartedAlert: AlertOperation { let comment = "First Time Launch Message" init(presentationContext mainController: MainController) { diff --git a/Kiwix/Tools/StringTools.swift b/Kiwix/Tools/StringTools.swift index 8b21c7b2..50bce00e 100644 --- a/Kiwix/Tools/StringTools.swift +++ b/Kiwix/Tools/StringTools.swift @@ -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"