Compare commits

...
4 Commits
Author SHA1 Message Date
Florian Gabach b93d2f0d2a Bump to 2.0.1 2017-12-08 12:20:41 +01:00
Florian Gabach 2127942e5f Bump build system 2017-12-07 17:42:05 +01:00
Florian Gabach fd1107d42e Update README.md 2017-12-07 10:41:04 +01:00
Florian Gabach 1487636084 Update README.md 2017-11-22 21:09:29 +01:00
13 changed files with 158 additions and 64 deletions
+4
View File
@@ -1,6 +1,10 @@
Changelog Changelog
========== ==========
### 2.0.1
- Clean code and move loader position
### 2.0 ### 2.0
- Swift 4 version - Swift 4 version
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildSystemType</key>
<string>Latest</string>
</dict>
</plist>
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildLocationStyle</key>
<string>UseAppPreferences</string>
<key>CustomBuildLocationType</key>
<string>RelativeToDerivedData</string>
<key>DerivedDataLocationStyle</key>
<string>Default</string>
<key>EnabledFullIndexStoreVisibility</key>
<false/>
<key>IssueFilterStyle</key>
<string>ShowActiveSchemeOnly</string>
<key>LiveSourceIssuesEnabled</key>
<true/>
</dict>
</plist>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>OpenSourceControllerDemo.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
@@ -103,8 +103,9 @@
"scale" : "2x" "scale" : "2x"
}, },
{ {
"idiom" : "ios-marketing",
"size" : "1024x1024", "size" : "1024x1024",
"idiom" : "ios-marketing",
"filename" : "logo 7-3.png",
"scale" : "1x" "scale" : "1x"
} }
], ],
Binary file not shown.

After

Width:  |  Height:  |  Size: 287 KiB

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildSystemType</key>
<string>Latest</string>
</dict>
</plist>
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildLocationStyle</key>
<string>UseAppPreferences</string>
<key>CustomBuildLocationType</key>
<string>RelativeToDerivedData</string>
<key>DerivedDataLocationStyle</key>
<string>Default</string>
<key>EnabledFullIndexStoreVisibility</key>
<false/>
<key>IssueFilterStyle</key>
<string>ShowActiveSchemeOnly</string>
<key>LiveSourceIssuesEnabled</key>
<true/>
</dict>
</plist>
+3 -3
View File
@@ -54,9 +54,9 @@ pod "OpenSourceController", '~> 1.0.8' # Swift 3.1 version
- To integrate OpenSourceController into your Xcode project using [Carthage](https://github.com/Carthage/Carthage), specify it in your Cartfile : - To integrate OpenSourceController into your Xcode project using [Carthage](https://github.com/Carthage/Carthage), specify it in your Cartfile :
```ruby ```ruby
github "terflogag/OpenSourceController" ~> 2.0 github "floriangbh/OpenSourceController" ~> 2.0
github "terflogag/OpenSourceController" ~> 1.0.8 # Swift 3.1 version github "floriangbh/OpenSourceController" ~> 1.0.8 # Swift 3.1 version
``` ```
## Usage ## Usage
@@ -131,7 +131,7 @@ What about yours ? If your application also use this library, feel free to cont
## Author ## Author
Florian Gabach, contact@floriangabach.fr Florian Gabach, florian.gabach@gmail.com
## License ## License
@@ -7,21 +7,31 @@
import UIKit import UIKit
class OpenSourceViewController: UITableViewController { class OpenSourceViewController: UITableViewController {
// MARK: - Var // MARK: - Var
/// Loading indicator /// Loading indicator
fileprivate var indicator = UIActivityIndicatorView() fileprivate lazy var indicator: UIActivityIndicatorView = {
let indicator = UIActivityIndicatorView(frame:CGRect(x: 0,
y: 0,
width: 40,
height: 40) )
indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
indicator.hidesWhenStopped = true
indicator.backgroundColor = UIColor.clear
indicator.color = UIColor.black
return indicator
}()
/// TableViewCell identifier /// TableViewCell identifier
private let reuseIdentifier = "openSourceCell" private let reuseIdentifier = "openSourceCell"
/// Contains all licence object before downloaded /// Contains all licence object before downloaded
internal var licences: [LicenceFile]? internal var licences: [LicenceFile]?
// Controller configuration for customization // Controller configuration for customization
internal var config = OpenSourceControllerConfig() internal var config = OpenSourceControllerConfig()
/// Contains all licences object after downloaded /// Contains all licences object after downloaded
fileprivate var downloadedLicence: [LicenceFile]? { fileprivate var downloadedLicence: [LicenceFile]? {
didSet { didSet {
@@ -32,37 +42,45 @@ class OpenSourceViewController: UITableViewController {
} }
} }
} }
// MARK: - Lifecyle // MARK: - Lifecyle
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
// Prepare tableview // Prepare controller
self.prepare()
}
// MARK: - Prepare
/// Prepare controller
fileprivate func prepare() {
self.prepareTableView() self.prepareTableView()
self.prepareActivityIndicator()
// Download licences self.prepareCloseButton()
self.prepareStyle()
self.prepareLicences() self.prepareLicences()
} }
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// MARK: - Prepare
/// Download licences /// Download licences
fileprivate func prepareLicences() { fileprivate func prepareLicences() {
if let licences = self.licences { self.startLoading()
self.startLoading()
LicenceDownloader.downloadLicences(licences: licences, // Retrieve licence
config: self.config) { () in guard let licences = self.licences else {
// Update licences print("No licences found.")
self.downloadedLicence = self.licences return
} }
// Download licence
LicenceDownloader.downloadLicences(licences: licences,
config: self.config) { () in
// Update licences
self.downloadedLicence = self.licences
} }
} }
/// Init tableView dataSource, delegate, bar button & title /// Init tableView dataSource, delegate, bar button & title
fileprivate func prepareTableView() { fileprivate func prepareTableView() {
// Common init // Common init
@@ -74,46 +92,51 @@ class OpenSourceViewController: UITableViewController {
self.tableView.dataSource = self self.tableView.dataSource = self
self.tableView.delegate = self self.tableView.delegate = self
self.tableView.separatorStyle = .singleLine self.tableView.separatorStyle = .singleLine
// Apply background color from configuration if needed
if let backgroundColor = self.config.uiConfig.backgroundColor { if let backgroundColor = self.config.uiConfig.backgroundColor {
self.tableView.backgroundColor = backgroundColor self.tableView.backgroundColor = backgroundColor
} }
}
// Navigation bar
/// Prepare controller style
fileprivate func prepareStyle() {
// Apply navigation bar tint color if needed
if let tintColor = self.config.uiConfig.barTintColor { if let tintColor = self.config.uiConfig.barTintColor {
self.navigationController?.navigationBar.barTintColor = tintColor self.navigationController?.navigationBar.barTintColor = tintColor
} }
// Applu navigation bar text color if needed
if let textColor = self.config.uiConfig.titleColor { if let textColor = self.config.uiConfig.titleColor {
let attribut = [NSAttributedStringKey.foregroundColor: textColor] let attribut = [NSAttributedStringKey.foregroundColor: textColor]
self.navigationController?.navigationBar.titleTextAttributes = attribut self.navigationController?.navigationBar.titleTextAttributes = attribut
} }
}
/// Prepare close button on navigation bar
fileprivate func prepareCloseButton() {
// Close button (on the right corner of navigation bar) // Close button (on the right corner of navigation bar)
let closeButton = UIBarButtonItem(barButtonSystemItem: .stop, let closeButton = UIBarButtonItem(barButtonSystemItem: .stop,
target: self, target: self,
action: #selector(self.closePicker)) action: #selector(self.closePicker))
closeButton.tintColor = config.uiConfig.closeButtonColor ?? UIColor.black closeButton.tintColor = config.uiConfig.closeButtonColor ?? UIColor.black
self.navigationItem.rightBarButtonItem = closeButton self.navigationItem.rightBarButtonItem = closeButton
// Loading indicator
self.prepareActivityIndicator()
} }
// MARK: - Loading indicator // MARK: - Loading indicator
/// Prepare UIActivityIndicatorView and display it at the center of the view /// Prepare UIActivityIndicatorView and display it at the center of the view
fileprivate func prepareActivityIndicator() { fileprivate func prepareActivityIndicator() {
self.indicator = UIActivityIndicatorView(frame:CGRect(x: 0, // Add to view
y: 0,
width: 40,
height: 40) )
self.indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
self.indicator.center = self.view.center
self.indicator.hidesWhenStopped = true
self.indicator.backgroundColor = UIColor.clear
self.indicator.color = UIColor.black
self.view.addSubview(indicator) self.view.addSubview(indicator)
// Apply constraint
self.indicator.translatesAutoresizingMaskIntoConstraints = false
self.indicator.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
let topConstraint = self.navigationController?.navigationBar.frame.size.height ?? 0.0
self.indicator.bottomAnchor.constraint(equalTo: view.topAnchor, constant: topConstraint).isActive=true
} }
/// Start loading : start the loader animation /// Start loading : start the loader animation
fileprivate func startLoading() { fileprivate func startLoading() {
self.indicator.startAnimating() self.indicator.startAnimating()
@@ -122,7 +145,7 @@ class OpenSourceViewController: UITableViewController {
// Disable scroll // Disable scroll
self.tableView.isScrollEnabled = false self.tableView.isScrollEnabled = false
} }
/// Stop loading : stop and hide the loader /// Stop loading : stop and hide the loader
fileprivate func stopLoading() { fileprivate func stopLoading() {
self.indicator.stopAnimating() self.indicator.stopAnimating()
@@ -131,17 +154,17 @@ class OpenSourceViewController: UITableViewController {
// Enable scroll // Enable scroll
self.tableView.isScrollEnabled = true self.tableView.isScrollEnabled = true
} }
// MARK: - Table View Data Source // MARK: - Table View Data Source
override func numberOfSections(in tableView: UITableView) -> Int { override func numberOfSections(in tableView: UITableView) -> Int {
return 1 return 1
} }
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.downloadedLicence?.count ?? 0 return self.downloadedLicence?.count ?? 0
} }
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: self.reuseIdentifier, var cell = tableView.dequeueReusableCell(withIdentifier: self.reuseIdentifier,
for: indexPath) as? OpenSourceTableViewCell for: indexPath) as? OpenSourceTableViewCell
@@ -150,29 +173,29 @@ class OpenSourceViewController: UITableViewController {
cell = OpenSourceTableViewCell(style: UITableViewCellStyle.default, cell = OpenSourceTableViewCell(style: UITableViewCellStyle.default,
reuseIdentifier: self.reuseIdentifier) reuseIdentifier: self.reuseIdentifier)
} }
// Configure the cell with licence // Configure the cell with licence
if let licence = self.downloadedLicence?.get(at: indexPath.row) { if let licence = self.downloadedLicence?.get(at: indexPath.row) {
cell?.configure(licence: licence, config: self.config) cell?.configure(licence: licence, config: self.config)
} }
return cell! return cell!
} }
override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
// Automatic dimension // Automatic dimension
return UITableViewAutomaticDimension return UITableViewAutomaticDimension
} }
// MARK: - Action // MARK: - Action
/// Handler for click on close button /// Handler for click on close button
@objc fileprivate func closePicker() { @objc fileprivate func closePicker() {
self.dismissController() self.dismissController()
} }
// MARK: - Navigation // MARK: - Navigation
/// Dismiss the OpenSourceController /// Dismiss the OpenSourceController
func dismissController() { func dismissController() {
DispatchQueue.main.async { [weak self] in DispatchQueue.main.async { [weak self] in
@@ -33,7 +33,7 @@ public struct OpenSourceControllerConfig {
/// Will be applied to the navigation bar title /// Will be applied to the navigation bar title
public var title: String = "Tiers library" public var title: String = "Tiers library"
// Verbose mode for print log when licence are downloaded /// Verbose mode for print log when licence are downloaded
public var verbose: Bool = false public var verbose: Bool = false
/// UI-specific configuration. /// UI-specific configuration.