ChatAddressViewController.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. //
  2. // ChatAddressViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/23.
  6. //
  7. #import "ChatAddressViewController.h"
  8. #import "ChatAddressHeaderView.h"
  9. #import "JXCategoryView.h"
  10. #import "JXPagerListRefreshView.h"
  11. #import "ChatAddressBodyView.h"
  12. @interface ChatAddressViewController ()<JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate,JXCategoryViewDelegate>
  13. @property (nonatomic, strong) ChatAddressHeaderView *headView;
  14. @property (nonatomic, assign) NSInteger selectedIndex;
  15. @property (nonatomic, strong) NSMutableArray *listViewArray;
  16. @end
  17. @implementation ChatAddressViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view.
  21. [self configUI];
  22. }
  23. - (void)configUI {
  24. [self.scrollView removeFromSuperview];
  25. self.view.backgroundColor = [UIColor clearColor];
  26. [self.view addSubview:self.headView];
  27. self.headView.frame = CGRectMake(0, 0, kScreenWidth, 100);
  28. MJWeakSelf;
  29. [self.headView chatAddressbookAction:^(CHATADDRESSTYPE type, NSString * _Nullable searchKey) {
  30. [weakSelf topViewAction:type search:searchKey];
  31. }];
  32. _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 100, kScreenWidth, 10)];
  33. _categoryView.backgroundColor = HexRGB(0xf6f8f9);
  34. self.categoryView.titles = self.titles;
  35. self.categoryView.delegate = self;
  36. self.categoryView.titleFont = [UIFont systemFontOfSize:16.0f];
  37. self.categoryView.titleSelectedFont = [UIFont systemFontOfSize:16.0f weight:UIFontWeightMedium];
  38. self.categoryView.titleSelectedColor = THEMECOLOR;
  39. self.categoryView.titleColor = HexRGB(0x777777);
  40. self.categoryView.titleColorGradientEnabled = YES;
  41. self.categoryView.hidden = YES;
  42. _pagerView = [self preferredPagingView];
  43. self.pagerView.frame = CGRectMake(0, 100, kScreenWidth, kScreenHeight - kNaviBarHeight-100 - kTabBarHeight);
  44. self.pagerView.listContainerView.categoryNestPagingEnabled = YES;
  45. self.pagerView.mainTableView.gestureDelegate = self;
  46. self.pagerView.backgroundColor = [UIColor clearColor];
  47. self.pagerView.mainTableView.backgroundColor = [UIColor clearColor];
  48. [self.view addSubview:self.pagerView];
  49. self.categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  50. }
  51. - (void)topViewAction:(CHATADDRESSTYPE)type search:(NSString *)searchKey {
  52. switch (type) {
  53. case CHATADDRESSTYPE_PERSON: // 联系人
  54. {
  55. [self.categoryView selectItemAtIndex:0];
  56. self.selectedIndex = 0;
  57. }
  58. break;
  59. case CHATADDRESSTYPE_GROUP: // 群组
  60. {
  61. [self.categoryView selectItemAtIndex:1];
  62. self.selectedIndex = 1;
  63. }
  64. break;
  65. case CHATADDRESSTYPE_SEARCH: // 搜索
  66. {
  67. [self searchRequest:searchKey];
  68. }
  69. break;
  70. default:
  71. break;
  72. }
  73. }
  74. - (void)searchRequest:(NSString *)searchKey {
  75. if (self.listViewArray.count > self.selectedIndex) {
  76. ChatAddressBodyView *listView = self.listViewArray[self.selectedIndex];
  77. listView.searchKey = searchKey;
  78. [listView refreshAndRequestData];
  79. }
  80. }
  81. - (void)viewWillAppear:(BOOL)animated {
  82. [super viewWillAppear:animated];
  83. self.navigationController.interactivePopGestureRecognizer.enabled = YES;
  84. if (self.listViewArray.count > self.categoryView.selectedIndex) {
  85. id value = self.listViewArray[self.categoryView.selectedIndex];
  86. if ([value isKindOfClass:[KSJXBodyView class]]) {
  87. KSJXBodyView *listView = (KSJXBodyView *)value;
  88. [listView beginFirstRefresh];
  89. }
  90. }
  91. }
  92. - (void)viewDidAppear:(BOOL)animated {
  93. [super viewDidAppear:animated];
  94. }
  95. - (JXPagerView *)preferredPagingView {
  96. return [[JXPagerListRefreshView alloc] initWithDelegate:self];
  97. }
  98. #pragma mark - JXPagerViewDelegate
  99. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  100. return [UIView new];
  101. }
  102. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  103. return CGFLOAT_MIN;
  104. }
  105. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  106. return 10;
  107. }
  108. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  109. return self.categoryView;
  110. }
  111. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  112. //和categoryView的item数量一致
  113. return self.titles.count;
  114. }
  115. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  116. ChatAddressBodyView *listView = [[ChatAddressBodyView alloc] init];
  117. listView.naviController = self.navigationController;
  118. [self.listViewArray addObject:listView];
  119. if (index == 0) {
  120. listView.selectIndex = 0;
  121. }else if (index == 1) {
  122. listView.selectIndex = 1;
  123. }
  124. [listView beginFirstRefresh];
  125. return listView;
  126. }
  127. #pragma mark - JXCategoryViewDelegate
  128. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  129. BOOL scrollPersonTable = index == 0;
  130. [self.headView scrollPersonTable:scrollPersonTable];
  131. self.selectedIndex = index;
  132. }
  133. #pragma mark - JXPagerMainTableViewGestureDelegate
  134. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  135. //禁止categoryView左右滑动的时候,上下和左右都可以滚动
  136. if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
  137. return NO;
  138. }
  139. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  140. }
  141. - (NSMutableArray *)listViewArray {
  142. if (!_listViewArray) {
  143. _listViewArray = [NSMutableArray array];
  144. }
  145. return _listViewArray;
  146. }
  147. #pragma mark - JXCategoryListContentViewDelegate
  148. - (UIView *)listView {
  149. return self.view;
  150. }
  151. - (ChatAddressHeaderView *)headView {
  152. if (!_headView) {
  153. _headView = [ChatAddressHeaderView shareInstance];
  154. }
  155. return _headView;
  156. }
  157. - (void)setSelectedIndex:(NSInteger)selectedIndex {
  158. _selectedIndex = selectedIndex;
  159. ChatAddressBodyView *listView = self.listViewArray[selectedIndex];
  160. NSString *searchKey = listView.searchKey;
  161. self.headView.searchField.text = searchKey;
  162. }
  163. /*
  164. #pragma mark - Navigation
  165. // In a storyboard-based application, you will often want to do a little preparation before navigation
  166. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  167. // Get the new view controller using [segue destinationViewController].
  168. // Pass the selected object to the new view controller.
  169. }
  170. */
  171. @end