KSShareChooseViewController.m 7.6 KB

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