Sin descripción

FKBookNormalViewModel.m 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // FKMyBookViewModel.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/4/29.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKBookNormalViewModel.h"
  9. #import "FKBookProItem.h"
  10. #import "FKBookBrandItem.h"
  11. @implementation FKBookNormalViewModel
  12. @synthesize itemArray = _itemArray;
  13. + (NSDictionary *)mts_mapping {
  14. return @{
  15. @"list" : mts_key(itemArray),
  16. @"brand_list" : mts_key(brandArray),
  17. @"pager.total" : mts_key(productTotal),
  18. @"server_time" : mts_key(serveTime),
  19. };
  20. }
  21. + (BOOL)mts_shouldSetUndefinedKeys {
  22. return NO;
  23. }
  24. + (NSDictionary *)mts_arrayClassMapping{
  25. return @{mts_key(itemArray) : FKBookProItem.class,
  26. mts_key(brandArray) : FKBookBrandItem.class};
  27. }
  28. - (NSInteger)numberOfRowsInSection:(NSInteger)section{
  29. return self.itemArray.count;
  30. }
  31. - (CGFloat)heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  32. return 118.0f;
  33. }
  34. - (CGFloat)heightForHeaderInSection:(NSInteger)section{
  35. return CGFLOAT_MIN;
  36. }
  37. - (NSString *)cellIdentify{
  38. return FK_BOOK_PRO_CELL_IDENTIFY;
  39. }
  40. - (NSString *)brandIdAtIndex:(NSUInteger)index{
  41. if (index <= self.brandArray.count){
  42. FKBookBrandItem *item = self.brandArray[index];
  43. return item.itemID;
  44. }
  45. return nil;
  46. }
  47. - (NSString *)brandNameAtIndex:(NSUInteger)index{
  48. if (index <= self.brandArray.count){
  49. FKBookBrandItem *item = self.brandArray[index];
  50. return item.name;
  51. }
  52. return nil;
  53. }
  54. - (BookContentType)contentType{
  55. return BookContentTypeNormal;
  56. }
  57. - (BOOL)enableBottomRefresh{
  58. if (self.itemArray.count >= self.productTotal) {
  59. return NO;
  60. }
  61. return YES;
  62. }
  63. - (void)appendMoreItem:(NSArray *)moreArray{
  64. if (!self.itemArray || !self.itemArray.count) self.itemArray = moreArray;
  65. NSMutableArray *arrayM = [NSMutableArray arrayWithArray:self.itemArray];
  66. [arrayM addObjectsFromArray:moreArray];
  67. self.itemArray = arrayM;
  68. }
  69. - (BOOL)saveServeTime{
  70. if ([FLStringHelper isValidString:self.serveTime]) {
  71. [[NSUserDefaults standardUserDefaults] setObject:self.serveTime forKey:FK_BOOK_BRAND_SERVER_TIME_KEY];
  72. return [[NSUserDefaults standardUserDefaults] synchronize];
  73. }
  74. return NO;
  75. }
  76. - (id)proModelAtIndex:(NSUInteger)index{
  77. if (index < self.itemArray.count) {
  78. return self.itemArray[index];
  79. }
  80. return nil;
  81. }
  82. - (NSArray *)getBrandStrArray{
  83. if (self.brandArray.count) {
  84. NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:self.brandArray.count];
  85. for (FKBookBrandItem *item in self.brandArray) {
  86. if ([FLStringHelper isValidString:item.name]){
  87. [arrayM addObject:item.name];
  88. }
  89. }
  90. return arrayM;
  91. }
  92. return nil;
  93. }
  94. @end