2019-12-19 17:32:49 +00:00
|
|
|
/*
|
2023-04-06 09:44:16 +00:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2019-12-19 17:32:49 +00:00
|
|
|
*
|
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-04-07 18:20:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#import "PostSectionController.h"
|
|
|
|
|
|
|
|
|
|
#import "CommentCell.h"
|
2019-12-19 17:32:49 +00:00
|
|
|
#import "InteractiveCell.h"
|
|
|
|
|
#import "PhotoCell.h"
|
|
|
|
|
#import "Post.h"
|
2017-04-07 18:20:37 +00:00
|
|
|
#import "UserInfoCell.h"
|
|
|
|
|
|
|
|
|
|
static NSInteger cellsBeforeComments = 3;
|
|
|
|
|
|
|
|
|
|
@implementation PostSectionController {
|
|
|
|
|
Post *_post;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-19 15:17:56 +00:00
|
|
|
#pragma mark - IGListSectionController Overrides
|
2017-04-07 18:20:37 +00:00
|
|
|
|
|
|
|
|
- (NSInteger)numberOfItems {
|
|
|
|
|
return cellsBeforeComments + _post.comments.count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (CGSize)sizeForItemAtIndex:(NSInteger)index {
|
|
|
|
|
const CGFloat width = self.collectionContext.containerSize.width;
|
|
|
|
|
CGFloat height;
|
|
|
|
|
if (index == 0 || index == 2) {
|
|
|
|
|
height = 41.0;
|
|
|
|
|
} else if (index == 1) {
|
|
|
|
|
height = width; // square
|
|
|
|
|
} else {
|
|
|
|
|
height = 25.0;
|
|
|
|
|
}
|
|
|
|
|
return CGSizeMake(width, height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index {
|
|
|
|
|
Class cellClass;
|
|
|
|
|
if (index == 0) {
|
|
|
|
|
cellClass = [UserInfoCell class];
|
|
|
|
|
} else if (index == 1) {
|
|
|
|
|
cellClass = [PhotoCell class];
|
|
|
|
|
} else if (index == 2) {
|
|
|
|
|
cellClass = [InteractiveCell class];
|
|
|
|
|
} else {
|
|
|
|
|
cellClass = [CommentCell class];
|
|
|
|
|
}
|
|
|
|
|
id cell = [self.collectionContext dequeueReusableCellOfClass:cellClass forSectionController:self atIndex:index];
|
|
|
|
|
if ([cell isKindOfClass:[CommentCell class]]) {
|
|
|
|
|
[(CommentCell *)cell setComment:_post.comments[index - cellsBeforeComments]];
|
|
|
|
|
} else if ([cell isKindOfClass:[UserInfoCell class]]) {
|
|
|
|
|
[(UserInfoCell *)cell setName:_post.username];
|
|
|
|
|
}
|
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)didUpdateToObject:(id)object {
|
|
|
|
|
_post = object;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|