Add verbose mode
This commit is contained in:
@@ -31,7 +31,7 @@ class ViewController: UIViewController {
|
||||
let openSourceVC = OpenSourceController()
|
||||
|
||||
// Apply somre customisation if you want !
|
||||
self.controllerCustomUI(controller: openSourceVC)
|
||||
//self.controllerCustomUI(openSourceVC: openSourceVC)
|
||||
|
||||
// Init with LicenceFile object
|
||||
openSourceVC.licences = [LicenceFile(title: "FacebookImagePicker",
|
||||
@@ -47,26 +47,29 @@ class ViewController: UIViewController {
|
||||
|
||||
// Customization
|
||||
|
||||
fileprivate func controllerCustomUI(controller: OpenSourceController) {
|
||||
fileprivate func controllerCustomUI(openSourceVC: OpenSourceController) {
|
||||
// Navigation bar title
|
||||
controller.config.title = "MyCustomTitle"
|
||||
openSourceVC.config.title = "MyCustomTitle"
|
||||
|
||||
// Navigation bar tint color
|
||||
controller.config.uiConfig.barTintColor = UIColor.red
|
||||
openSourceVC.config.uiConfig.barTintColor = UIColor.red
|
||||
|
||||
// Close button color
|
||||
controller.config.uiConfig.closeButtonColor = UIColor.white
|
||||
openSourceVC.config.uiConfig.closeButtonColor = UIColor.white
|
||||
|
||||
// BackgroundColor
|
||||
controller.config.uiConfig.backgroundColor = UIColor.red.withAlphaComponent(0.6)
|
||||
openSourceVC.config.uiConfig.backgroundColor = UIColor.red.withAlphaComponent(0.6)
|
||||
|
||||
// Licence text color
|
||||
controller.config.uiConfig.licenceTextColor = UIColor.white
|
||||
openSourceVC.config.uiConfig.licenceTextColor = UIColor.white
|
||||
|
||||
// Navigation bar title color
|
||||
controller.config.uiConfig.titleColor = UIColor.white
|
||||
openSourceVC.config.uiConfig.titleColor = UIColor.white
|
||||
|
||||
// Licence cell background color
|
||||
controller.config.uiConfig.licenceBackgroundColor = UIColor.red
|
||||
openSourceVC.config.uiConfig.licenceBackgroundColor = UIColor.red
|
||||
|
||||
// Verbose mode
|
||||
openSourceVC.config.verbose = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,8 @@ class OpenSourceViewController: UITableViewController {
|
||||
fileprivate func prepareLicences() {
|
||||
if let licences = self.licences {
|
||||
self.startLoading()
|
||||
LicenceDownloader.downloadLicences(licences: licences) { () in
|
||||
LicenceDownloader.downloadLicences(licences: licences,
|
||||
config: self.config) { () in
|
||||
// Update licences
|
||||
self.downloadedLicence = self.licences
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ class LicenceDownloader: NSObject {
|
||||
/// - licences: array which contains licence model model
|
||||
/// - completion: end downloading completion
|
||||
class func downloadLicences(licences: [LicenceFile],
|
||||
config: OpenSourceControllerConfig,
|
||||
completion: @escaping () -> Void) {
|
||||
// Number of licences
|
||||
let licenceCount = licences.count
|
||||
@@ -25,7 +26,7 @@ class LicenceDownloader: NSObject {
|
||||
|
||||
// Download licence's detail for every lience
|
||||
for licence in licences {
|
||||
licence.downloadLicenceDetail(completion: { () in
|
||||
licence.downloadLicenceDetail(config: config, completion: { () in
|
||||
alreadyDownloaded += 1
|
||||
|
||||
// If this is the last licence, perfom completion
|
||||
|
||||
@@ -38,7 +38,8 @@ public class LicenceFile: NSObject {
|
||||
/// Download licence detail
|
||||
///
|
||||
/// - Parameter completion: end of download handler
|
||||
func downloadLicenceDetail(completion: @escaping (Void) -> Void) {
|
||||
func downloadLicenceDetail(config: OpenSourceControllerConfig,
|
||||
completion: @escaping (Void) -> Void) {
|
||||
if let url = URL(string: self.url) {
|
||||
let task = URLSession.shared.dataTask(with: url) { (data, _, _) in
|
||||
if let data = data,
|
||||
@@ -48,7 +49,9 @@ public class LicenceFile: NSObject {
|
||||
self.detail = html
|
||||
|
||||
// Log
|
||||
print("Licence for \(self.title ?? "") downloaded with success.")
|
||||
if config.verbose {
|
||||
print("Licence for \(self.title ?? "") downloaded with success.")
|
||||
}
|
||||
}
|
||||
completion()
|
||||
}
|
||||
|
||||
@@ -33,6 +33,9 @@ public struct OpenSourceControllerConfig {
|
||||
/// Will be applied to the navigation bar title
|
||||
public var title: String = "Tiers library"
|
||||
|
||||
// Verbose mode for print log when licence are downloaded
|
||||
public var verbose: Bool = false
|
||||
|
||||
/// UI-specific configuration.
|
||||
public var uiConfig = UIConfig()
|
||||
}
|
||||
|
||||
@@ -81,25 +81,28 @@ You can apply some customisation. To do it you can use the OpenSourceControllerC
|
||||
|
||||
```swift
|
||||
// Navigation bar title
|
||||
controller.config.title = "MyCustomTitle"
|
||||
openSourceVC.config.title = "MyCustomTitle"
|
||||
|
||||
// Navigation bar tint color
|
||||
controller.config.uiConfig.barTintColor = UIColor.red
|
||||
openSourceVC.config.uiConfig.barTintColor = UIColor.red
|
||||
|
||||
// Close button color
|
||||
controller.config.uiConfig.closeButtonColor = UIColor.white
|
||||
openSourceVC.config.uiConfig.closeButtonColor = UIColor.white
|
||||
|
||||
// BackgroundColor
|
||||
controller.config.uiConfig.backgroundColor = UIColor.red.withAlphaComponent(0.6)
|
||||
openSourceVC.config.uiConfig.backgroundColor = UIColor.red.withAlphaComponent(0.6)
|
||||
|
||||
// Licence text color
|
||||
controller.config.uiConfig.licenceTextColor = UIColor.white
|
||||
openSourceVC.config.uiConfig.licenceTextColor = UIColor.white
|
||||
|
||||
// Navigation bar title color
|
||||
controller.config.uiConfig.titleColor = UIColor.white
|
||||
openSourceVC.config.uiConfig.titleColor = UIColor.white
|
||||
|
||||
// Licence cell background color
|
||||
controller.config.uiConfig.licenceBackgroundColor = UIColor.red
|
||||
openSourceVC.config.uiConfig.licenceBackgroundColor = UIColor.red
|
||||
|
||||
// Verbose mode
|
||||
openSourceVC.config.verbose = true
|
||||
```
|
||||
|
||||
## Translation
|
||||
|
||||
Reference in New Issue
Block a user