Commit b2e465a7 by Daniel Dahan

pattern made for BasicCollectionViewCell

parent 513e81ef
...@@ -164,7 +164,9 @@ extension AppLeftViewController: UITableViewDelegate { ...@@ -164,7 +164,9 @@ extension AppLeftViewController: UITableViewDelegate {
let item: Item = items[indexPath.row] let item: Item = items[indexPath.row]
if let a: MenuViewController = sideNavigationViewController?.mainViewController as? MenuViewController { if let a: MenuViewController = sideNavigationViewController?.mainViewController as? MenuViewController {
if let b: NavigationBarViewController = a.mainViewController as? NavigationBarViewController { if let b: NavigationBarViewController = a.mainViewController as? NavigationBarViewController {
b.transitionFromMainViewController("Feed" == item.text ? FeedViewController() : InboxViewController(), options: [.TransitionCrossDissolve]) b.transitionFromMainViewController("Feed" == item.text ? FeedViewController() : InboxViewController(), duration: 0.75, options: [.TransitionCrossDissolve]) { [weak self] _ in
self?.sideNavigationViewController?.closeLeftView()
}
} }
} }
return indexPath return indexPath
......
...@@ -72,18 +72,18 @@ extension FeedViewController: MaterialCollectionViewDataSource { ...@@ -72,18 +72,18 @@ extension FeedViewController: MaterialCollectionViewDataSource {
/// Retrieves the items for the collectionView. /// Retrieves the items for the collectionView.
func items() -> Array<MaterialDataSourceItem> { func items() -> Array<MaterialDataSourceItem> {
return [ return [
MaterialDataSourceItem(data: ["title": "Material", "detail": "#Pumpkin #pie - Preheat oven to 425 degrees F. Whisk pumpkin, sweetened condensed milk, eggs...", "date": "February 26, 2016"], width: 125, height: 125), MaterialDataSourceItem(data: ["title": "Material", "detail": "#Pumpkin #pie - Preheat oven to 425 degrees F. Whisk pumpkin, sweetened condensed milk, eggs...", "date": "February 26, 2016"], dataSourceItemSize: .Small),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Wow!!! I really really need this fabulous pair. Action is ending tonight #sneakerhead", "date": "February 26, 2016"], width: 125, height: 125), MaterialDataSourceItem(data: ["title": "Material", "detail": "Wow!!! I really really need this fabulous pair. Action is ending tonight #sneakerhead", "date": "February 26, 2016"], dataSourceItemSize: .Default),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Discovered an amazing #cofeeshop with the best #latte at Adelaide and Spadina #Toronto They also...", "date": "February 26, 2016"], width: 125, height: 125), MaterialDataSourceItem(data: ["title": "Material", "detail": "Discovered an amazing #cofeeshop with the best #latte at Adelaide and Spadina #Toronto They also...", "date": "February 26, 2016"], dataSourceItemSize: .Large),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Talk to that agency guy, a friend of #Jen, about renting...", "date": "February 26, 2016"], width: 125, height: 125), MaterialDataSourceItem(data: ["title": "Material", "detail": "Talk to that agency guy, a friend of #Jen, about renting...", "date": "February 26, 2016"], dataSourceItemSize: .Small),
MaterialDataSourceItem(data: ["title": "Material", "detail": "#Pumpkin #pie - Preheat oven to 425 degrees F. Whisk pumpkin, sweetened condensed milk, eggs...", "date": "February 26, 2016"], width: 125, height: 125), MaterialDataSourceItem(data: ["title": "Material", "detail": "#Pumpkin #pie - Preheat oven to 425 degrees F. Whisk pumpkin, sweetened condensed milk, eggs...", "date": "February 26, 2016"], dataSourceItemSize: .Default),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Wow!!! I really really need this fabulous pair. Action is ending tonight #sneakerhead", "date": "February 26, 2016"], width: 125, height: 125), MaterialDataSourceItem(data: ["title": "Material", "detail": "Wow!!! I really really need this fabulous pair. Action is ending tonight #sneakerhead", "date": "February 26, 2016"], dataSourceItemSize: .Large),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Discovered an amazing #cofeeshop with the best #latte at Adelaide and Spadina #Toronto They also...", "date": "February 26, 2016"], width: 125, height: 125), MaterialDataSourceItem(data: ["title": "Material", "detail": "Discovered an amazing #cofeeshop with the best #latte at Adelaide and Spadina #Toronto They also...", "date": "February 26, 2016"], dataSourceItemSize: .Default),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Talk to that agency guy, a friend of #Jen, about renting...", "date": "February 26, 2016"], width: 125, height: 125), MaterialDataSourceItem(data: ["title": "Material", "detail": "Talk to that agency guy, a friend of #Jen, about renting...", "date": "February 26, 2016"], dataSourceItemSize: .Default),
MaterialDataSourceItem(data: ["title": "Material", "detail": "#Pumpkin #pie - Preheat oven to 425 degrees F. Whisk pumpkin, sweetened condensed milk, eggs...", "date": "February 26, 2016"], width: 125, height: 125), MaterialDataSourceItem(data: ["title": "Material", "detail": "#Pumpkin #pie - Preheat oven to 425 degrees F. Whisk pumpkin, sweetened condensed milk, eggs...", "date": "February 26, 2016"], dataSourceItemSize: .Default),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Wow!!! I really really need this fabulous pair. Action is ending tonight #sneakerhead", "date": "February 26, 2016"], width: 125, height: 125), MaterialDataSourceItem(data: ["title": "Material", "detail": "Wow!!! I really really need this fabulous pair. Action is ending tonight #sneakerhead", "date": "February 26, 2016"], dataSourceItemSize: .Default),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Discovered an amazing #cofeeshop with the best #latte at Adelaide and Spadina #Toronto They also...", "date": "February 26, 2016"], width: 125, height: 125), MaterialDataSourceItem(data: ["title": "Material", "detail": "Discovered an amazing #cofeeshop with the best #latte at Adelaide and Spadina #Toronto They also...", "date": "February 26, 2016"], dataSourceItemSize: .Default),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Talk to that agency guy, a friend of #Jen, about renting...", "date": "February 26, 2016"], width: 125, height: 125) MaterialDataSourceItem(data: ["title": "Material", "detail": "Talk to that agency guy, a friend of #Jen, about renting...", "date": "February 26, 2016"], dataSourceItemSize: .Default)
] ]
} }
...@@ -102,7 +102,7 @@ extension FeedViewController: MaterialCollectionViewDataSource { ...@@ -102,7 +102,7 @@ extension FeedViewController: MaterialCollectionViewDataSource {
let c: BasicCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! BasicCollectionViewCell let c: BasicCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! BasicCollectionViewCell
let item: MaterialDataSourceItem = items()[indexPath.item] let item: MaterialDataSourceItem = items()[indexPath.item]
c.backgroundColor = MaterialColor.white c.backgroundColor = MaterialColor.blue.base
if let data: Dictionary<String, AnyObject> = item.data as? Dictionary<String, AnyObject> { if let data: Dictionary<String, AnyObject> = item.data as? Dictionary<String, AnyObject> {
if nil == data["title"] { if nil == data["title"] {
...@@ -114,28 +114,28 @@ extension FeedViewController: MaterialCollectionViewDataSource { ...@@ -114,28 +114,28 @@ extension FeedViewController: MaterialCollectionViewDataSource {
c.titleLabel = titleLabel c.titleLabel = titleLabel
} }
if nil == data["detail"] { // if nil == data["detail"] {
c.detailLabel = nil // c.detailLabel = nil
} else if nil == c.detailLabel { // } else if nil == c.detailLabel {
let detailLabel: UILabel = UILabel() // let detailLabel: UILabel = UILabel()
detailLabel.numberOfLines = 0 // detailLabel.numberOfLines = 0
detailLabel.lineBreakMode = .ByTruncatingTail // detailLabel.lineBreakMode = .ByTruncatingTail
detailLabel.font = RobotoFont.regularWithSize(12) // detailLabel.font = RobotoFont.regularWithSize(12)
detailLabel.textColor = MaterialColor.blueGrey.darken4 // detailLabel.textColor = MaterialColor.blueGrey.darken4
detailLabel.backgroundColor = MaterialColor.clear // detailLabel.backgroundColor = MaterialColor.clear
c.detailLabel = detailLabel // c.detailLabel = detailLabel
} // }
//
if nil == c.controlView { // if nil == c.controlView {
c.controlView = ControlView() // c.controlView = ControlView()
c.controlView!.backgroundColor = nil // c.controlView!.backgroundColor = nil
//
let date: UILabel = UILabel() // let date: UILabel = UILabel()
date.font = RobotoFont.regularWithSize(12) // date.font = RobotoFont.regularWithSize(12)
date.textColor = MaterialColor.grey.lighten1 // date.textColor = MaterialColor.grey.lighten1
c.controlView?.contentView.addSubview(date) // c.controlView?.contentView.addSubview(date)
c.controlView?.grid.views = [date] // c.controlView?.grid.views = [date]
} // }
c.titleLabel?.text = data["title"] as? String c.titleLabel?.text = data["title"] as? String
c.detailLabel?.text = data["detail"] as? String c.detailLabel?.text = data["detail"] as? String
......
...@@ -74,59 +74,181 @@ public class BasicCollectionViewCell : MaterialCollectionViewCell { ...@@ -74,59 +74,181 @@ public class BasicCollectionViewCell : MaterialCollectionViewCell {
/// Reloads the view. /// Reloads the view.
public func reloadView() { public func reloadView() {
contentView.grid.views = [] contentView.grid.views = []
contentView.grid.axis.direction = .Vertical switch height {
case 192:
for v in contentView.subviews { let rows: Int = Int(height / 48)
v.removeFromSuperview()
contentView.grid.axis.direction = .Vertical
contentView.grid.axis.rows = rows
for v in contentView.subviews {
v.removeFromSuperview()
}
var a: Int = 0
var b: Int = 0
var c: Int = 0
if nil != titleLabel && nil == detailLabel && nil == controlView {
a = rows
} else if nil == titleLabel && nil != detailLabel && nil == controlView {
b = rows
} else if nil == titleLabel && nil == detailLabel && nil != controlView {
c = rows
} else if nil != titleLabel && nil != detailLabel && nil == controlView {
a = 1
b = rows - 1
} else if nil != titleLabel && nil == detailLabel && nil != controlView {
a = rows - 1
c = 1
} else if nil == titleLabel && nil != detailLabel && nil != controlView {
b = rows - 1
c = 1
} else if nil != titleLabel && nil != detailLabel && nil != controlView {
a = 1
b = rows - 6
c = 1
}
if let v: UILabel = titleLabel {
v.grid.rows = a
contentView.addSubview(v)
contentView.grid.views?.append(v)
}
if let v: UILabel = detailLabel {
v.grid.rows = b
contentView.addSubview(v)
contentView.grid.views?.append(v)
}
if let v: ControlView = controlView {
v.grid.rows = c
contentView.addSubview(v)
contentView.grid.views?.append(v)
}
grid.views = [
contentView
]
contentView.grid.reloadLayout()
case 144:
let rows: Int = Int(height / 48)
contentView.grid.axis.direction = .Vertical
contentView.grid.axis.rows = rows
for v in contentView.subviews {
v.removeFromSuperview()
}
var a: Int = 0
var b: Int = 0
var c: Int = 0
if nil != titleLabel && nil == detailLabel && nil == controlView {
a = rows
} else if nil == titleLabel && nil != detailLabel && nil == controlView {
b = rows
} else if nil == titleLabel && nil == detailLabel && nil != controlView {
c = rows
} else if nil != titleLabel && nil != detailLabel && nil == controlView {
a = 1
b = rows - 1
} else if nil != titleLabel && nil == detailLabel && nil != controlView {
a = rows - 1
c = 1
} else if nil == titleLabel && nil != detailLabel && nil != controlView {
b = rows - 1
c = 1
} else if nil != titleLabel && nil != detailLabel && nil != controlView {
a = 1
b = rows - 6
c = 1
}
if let v: UILabel = titleLabel {
v.grid.rows = a
contentView.addSubview(v)
contentView.grid.views?.append(v)
}
if let v: UILabel = detailLabel {
v.grid.rows = b
contentView.addSubview(v)
contentView.grid.views?.append(v)
}
if let v: ControlView = controlView {
v.grid.rows = c
contentView.addSubview(v)
contentView.grid.views?.append(v)
}
grid.views = [
contentView
]
contentView.grid.reloadLayout()
case 192:
let rows: Int = Int(height / 48)
contentView.grid.axis.direction = .Vertical
contentView.grid.axis.rows = rows
for v in contentView.subviews {
v.removeFromSuperview()
}
var a: Int = 0
var b: Int = 0
var c: Int = 0
if nil != titleLabel && nil == detailLabel && nil == controlView {
a = rows
} else if nil == titleLabel && nil != detailLabel && nil == controlView {
b = rows
} else if nil == titleLabel && nil == detailLabel && nil != controlView {
c = rows
} else if nil != titleLabel && nil != detailLabel && nil == controlView {
a = 1
b = rows - 1
} else if nil != titleLabel && nil == detailLabel && nil != controlView {
a = rows - 1
c = 1
} else if nil == titleLabel && nil != detailLabel && nil != controlView {
b = rows - 1
c = 1
} else if nil != titleLabel && nil != detailLabel && nil != controlView {
a = 1
b = rows - 6
c = 1
}
if let v: UILabel = titleLabel {
v.grid.rows = a
contentView.addSubview(v)
contentView.grid.views?.append(v)
}
if let v: UILabel = detailLabel {
v.grid.rows = b
contentView.addSubview(v)
contentView.grid.views?.append(v)
}
if let v: ControlView = controlView {
v.grid.rows = c
contentView.addSubview(v)
contentView.grid.views?.append(v)
}
grid.views = [
contentView
]
contentView.grid.reloadLayout()
default:
grid.views = []
contentView.grid.views = []
} }
var a: Int = 0
var b: Int = 0
var c: Int = 0
if nil != titleLabel && nil == detailLabel && nil == controlView {
a = 12
} else if nil == titleLabel && nil != detailLabel && nil == controlView {
b = 12
} else if nil == titleLabel && nil == detailLabel && nil != controlView {
c = 12
} else if nil != titleLabel && nil != detailLabel && nil == controlView {
a = 3
b = 9
} else if nil != titleLabel && nil == detailLabel && nil != controlView {
a = 9
c = 3
} else if nil == titleLabel && nil != detailLabel && nil != controlView {
b = 9
c = 3
} else if nil != titleLabel && nil != detailLabel && nil != controlView {
a = 3
b = 6
c = 3
}
if let v: UILabel = titleLabel {
v.grid.rows = a
contentView.addSubview(v)
contentView.grid.views?.append(v)
}
if let v: UILabel = detailLabel {
v.grid.rows = b
contentView.addSubview(v)
contentView.grid.views?.append(v)
}
if let v: ControlView = controlView {
v.grid.rows = c
contentView.addSubview(v)
contentView.grid.views?.append(v)
}
grid.views = [
contentView
]
contentView.grid.reloadLayout()
} }
} }
...@@ -31,5 +31,25 @@ ...@@ -31,5 +31,25 @@
import UIKit import UIKit
public class BasicCollectionViewLayout : MaterialCollectionViewLayout { public class BasicCollectionViewLayout : MaterialCollectionViewLayout {
public override func prepareLayout() {
let dataSource: MaterialCollectionViewDataSource = collectionView!.dataSource as! MaterialCollectionViewDataSource
var items: Array<MaterialDataSourceItem> = dataSource.items()
for var i: Int = items.count - 1; 0 <= i; --i {
var v: MaterialDataSourceItem = items[i]
if let q: MaterialDataSourceItemSize = v.dataSourceItemSize {
switch q {
case .Small:
v.height = 96
case .Large:
v.height = 192
default:
v.height = 144
}
}
items[i] = v
}
prepareLayoutForItems(items)
}
} }
...@@ -115,8 +115,11 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout { ...@@ -115,8 +115,11 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
public override func prepareLayout() { public override func prepareLayout() {
let dataSource: MaterialCollectionViewDataSource = collectionView!.dataSource as! MaterialCollectionViewDataSource let dataSource: MaterialCollectionViewDataSource = collectionView!.dataSource as! MaterialCollectionViewDataSource
prepareLayoutForItems(dataSource.items())
items = dataSource.items() }
public func prepareLayoutForItems(items: Array<MaterialDataSourceItem>) {
self.items = items
layoutItems.removeAll() layoutItems.removeAll()
offset.x = contentInset.left offset.x = contentInset.left
...@@ -124,8 +127,8 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout { ...@@ -124,8 +127,8 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
var indexPath: NSIndexPath? var indexPath: NSIndexPath?
for var i: Int = 0, l: Int = items!.count - 1; i <= l; ++i { for var i: Int = 0, l: Int = items.count - 1; i <= l; ++i {
let item: MaterialDataSourceItem = items![i] let item: MaterialDataSourceItem = items[i]
indexPath = NSIndexPath(forItem: i, inSection: 0) indexPath = NSIndexPath(forItem: i, inSection: 0)
layoutItems.append((layoutAttributesForItemAtIndexPath(indexPath!)!, indexPath!)) layoutItems.append((layoutAttributesForItemAtIndexPath(indexPath!)!, indexPath!))
......
...@@ -30,19 +30,26 @@ ...@@ -30,19 +30,26 @@
import UIKit import UIKit
public enum MaterialDataSourceItemSize {
case Small
case Default
case Large
}
public struct MaterialDataSourceItem { public struct MaterialDataSourceItem {
public var data: AnyObject? public var data: AnyObject?
public var size: CGSize?
public var x: CGFloat? public var x: CGFloat?
public var y: CGFloat? public var y: CGFloat?
public var width: CGFloat? public var width: CGFloat?
public var height: CGFloat? public var height: CGFloat?
public var dataSourceItemSize: MaterialDataSourceItemSize?
public init(data: AnyObject? = nil, x: CGFloat? = nil, y: CGFloat? = nil, width: CGFloat? = nil, height: CGFloat? = nil) { public init(data: AnyObject? = nil, x: CGFloat? = nil, y: CGFloat? = nil, width: CGFloat? = nil, height: CGFloat? = nil, dataSourceItemSize: MaterialDataSourceItemSize? = nil) {
self.data = data self.data = data
self.x = x self.x = x
self.y = y self.y = y
self.width = width self.width = width
self.height = height self.height = height
self.dataSourceItemSize = dataSourceItemSize
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment