mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-27 22:10:57 -04:00
Cloud Controller Update
This commit is contained in:
parent
355e511e18
commit
b7f4c3e03d
@ -9,10 +9,13 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
import CoreData
|
import CoreData
|
||||||
import Operations
|
import Operations
|
||||||
|
import MBProgressHUD
|
||||||
import DZNEmptyDataSet
|
import DZNEmptyDataSet
|
||||||
|
|
||||||
class CloudBooksController: UITableViewController, NSFetchedResultsControllerDelegate, LanguageFilterUpdating, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
|
class CloudBooksController: UITableViewController, NSFetchedResultsControllerDelegate, LanguageFilterUpdating, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
|
||||||
|
|
||||||
|
private(set) var isRefreshing = false
|
||||||
|
|
||||||
// MARK: - Override
|
// MARK: - Override
|
||||||
|
|
||||||
required init?(coder aDecoder: NSCoder) {
|
required init?(coder aDecoder: NSCoder) {
|
||||||
@ -87,20 +90,43 @@ class CloudBooksController: UITableViewController, NSFetchedResultsControllerDel
|
|||||||
|
|
||||||
func refresh(invokedByUser invokedByUser: Bool) {
|
func refresh(invokedByUser invokedByUser: Bool) {
|
||||||
let operation = RefreshLibraryOperation()
|
let operation = RefreshLibraryOperation()
|
||||||
operation.addObserver(DidFinishObserver { (operation, errors) in
|
operation.addObserver(WillExecuteObserver { (operation) in
|
||||||
NSOperationQueue.mainQueue().addOperationWithBlock({
|
NSOperationQueue.mainQueue().addOperationWithBlock({
|
||||||
self.refreshControl?.endRefreshing()
|
self.isRefreshing = true
|
||||||
|
self.tableView.reloadEmptyDataSet()
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
if let error = errors.first as? ReachabilityCondition.Error{
|
operation.addObserver(DidFinishObserver { (operation, errors) in
|
||||||
guard error == ReachabilityCondition.Error.NotReachable && invokedByUser == true else {return}
|
|
||||||
|
NSOperationQueue.mainQueue().addOperationWithBlock({
|
||||||
|
defer {
|
||||||
|
self.refreshControl?.endRefreshing()
|
||||||
|
self.isRefreshing = false
|
||||||
|
self.tableView.reloadEmptyDataSet()
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure do have error
|
||||||
|
guard errors.count > 0 else {
|
||||||
|
guard let view = self.splitViewController?.view else {return}
|
||||||
|
let hud = MBProgressHUD.showHUDAddedTo(view, animated: true)
|
||||||
|
hud.mode = .Text
|
||||||
|
hud.label.numberOfLines = 0
|
||||||
|
hud.label.text = NSLocalizedString("Library is refreshed successfully!", comment: "Cloud Book Controller")
|
||||||
|
hud.hideAnimated(true, afterDelay: 2)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// test if is Reachability error
|
||||||
|
guard let error = errors.first as? ReachabilityCondition.Error
|
||||||
|
where error == ReachabilityCondition.Error.NotReachable && invokedByUser == true else {return}
|
||||||
let cancel = UIAlertAction(title: LocalizedStrings.Common.ok, style: .Cancel, handler: nil)
|
let cancel = UIAlertAction(title: LocalizedStrings.Common.ok, style: .Cancel, handler: nil)
|
||||||
let alertController = UIAlertController(title: NSLocalizedString("Network Required", comment: "Network Required Alert"),
|
let alertController = UIAlertController(title: NSLocalizedString("Network Required", comment: "Network Required Alert"),
|
||||||
message: NSLocalizedString("Unable to connect to server. Please check your Internet connection.", comment: "Network Required Alert"),
|
message: NSLocalizedString("Unable to connect to server. Please check your Internet connection.", comment: "Network Required Alert"),
|
||||||
preferredStyle: .Alert)
|
preferredStyle: .Alert)
|
||||||
alertController.addAction(cancel)
|
alertController.addAction(cancel)
|
||||||
self.presentViewController(alertController, animated: true, completion: nil)
|
self.presentViewController(alertController, animated: true, completion: nil)
|
||||||
}
|
})
|
||||||
})
|
})
|
||||||
GlobalQueue.shared.addOperation(operation)
|
GlobalQueue.shared.addOperation(operation)
|
||||||
}
|
}
|
||||||
|
@ -22,12 +22,13 @@ extension CloudBooksController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func buttonTitleForEmptyDataSet(scrollView: UIScrollView!, forState state: UIControlState) -> NSAttributedString! {
|
func buttonTitleForEmptyDataSet(scrollView: UIScrollView!, forState state: UIControlState) -> NSAttributedString! {
|
||||||
let string = NSLocalizedString("Refresh", comment: "Cloud Book Controller")
|
let string = isRefreshing ? NSLocalizedString("Refreshing...", comment: "Cloud Book Controller") : NSLocalizedString("Refresh", comment: "Cloud Book Controller")
|
||||||
let attributes = [NSFontAttributeName: UIFont.boldSystemFontOfSize(17), NSForegroundColorAttributeName: AppColors.theme]
|
let attributes = [NSFontAttributeName: UIFont.boldSystemFontOfSize(17), NSForegroundColorAttributeName: isRefreshing ? UIColor.grayColor() : AppColors.theme]
|
||||||
return NSAttributedString(string: string, attributes: attributes)
|
return NSAttributedString(string: string, attributes: attributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func emptyDataSetDidTapButton(scrollView: UIScrollView!) {
|
func emptyDataSetDidTapButton(scrollView: UIScrollView!) {
|
||||||
|
guard !isRefreshing else {return}
|
||||||
refresh(invokedByUser: true)
|
refresh(invokedByUser: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.7.1759</string>
|
<string>1.7.1781</string>
|
||||||
<key>ITSAppUsesNonExemptEncryption</key>
|
<key>ITSAppUsesNonExemptEncryption</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.7.2294</string>
|
<string>1.7.2326</string>
|
||||||
<key>NSExtension</key>
|
<key>NSExtension</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>NSExtensionMainStoryboard</key>
|
<key>NSExtensionMainStoryboard</key>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user