Commit 8a0d7d01 by Daniel Dahan

updated App example project

parent dd913a42
...@@ -48,7 +48,7 @@ class FeedViewController: UIViewController { ...@@ -48,7 +48,7 @@ class FeedViewController: UIViewController {
private var collectionView: MaterialCollectionView! private var collectionView: MaterialCollectionView!
/// Image thumbnail height. /// Image thumbnail height.
private var thumbnailHieght: CGFloat = 112 private var thumbnailHieght: CGFloat = 300
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
...@@ -141,7 +141,7 @@ class FeedViewController: UIViewController { ...@@ -141,7 +141,7 @@ class FeedViewController: UIViewController {
collectionView = MaterialCollectionView() collectionView = MaterialCollectionView()
collectionView.dataSource = self collectionView.dataSource = self
collectionView.delegate = self collectionView.delegate = self
collectionView.spacingPreset = .Spacing1 collectionView.spacingPreset = .Spacing2
collectionView.contentInsetPreset = .Square1 collectionView.contentInsetPreset = .Square1
collectionView.registerClass(MaterialCollectionViewCell.self, forCellWithReuseIdentifier: "MaterialCollectionViewCell") collectionView.registerClass(MaterialCollectionViewCell.self, forCellWithReuseIdentifier: "MaterialCollectionViewCell")
...@@ -231,46 +231,36 @@ extension FeedViewController: MaterialCollectionViewDataSource { ...@@ -231,46 +231,36 @@ extension FeedViewController: MaterialCollectionViewDataSource {
if let data: Dictionary<String, AnyObject> = item.data as? Dictionary<String, AnyObject> { if let data: Dictionary<String, AnyObject> = item.data as? Dictionary<String, AnyObject> {
var cardView: CardView? = cell.contentView.subviews.first as? CardView var cardView: ImageCardView? = cell.contentView.subviews.first as? ImageCardView
// Only build the template if the CardView doesn't exist. // Only build the template if the CardView doesn't exist.
if nil == cardView { if nil == cardView {
cardView = CardView() cardView = ImageCardView()
cell.backgroundColor = nil cell.backgroundColor = nil
cell.pulseColor = nil cell.pulseColor = nil
cell.contentView.addSubview(cardView!) cell.contentView.addSubview(cardView!)
cardView!.pulseScale = false cardView!.pulseScale = false
cardView!.divider = false cardView!.divider = false
cardView!.depth = .None cardView!.depth = .None
cardView!.contentsGravityPreset = .Left cardView!.contentInsetPreset = .Square2
cardView!.contentInsetPreset = .Square3
cardView!.contentInset.bottom /= 2 cardView!.contentInset.bottom /= 2
cardView!.cornerRadiusPreset = .Radius1 cardView!.cornerRadius = 2
cardView!.rightButtonsInset.right = -8
let titleLabel: UILabel = UILabel() let titleLabel: UILabel = UILabel()
titleLabel.textColor = MaterialColor.grey.darken4 titleLabel.textColor = MaterialColor.grey.darken4
titleLabel.font = RobotoFont.regularWithSize(18) titleLabel.font = RobotoFont.regularWithSize(18)
cardView!.titleLabel = titleLabel cardView!.titleLabel = titleLabel
cardView!.titleLabelInset.left = 120
let detailLabel: UILabel = UILabel() let detailLabel: UILabel = UILabel()
detailLabel.textColor = MaterialColor.grey.darken2 detailLabel.textColor = MaterialColor.grey.darken2
detailLabel.font = RobotoFont.regular detailLabel.font = RobotoFont.regular
cardView!.detailView = detailLabel detailLabel.numberOfLines = 0
cardView!.detailViewInset.left = 120
let image: UIImage? = UIImage(named: "ic_share_white_18pt")?.imageWithRenderingMode(.AlwaysTemplate) cardView!.detailView = detailLabel
let shareButton: FlatButton = FlatButton()
shareButton.pulseScale = false
shareButton.pulseColor = MaterialColor.grey.base
shareButton.tintColor = MaterialColor.grey.base
shareButton.setImage(image, forState: .Normal)
shareButton.setImage(image, forState: .Highlighted)
cardView!.rightButtons = [shareButton]
cell.contentView.addSubview(cardView!) cell.contentView.addSubview(cardView!)
} }
...@@ -280,9 +270,9 @@ extension FeedViewController: MaterialCollectionViewDataSource { ...@@ -280,9 +270,9 @@ extension FeedViewController: MaterialCollectionViewDataSource {
(cardView?.detailView as? UILabel)?.text = data["detail"] as? String (cardView?.detailView as? UILabel)?.text = data["detail"] as? String
// Asynchronously the load image. // Asynchronously the load image.
let height: CGFloat = thumbnailHieght let height: CGFloat = 200
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)) {
let image: UIImage? = UIImage(named: data["image"] as! String)?.resize(toHeight: height)?.crop(toWidth: height, toHeight: height) let image: UIImage? = UIImage(named: data["image"] as! String)?.resize(toWidth: cell.bounds.width)?.crop(toWidth: cell.bounds.width, toHeight: height)
dispatch_sync(dispatch_get_main_queue()) { dispatch_sync(dispatch_get_main_queue()) {
cardView?.image = image cardView?.image = image
} }
......
...@@ -31,12 +31,6 @@ ...@@ -31,12 +31,6 @@
import UIKit import UIKit
import Material import Material
private struct Item {
var text: String
var detail: String
var image: UIImage?
}
class RecipesViewController: UIViewController { class RecipesViewController: UIViewController {
/// NavigationBar title label. /// NavigationBar title label.
private var titleLabel: UILabel! private var titleLabel: UILabel!
...@@ -51,7 +45,7 @@ class RecipesViewController: UIViewController { ...@@ -51,7 +45,7 @@ class RecipesViewController: UIViewController {
private var tableView: UITableView! private var tableView: UITableView!
/// A list of all the Author Bond types. /// A list of all the Author Bond types.
private var items: Array<Item>! private var items: Array<MaterialDataSourceItem>!
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
...@@ -93,15 +87,56 @@ class RecipesViewController: UIViewController { ...@@ -93,15 +87,56 @@ class RecipesViewController: UIViewController {
/// Prepares the items Array. /// Prepares the items Array.
private func prepareItems() { private func prepareItems() {
items = Array<Item>() items = [
items.append(Item(text: "Summer BBQ", detail: "Wish I could come, but I am out of town this weekend.", image: UIImage(named: "Profile1"))) MaterialDataSourceItem(
items.append(Item(text: "Birthday gift", detail: "Have any ideas about what we should get Heidi for her birthday?", image: UIImage(named: "Profile2"))) data: [
items.append(Item(text: "Brunch this weekend?", detail: "I'll be in your neighborhood doing errands this weekend.", image: UIImage(named: "Profile3"))) "title": "Summer BBQ",
items.append(Item(text: "Giants game", detail: "Are we on this weekend for the game?", image: UIImage(named: "Profile4"))) "detail": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
items.append(Item(text: "Recipe to try", detail: "We should eat this: Squash, Corn and tomatillo Tacos.", image: UIImage(named: "Profile5"))) "date": "February 26, 2016",
items.append(Item(text: "Interview", detail: "The candidate will be arriving at 11:30, are you free?", image: UIImage(named: "Profile6"))) "image": "AssortmentOfDessert"
items.append(Item(text: "Book recommendation", detail: "I found the book title, Surely You’re Joking, Mr. Feynman!", image: UIImage(named: "Profile7"))) ]
items.append(Item(text: "Oui oui", detail: "Do you have Paris recommendations? Have you ever been?", image: UIImage(named: "Profile8"))) ),
MaterialDataSourceItem(
data: [
"title": "Birthday gift",
"detail": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"date": "February 26, 2016",
"image": "AssortmentOfFood"
]
),
MaterialDataSourceItem(
data: [
"title": "Brunch this weekend?",
"detail": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"date": "February 26, 2016",
"image": "AvocadoIceCream"
]
),
MaterialDataSourceItem(
data: [
"title": "Giants game",
"detail": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"date": "February 26, 2016",
"image": "HeartCookies"
]
),
MaterialDataSourceItem(
data: [
"title": "Recipe to try",
"detail": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"date": "February 26, 2016",
"image": "VeganHempBalls"
]
),
MaterialDataSourceItem(
data: [
"title": "Interview",
"detail": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"date": "February 26, 2016",
"image": "VeganPieAbove"
]
)
]
} }
/// Prepares the tableView. /// Prepares the tableView.
...@@ -160,15 +195,19 @@ extension RecipesViewController: UITableViewDataSource { ...@@ -160,15 +195,19 @@ extension RecipesViewController: UITableViewDataSource {
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: MaterialTableViewCell = MaterialTableViewCell(style: .Subtitle, reuseIdentifier: "MaterialTableViewCell") let cell: MaterialTableViewCell = MaterialTableViewCell(style: .Subtitle, reuseIdentifier: "MaterialTableViewCell")
let item: Item = items[indexPath.row] let item: MaterialDataSourceItem = items[indexPath.row]
cell.selectionStyle = .None
cell.textLabel!.text = item.text if let data: Dictionary<String, AnyObject> = item.data as? Dictionary<String, AnyObject> {
cell.textLabel!.font = RobotoFont.regular
cell.detailTextLabel!.text = item.detail cell.selectionStyle = .None
cell.detailTextLabel!.font = RobotoFont.regular cell.textLabel?.text = data["title"] as? String
cell.detailTextLabel!.textColor = MaterialColor.grey.darken1 cell.textLabel?.font = RobotoFont.regular
cell.imageView!.image = item.image?.resize(toWidth: 40) cell.detailTextLabel?.text = data["detail"] as? String
cell.imageView!.layer.cornerRadius = 20 cell.detailTextLabel?.font = RobotoFont.regular
cell.detailTextLabel?.textColor = MaterialColor.grey.darken1
cell.imageView!.layer.cornerRadius = 32
cell.imageView!.image = UIImage(named: data["image"] as! String)?.crop(toWidth: 64, toHeight: 64)
}
return cell return cell
} }
......
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