説明なし

FKLiveViewModel.m 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // FKLiveViewModel.m
  3. // FirstLink
  4. //
  5. // Created by Lofty on 16/10/13.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKLiveViewModel.h"
  9. #import "FKShoppingLiveBrandCell.h"
  10. #import "FKShoppingLiveProductCell.h"
  11. #import "FKShoppingLiveActivityHead.h"
  12. #import "FKShoppingLiveActivityProduct.h"
  13. @implementation FKLiveViewModel
  14. - (void)addItems:(NSArray *)array {
  15. if (array.count > 0) {
  16. [self.items addObjectsFromArray:array];
  17. }
  18. }
  19. - (NSInteger)itemCount{
  20. return self.items.count;
  21. }
  22. - (FKLivesProductItem *)itemAtIndexPath:(NSIndexPath *)indexPath {
  23. if (indexPath.section >= 0 && indexPath.section < self.items.count) {
  24. return self.items[indexPath.section];
  25. }
  26. return nil;
  27. }
  28. - (BOOL)isEmpty{
  29. if (!self.items.count) {
  30. return YES;
  31. }
  32. return NO;
  33. }
  34. - (kLiveCellType)cellTypeAtIndexPath:(NSIndexPath *)indexPath{
  35. FKLivesProductItem *item = [self itemAtIndexPath:indexPath];
  36. if (item.source == kShoppingLivesSourceRecommend) {
  37. return (indexPath.row == 0 ? kLiveCellTypeActivityHead : kLiveCellTypeActivityProduct);
  38. } else {
  39. return (indexPath.row == 0 ? kLiveCellTypeBrandHead : kLiveCellTypeProduct);
  40. }
  41. return kLiveCellTypeNone;
  42. }
  43. - (NSString *)cellIdentifiyAtIndexPath:(NSIndexPath *)indexPath{
  44. kLiveCellType cellType = [self cellTypeAtIndexPath:indexPath];
  45. switch (cellType) {
  46. case kLiveCellTypeBrandHead:
  47. return NSStringFromClass([FKShoppingLiveBrandCell class]);
  48. case kLiveCellTypeProduct:
  49. return NSStringFromClass([FKShoppingLiveProductCell class]);
  50. case kLiveCellTypeActivityHead:
  51. return NSStringFromClass([FKShoppingLiveActivityHead class]);
  52. case kLiveCellTypeActivityProduct:
  53. return NSStringFromClass([FKShoppingLiveActivityProduct class]);
  54. default:
  55. break;
  56. }
  57. return nil;
  58. }
  59. - (CGFloat)heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  60. kLiveCellType cellType = [self cellTypeAtIndexPath:indexPath];
  61. switch (cellType) {
  62. case kLiveCellTypeBrandHead:
  63. return [FKShoppingLiveBrandCell height];
  64. case kLiveCellTypeProduct:
  65. return [FKShoppingLiveProductCell height];
  66. case kLiveCellTypeActivityHead:
  67. return [FKShoppingLiveActivityHead height];
  68. case kLiveCellTypeActivityProduct:
  69. return [FKShoppingLiveActivityProduct height];
  70. default:
  71. break;
  72. }
  73. return 0.0f;
  74. }
  75. #pragma mark - Property
  76. - (NSMutableArray *)items {
  77. if (!_items) {
  78. _items = [NSMutableArray array];
  79. }
  80. return _items;
  81. }
  82. @end