123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- //
- // FKLiveViewModel.m
- // FirstLink
- //
- // Created by Lofty on 16/10/13.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKLiveViewModel.h"
- #import "FKShoppingLiveBrandCell.h"
- #import "FKShoppingLiveProductCell.h"
- #import "FKShoppingLiveActivityHead.h"
- #import "FKShoppingLiveActivityProduct.h"
- @implementation FKLiveViewModel
- - (void)addItems:(NSArray *)array {
- if (array.count > 0) {
- [self.items addObjectsFromArray:array];
- }
- }
- - (NSInteger)itemCount{
- return self.items.count;
- }
- - (FKLivesProductItem *)itemAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section >= 0 && indexPath.section < self.items.count) {
- return self.items[indexPath.section];
- }
- return nil;
- }
- - (BOOL)isEmpty{
- if (!self.items.count) {
- return YES;
- }
- return NO;
- }
- - (kLiveCellType)cellTypeAtIndexPath:(NSIndexPath *)indexPath{
- FKLivesProductItem *item = [self itemAtIndexPath:indexPath];
- if (item.source == kShoppingLivesSourceRecommend) {
- return (indexPath.row == 0 ? kLiveCellTypeActivityHead : kLiveCellTypeActivityProduct);
- } else {
- return (indexPath.row == 0 ? kLiveCellTypeBrandHead : kLiveCellTypeProduct);
- }
- return kLiveCellTypeNone;
- }
- - (NSString *)cellIdentifiyAtIndexPath:(NSIndexPath *)indexPath{
- kLiveCellType cellType = [self cellTypeAtIndexPath:indexPath];
- switch (cellType) {
- case kLiveCellTypeBrandHead:
- return NSStringFromClass([FKShoppingLiveBrandCell class]);
- case kLiveCellTypeProduct:
- return NSStringFromClass([FKShoppingLiveProductCell class]);
- case kLiveCellTypeActivityHead:
- return NSStringFromClass([FKShoppingLiveActivityHead class]);
- case kLiveCellTypeActivityProduct:
- return NSStringFromClass([FKShoppingLiveActivityProduct class]);
- default:
- break;
- }
- return nil;
- }
- - (CGFloat)heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- kLiveCellType cellType = [self cellTypeAtIndexPath:indexPath];
- switch (cellType) {
- case kLiveCellTypeBrandHead:
- return [FKShoppingLiveBrandCell height];
- case kLiveCellTypeProduct:
- return [FKShoppingLiveProductCell height];
- case kLiveCellTypeActivityHead:
- return [FKShoppingLiveActivityHead height];
- case kLiveCellTypeActivityProduct:
- return [FKShoppingLiveActivityProduct height];
- default:
- break;
- }
- return 0.0f;
- }
- #pragma mark - Property
- - (NSMutableArray *)items {
- if (!_items) {
- _items = [NSMutableArray array];
- }
- return _items;
- }
- @end
|