Commit b2e465a7 by Daniel Dahan

pattern made for BasicCollectionViewCell

parent 513e81ef
......@@ -164,7 +164,9 @@ extension AppLeftViewController: UITableViewDelegate {
let item: Item = items[indexPath.row]
if let a: MenuViewController = sideNavigationViewController?.mainViewController as? MenuViewController {
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
......
......@@ -72,18 +72,18 @@ extension FeedViewController: MaterialCollectionViewDataSource {
/// Retrieves the items for the collectionView.
func items() -> Array<MaterialDataSourceItem> {
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": "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": "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": "Talk to that agency guy, a friend of #Jen, about renting...", "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"], 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"], 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"], width: 125, height: 125),
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": "#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": "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": "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": "Talk to that agency guy, a friend of #Jen, about renting...", "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"], 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"], dataSourceItemSize: .Large),
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"], dataSourceItemSize: .Default),
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"], dataSourceItemSize: .Default),
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"], dataSourceItemSize: .Default),
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"], dataSourceItemSize: .Default),
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 {
let c: BasicCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! BasicCollectionViewCell
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 nil == data["title"] {
......@@ -114,28 +114,28 @@ extension FeedViewController: MaterialCollectionViewDataSource {
c.titleLabel = titleLabel
}
if nil == data["detail"] {
c.detailLabel = nil
} else if nil == c.detailLabel {
let detailLabel: UILabel = UILabel()
detailLabel.numberOfLines = 0
detailLabel.lineBreakMode = .ByTruncatingTail
detailLabel.font = RobotoFont.regularWithSize(12)
detailLabel.textColor = MaterialColor.blueGrey.darken4
detailLabel.backgroundColor = MaterialColor.clear
c.detailLabel = detailLabel
}
if nil == c.controlView {
c.controlView = ControlView()
c.controlView!.backgroundColor = nil
let date: UILabel = UILabel()
date.font = RobotoFont.regularWithSize(12)
date.textColor = MaterialColor.grey.lighten1
c.controlView?.contentView.addSubview(date)
c.controlView?.grid.views = [date]
}
// if nil == data["detail"] {
// c.detailLabel = nil
// } else if nil == c.detailLabel {
// let detailLabel: UILabel = UILabel()
// detailLabel.numberOfLines = 0
// detailLabel.lineBreakMode = .ByTruncatingTail
// detailLabel.font = RobotoFont.regularWithSize(12)
// detailLabel.textColor = MaterialColor.blueGrey.darken4
// detailLabel.backgroundColor = MaterialColor.clear
// c.detailLabel = detailLabel
// }
//
// if nil == c.controlView {
// c.controlView = ControlView()
// c.controlView!.backgroundColor = nil
//
// let date: UILabel = UILabel()
// date.font = RobotoFont.regularWithSize(12)
// date.textColor = MaterialColor.grey.lighten1
// c.controlView?.contentView.addSubview(date)
// c.controlView?.grid.views = [date]
// }
c.titleLabel?.text = data["title"] as? String
c.detailLabel?.text = data["detail"] as? String
......
......@@ -74,7 +74,69 @@ public class BasicCollectionViewCell : MaterialCollectionViewCell {
/// Reloads the view.
public func reloadView() {
contentView.grid.views = []
switch height {
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()
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()
......@@ -85,24 +147,24 @@ public class BasicCollectionViewCell : MaterialCollectionViewCell {
var c: Int = 0
if nil != titleLabel && nil == detailLabel && nil == controlView {
a = 12
a = rows
} else if nil == titleLabel && nil != detailLabel && nil == controlView {
b = 12
b = rows
} else if nil == titleLabel && nil == detailLabel && nil != controlView {
c = 12
c = rows
} else if nil != titleLabel && nil != detailLabel && nil == controlView {
a = 3
b = 9
a = 1
b = rows - 1
} else if nil != titleLabel && nil == detailLabel && nil != controlView {
a = 9
c = 3
a = rows - 1
c = 1
} else if nil == titleLabel && nil != detailLabel && nil != controlView {
b = 9
c = 3
b = rows - 1
c = 1
} else if nil != titleLabel && nil != detailLabel && nil != controlView {
a = 3
b = 6
c = 3
a = 1
b = rows - 6
c = 1
}
if let v: UILabel = titleLabel {
......@@ -126,7 +188,67 @@ public class BasicCollectionViewCell : MaterialCollectionViewCell {
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 = []
}
}
}
......@@ -31,5 +31,25 @@
import UIKit
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 {
public override func prepareLayout() {
let dataSource: MaterialCollectionViewDataSource = collectionView!.dataSource as! MaterialCollectionViewDataSource
prepareLayoutForItems(dataSource.items())
}
items = dataSource.items()
public func prepareLayoutForItems(items: Array<MaterialDataSourceItem>) {
self.items = items
layoutItems.removeAll()
offset.x = contentInset.left
......@@ -124,8 +127,8 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
var indexPath: NSIndexPath?
for var i: Int = 0, l: Int = items!.count - 1; i <= l; ++i {
let item: MaterialDataSourceItem = items![i]
for var i: Int = 0, l: Int = items.count - 1; i <= l; ++i {
let item: MaterialDataSourceItem = items[i]
indexPath = NSIndexPath(forItem: i, inSection: 0)
layoutItems.append((layoutAttributesForItemAtIndexPath(indexPath!)!, indexPath!))
......
......@@ -30,19 +30,26 @@
import UIKit
public enum MaterialDataSourceItemSize {
case Small
case Default
case Large
}
public struct MaterialDataSourceItem {
public var data: AnyObject?
public var size: CGSize?
public var x: CGFloat?
public var y: CGFloat?
public var width: 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.x = x
self.y = y
self.width = width
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