2020-04-16 15:25:40 +02:00
//
// E x t e n s i o n P o i n t I n s p e c t o r 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 4 / 1 6 / 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
class ExtensionPointInspectorViewController : UITableViewController {
@IBOutlet weak var extensionDescription : UILabel !
var extensionPoint : ExtensionPoint ?
override func viewDidLoad ( ) {
super . viewDidLoad ( )
guard let extensionPoint = extensionPoint else { return }
navigationItem . title = extensionPoint . title
extensionDescription . attributedText = extensionPoint . description
tableView . register ( ImageHeaderView . self , forHeaderFooterViewReuseIdentifier : " SectionHeader " )
}
@IBAction func disable ( _ sender : Any ) {
guard let extensionPoint = extensionPoint else { return }
2020-12-08 23:54:34 +01:00
let title = NSLocalizedString ( " Deactivate Extension " , comment : " Deactivate Extension " )
let extensionPointTypeTitle = extensionPoint . extensionPointID . extensionPointType . title
let message = NSLocalizedString ( " Are you sure you want to deactivate the \( extensionPointTypeTitle ) extension “ \( extensionPoint . title ) ”? " , comment : " Deactivate text " )
let alertController = UIAlertController ( title : title , message : message , preferredStyle : . alert )
let cancelTitle = NSLocalizedString ( " Cancel " , comment : " Cancel " )
let cancelAction = UIAlertAction ( title : cancelTitle , style : . cancel )
alertController . addAction ( cancelAction )
let markTitle = NSLocalizedString ( " Deactivate " , comment : " Deactivate " )
let markAction = UIAlertAction ( title : markTitle , style : . default ) { [ weak self ] ( action ) in
ExtensionPointManager . shared . deactivateExtensionPoint ( extensionPoint . extensionPointID )
self ? . navigationController ? . popViewController ( animated : true )
}
alertController . addAction ( markAction )
2021-01-12 02:57:14 +01:00
alertController . preferredAction = markAction
2020-12-08 23:54:34 +01:00
present ( alertController , animated : true )
2020-04-16 15:25:40 +02:00
}
}
// MARK: T a b l e V i e w
extension ExtensionPointInspectorViewController {
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 ? {
guard let extensionPoint = extensionPoint else { return nil }
if section = = 0 {
let headerView = tableView . dequeueReusableHeaderFooterView ( withIdentifier : " SectionHeader " ) as ! ImageHeaderView
2020-10-30 23:10:24 +01:00
headerView . imageView . image = extensionPoint . image
2020-04-16 15:25:40 +02:00
return headerView
} else {
return super . tableView ( tableView , viewForHeaderInSection : section )
}
}
override func tableView ( _ tableView : UITableView , shouldHighlightRowAt indexPath : IndexPath ) -> Bool {
if indexPath . section > 0 {
return true
}
return false
}
override func tableView ( _ tableView : UITableView , didSelectRowAt indexPath : IndexPath ) {
tableView . selectRow ( at : nil , animated : true , scrollPosition : . none )
}
}