|
|
@ -73,8 +73,8 @@ class DetailViewController: UIViewController, UICollectionViewDelegateFlowLayout |
|
|
collectionView.dataSource = self |
|
|
collectionView.dataSource = self |
|
|
collectionView.delegate = self |
|
|
collectionView.delegate = self |
|
|
collectionView.registerClass(ItemCell.self, forCellWithReuseIdentifier: "Cell") |
|
|
collectionView.registerClass(ItemCell.self, forCellWithReuseIdentifier: "Cell") |
|
|
collectionView.backgroundColor = UIColor.greenColor() |
|
|
|
|
|
collectionView.registerClass(ItemCell.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "HeaderView"); |
|
|
|
|
|
|
|
|
collectionView.backgroundColor = UIColor.lightGrayColor() |
|
|
|
|
|
collectionView.registerClass(HeaderCell.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "HeaderView"); |
|
|
|
|
|
|
|
|
view.addSubview(collectionView) |
|
|
view.addSubview(collectionView) |
|
|
view.autoresizesSubviews = true |
|
|
view.autoresizesSubviews = true |
|
|
@ -95,19 +95,22 @@ class DetailViewController: UIViewController, UICollectionViewDelegateFlowLayout |
|
|
let index = notification.object as! Int |
|
|
let index = notification.object as! Int |
|
|
|
|
|
|
|
|
if let detail: MediaItem = self.detailItem { |
|
|
if let detail: MediaItem = self.detailItem { |
|
|
collectionView.performBatchUpdates( { |
|
|
|
|
|
let path = NSIndexPath(forItem: 0, inSection: index) |
|
|
|
|
|
self.collectionView.reloadItemsAtIndexPaths([path]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
collectionView.performBatchUpdates({ |
|
|
var newItems = [NSIndexPath]() |
|
|
var newItems = [NSIndexPath]() |
|
|
var j = 0 |
|
|
var j = 0 |
|
|
for i in detail.children[index].children { |
|
|
|
|
|
if j >= 1 { |
|
|
|
|
|
newItems.append(NSIndexPath(forItem: j, inSection: index)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if count(detail.children) > index { |
|
|
|
|
|
let path = NSIndexPath(forItem: 0, inSection: index) |
|
|
|
|
|
self.collectionView.reloadItemsAtIndexPaths([path]) |
|
|
|
|
|
|
|
|
|
|
|
for i in detail.children[index].children { |
|
|
|
|
|
if j >= 1 { |
|
|
|
|
|
newItems.append(NSIndexPath(forItem: j, inSection: index)) |
|
|
|
|
|
} |
|
|
|
|
|
j++ |
|
|
} |
|
|
} |
|
|
j++ |
|
|
|
|
|
|
|
|
self.collectionView.insertItemsAtIndexPaths(newItems) |
|
|
} |
|
|
} |
|
|
self.collectionView.insertItemsAtIndexPaths(newItems) |
|
|
|
|
|
return |
|
|
return |
|
|
}, completion: nil) |
|
|
}, completion: nil) |
|
|
} |
|
|
} |
|
|
@ -125,8 +128,8 @@ class DetailViewController: UIViewController, UICollectionViewDelegateFlowLayout |
|
|
println("couldn't find index path"); |
|
|
println("couldn't find index path"); |
|
|
} else { |
|
|
} else { |
|
|
if let detail: MediaItem = self.detailItem { |
|
|
if let detail: MediaItem = self.detailItem { |
|
|
if (detail.loaded) { |
|
|
|
|
|
let items = detail.children[indexPath!.section] |
|
|
|
|
|
|
|
|
let items = detail.children[indexPath!.section] |
|
|
|
|
|
if (items.loaded) { |
|
|
if count(items.children) == 0 { |
|
|
if count(items.children) == 0 { |
|
|
} else { |
|
|
} else { |
|
|
if indexPath!.item >= count(items.children) { |
|
|
if indexPath!.item >= count(items.children) { |
|
|
@ -155,7 +158,6 @@ class DetailViewController: UIViewController, UICollectionViewDelegateFlowLayout |
|
|
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { |
|
|
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { |
|
|
if let detail: MediaItem = self.detailItem { |
|
|
if let detail: MediaItem = self.detailItem { |
|
|
let cnt = count(detail.children) |
|
|
let cnt = count(detail.children) |
|
|
println(cnt) |
|
|
|
|
|
return cnt |
|
|
return cnt |
|
|
} |
|
|
} |
|
|
return 0 |
|
|
return 0 |
|
|
@ -168,7 +170,6 @@ class DetailViewController: UIViewController, UICollectionViewDelegateFlowLayout |
|
|
if n == 0 { |
|
|
if n == 0 { |
|
|
return 1 |
|
|
return 1 |
|
|
} |
|
|
} |
|
|
println(n) |
|
|
|
|
|
return n |
|
|
return n |
|
|
} |
|
|
} |
|
|
return 0 |
|
|
return 0 |
|
|
@ -190,7 +191,6 @@ class DetailViewController: UIViewController, UICollectionViewDelegateFlowLayout |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
cell.backgroundColor = UIColor.blueColor() |
|
|
|
|
|
return cell |
|
|
return cell |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -203,11 +203,10 @@ class DetailViewController: UIViewController, UICollectionViewDelegateFlowLayout |
|
|
collectionView.dequeueReusableSupplementaryViewOfKind(kind, |
|
|
collectionView.dequeueReusableSupplementaryViewOfKind(kind, |
|
|
withReuseIdentifier: "HeaderView", |
|
|
withReuseIdentifier: "HeaderView", |
|
|
forIndexPath: indexPath) |
|
|
forIndexPath: indexPath) |
|
|
as! ItemCell |
|
|
|
|
|
|
|
|
as! HeaderCell |
|
|
let items = detailItem!.children[indexPath.section] |
|
|
let items = detailItem!.children[indexPath.section] |
|
|
|
|
|
|
|
|
headerView.label.text = items.name |
|
|
|
|
|
headerView.backgroundColor = UIColor.yellowColor() |
|
|
|
|
|
|
|
|
headerView.setItem(items) |
|
|
return headerView |
|
|
return headerView |
|
|
default: |
|
|
default: |
|
|
assert(false, "Unexpected element kind") |
|
|
assert(false, "Unexpected element kind") |
|
|
@ -216,8 +215,8 @@ class DetailViewController: UIViewController, UICollectionViewDelegateFlowLayout |
|
|
|
|
|
|
|
|
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { |
|
|
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { |
|
|
if let detail: MediaItem = self.detailItem { |
|
|
if let detail: MediaItem = self.detailItem { |
|
|
if (detail.loaded) { |
|
|
|
|
|
var items = detail.children[indexPath.section] |
|
|
|
|
|
|
|
|
var items = detail.children[indexPath.section] |
|
|
|
|
|
if (items.loaded) { |
|
|
if indexPath.item >= count(items.children) { |
|
|
if indexPath.item >= count(items.children) { |
|
|
println(items.name) |
|
|
println(items.name) |
|
|
} else { |
|
|
} else { |
|
|
|