2020-03-28 23:51:14 +01:00
//
// C l o u d K i t A c c o u n t V i e w C o n t r o l l e r . s w i f t
// N e t N e w s W i r e - i O S
//
// C r e a t e d b y M a u r i c e P a r k e r o n 3 / 2 8 / 2 0 .
// C o p y r i g h t © 2 0 2 0 R a n c h e r o S o f t w a r e . A l l r i g h t s r e s e r v e d .
//
import UIKit
import Account
2021-06-18 02:05:39 +02:00
enum CloudKitAccountViewControllerError : LocalizedError {
case iCloudDriveMissing
var errorDescription : String ? {
return NSLocalizedString ( " Unable to add iCloud Account. Please make sure you have iCloud and iCloud enabled in System Preferences. " , comment : " Unable to add iCloud Account. " )
}
}
2020-03-28 23:51:14 +01:00
class CloudKitAccountViewController : UITableViewController {
weak var delegate : AddAccountDismissDelegate ?
2020-11-09 14:41:05 +01:00
@IBOutlet weak var footerLabel : UILabel !
2020-03-28 23:51:14 +01:00
override func viewDidLoad ( ) {
super . viewDidLoad ( )
2020-11-09 14:41:05 +01:00
setupFooter ( )
2020-03-28 23:51:14 +01:00
tableView . register ( ImageHeaderView . self , forHeaderFooterViewReuseIdentifier : " SectionHeader " )
}
2020-11-09 14:41:05 +01:00
private func setupFooter ( ) {
2021-06-01 00:52:56 +02:00
footerLabel . text = NSLocalizedString ( " Feeds in your iCloud account will be synced across your Mac and iOS devices. \n \n Important note: while NetNewsWire itself is very fast, iCloud syncing is sometimes very slow. This can happen after adding a number of feeds and when setting it up on a new device. \n \n If that happens to you, it may appear stuck. But don’ t worry — it’ s not. Just let it run. " , comment : " iCloud " )
2020-11-09 14:41:05 +01:00
}
2020-03-28 23:51:14 +01:00
@IBAction func cancel ( _ sender : Any ) {
dismiss ( animated : true , completion : nil )
delegate ? . dismiss ( )
}
@IBAction func add ( _ sender : Any ) {
2021-06-18 02:05:39 +02:00
guard FileManager . default . ubiquityIdentityToken != nil else {
presentError ( CloudKitAccountViewControllerError . iCloudDriveMissing )
return
}
2020-04-01 23:45:29 +02:00
let _ = AccountManager . shared . createAccount ( type : . cloudKit )
2020-03-28 23:51:14 +01:00
dismiss ( animated : true , completion : nil )
delegate ? . dismiss ( )
}
override func tableView ( _ tableView : UITableView , heightForHeaderInSection section : Int ) -> CGFloat {
return section = = 0 ? ImageHeaderView . rowHeight : super . tableView ( tableView , heightForHeaderInSection : section )
}
override func tableView ( _ tableView : UITableView , viewForHeaderInSection section : Int ) -> UIView ? {
if section = = 0 {
let headerView = tableView . dequeueReusableHeaderFooterView ( withIdentifier : " SectionHeader " ) as ! ImageHeaderView
2024-07-08 19:07:26 +02:00
headerView . imageView . image = AppAsset . Account . image ( for : . cloudKit )
2020-03-28 23:51:14 +01:00
return headerView
} else {
return super . tableView ( tableView , viewForHeaderInSection : section )
}
}
}