No Description

FKExploreViewModel.m 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // FKExploreViewModel.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 16/2/16.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKExploreViewModel.h"
  9. #import "FKExploreTopicTag.h"
  10. int const FKExploreRequestPageSize = 6;
  11. NSString * const FKExploreTopicTagKey = @"FKExploreTopicTagKey";
  12. int const FKExploreRequestTopicTags = 100;
  13. int const FKExploreRequestTopicList = 200;
  14. int const FKExploreRequestTopicListNextPage = 300;
  15. @implementation FKExploreViewModel
  16. - (NSString *)topicTagIDAtIndex:(NSInteger)index {
  17. if (index < self.topicTagArray.count) {
  18. return ((FKExploreTopicTag *)self.topicTagArray[index]).tagID;
  19. }
  20. return nil;
  21. }
  22. - (NSString *)startRowWithTagID:(NSString *)tagID {
  23. if (tagID) {
  24. NSArray *topicArray = self.topicListCache[tagID];
  25. return [NSString stringWithFormat:@"%lu", (unsigned long)topicArray.count];
  26. }
  27. return nil;
  28. }
  29. - (NSArray *)validTopicListWithTagID:(NSString *)tagID {
  30. if (tagID) {
  31. NSArray *topicArray = self.topicListCache[tagID];
  32. NSMutableArray *validArray = [NSMutableArray array];
  33. [topicArray enumerateObjectsUsingBlock:^(FKExploreTopicListItem *obj, NSUInteger idx, BOOL * _Nonnull stop) {
  34. if (obj.subItemArray.count > 0) {
  35. [validArray addObject:obj];
  36. }
  37. }];
  38. return validArray;
  39. }
  40. return nil;
  41. }
  42. - (FKExploreTopicListItem *)validTopicListItemWithTagID:(NSString *)tagID atIndex:(NSInteger)index {
  43. NSArray *array = [self validTopicListWithTagID:tagID];
  44. if (index < array.count) {
  45. return array[index];
  46. }
  47. return nil;
  48. }
  49. - (void)setContentOffset:(CGFloat)offsetX forKey:(NSInteger)key {
  50. if (!_contensOffsetArray) {
  51. _contensOffsetArray = [NSMutableDictionary dictionary];
  52. }
  53. NSNumber *number = [NSNumber numberWithFloat:offsetX];
  54. NSString *keySring = [NSString stringWithFormat:@"%ld",(long)key];
  55. [self.contensOffsetArray setValue:number forKey:keySring];
  56. }
  57. - (CGFloat)contentOffsetForKey:(NSInteger)key {
  58. NSString *keySring = [NSString stringWithFormat:@"%ld",(long)key];
  59. NSNumber *value = [self.contensOffsetArray valueForKey:keySring];
  60. if ([value isKindOfClass:[NSNumber class]]) {
  61. return value.floatValue;
  62. }
  63. return 0;
  64. }
  65. #pragma mark - Property
  66. - (NSArray *)topicTagArray {
  67. if (!_topicTagArray) {
  68. _topicTagArray = [NSArray array];
  69. }
  70. return _topicTagArray;
  71. }
  72. - (NSArray *)sectionTitlesArray {
  73. NSMutableArray *array = [NSMutableArray array];
  74. for (FKExploreTopicTag *tag in self.topicTagArray) {
  75. [array addObject:tag.name];
  76. }
  77. return array;
  78. }
  79. - (NSMutableDictionary *)topicListCache {
  80. if (!_topicListCache) {
  81. _topicListCache = [NSMutableDictionary dictionary];
  82. }
  83. return _topicListCache;
  84. }
  85. @end