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