|  | @@ -0,0 +1,233 @@
 | 
	
		
			
				|  |  | +//
 | 
	
		
			
				|  |  | +//  KSImageShareViewController.m
 | 
	
		
			
				|  |  | +//  KulexiuForStudent
 | 
	
		
			
				|  |  | +//
 | 
	
		
			
				|  |  | +//  Created by 王智 on 2022/9/21.
 | 
	
		
			
				|  |  | +//
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +#import "KSImageShareViewController.h"
 | 
	
		
			
				|  |  | +#import "ChatAddressHeaderView.h"
 | 
	
		
			
				|  |  | +#import "JXCategoryView.h"
 | 
	
		
			
				|  |  | +#import "JXPagerListRefreshView.h"
 | 
	
		
			
				|  |  | +#import "ChatAddressBodyView.h"
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +@interface KSImageShareViewController ()<JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate,JXCategoryViewDelegate>
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +@property (nonatomic, strong) ChatAddressHeaderView *headView;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +@property (nonatomic, assign) NSInteger selectedIndex;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +@property (nonatomic, strong) NSMutableArray *listViewArray;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +@property (nonatomic, copy) ShareGroupCallback callback;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +@end
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +@implementation KSImageShareViewController
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (void)backAction {
 | 
	
		
			
				|  |  | +    if (self.callback) {
 | 
	
		
			
				|  |  | +        self.callback(NO, @"已取消");
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    [self.navigationController popViewControllerAnimated:YES];
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (void)shareGroupCallback:(ShareGroupCallback)callback {
 | 
	
		
			
				|  |  | +    if (callback) {
 | 
	
		
			
				|  |  | +        self.callback = callback;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (void)viewDidLoad {
 | 
	
		
			
				|  |  | +    [super viewDidLoad];
 | 
	
		
			
				|  |  | +    // Do any additional setup after loading the view.
 | 
	
		
			
				|  |  | +    _titles = @[@"班级",@"老师"];
 | 
	
		
			
				|  |  | +    [self allocTitle:@"分享"];
 | 
	
		
			
				|  |  | +    [self configUI];
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (void)configUI {
 | 
	
		
			
				|  |  | +    [self.scrollView removeFromSuperview];
 | 
	
		
			
				|  |  | +    self.view.backgroundColor = HexRGB(0xf6f8f9);
 | 
	
		
			
				|  |  | +    [self.view addSubview:self.headView];
 | 
	
		
			
				|  |  | +    self.headView.frame = CGRectMake(0, 0, kScreenWidth, 100);
 | 
	
		
			
				|  |  | +    MJWeakSelf;
 | 
	
		
			
				|  |  | +    [self.headView chatAddressbookAction:^(CHATADDRESSTYPE type, NSString * _Nullable searchKey) {
 | 
	
		
			
				|  |  | +        [weakSelf topViewAction:type search:searchKey];
 | 
	
		
			
				|  |  | +    }];
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 100, kScreenWidth, 10)];
 | 
	
		
			
				|  |  | +    _categoryView.backgroundColor = HexRGB(0xf6f8f9);
 | 
	
		
			
				|  |  | +    self.categoryView.titles = self.titles;
 | 
	
		
			
				|  |  | +    self.categoryView.delegate = self;
 | 
	
		
			
				|  |  | +    self.categoryView.titleFont = [UIFont systemFontOfSize:16.0f];
 | 
	
		
			
				|  |  | +    self.categoryView.titleSelectedFont = [UIFont systemFontOfSize:16.0f weight:UIFontWeightMedium];
 | 
	
		
			
				|  |  | +    self.categoryView.titleSelectedColor = THEMECOLOR;
 | 
	
		
			
				|  |  | +    self.categoryView.titleColor = HexRGB(0x777777);
 | 
	
		
			
				|  |  | +    self.categoryView.titleColorGradientEnabled = YES;
 | 
	
		
			
				|  |  | +    self.categoryView.hidden = YES;
 | 
	
		
			
				|  |  | +    _pagerView = [self preferredPagingView];
 | 
	
		
			
				|  |  | +    self.pagerView.frame = CGRectMake(0, 100, kScreenWidth, kScreenHeight - kNaviBarHeight-100 - kTabBarHeight);
 | 
	
		
			
				|  |  | +    self.pagerView.listContainerView.categoryNestPagingEnabled = YES;
 | 
	
		
			
				|  |  | +    self.pagerView.mainTableView.gestureDelegate = self;
 | 
	
		
			
				|  |  | +    self.pagerView.backgroundColor = [UIColor clearColor];
 | 
	
		
			
				|  |  | +    self.pagerView.mainTableView.backgroundColor = [UIColor clearColor];
 | 
	
		
			
				|  |  | +    [self.view addSubview:self.pagerView];
 | 
	
		
			
				|  |  | +    self.categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (void)topViewAction:(CHATADDRESSTYPE)type search:(NSString *)searchKey {
 | 
	
		
			
				|  |  | +    switch (type) {
 | 
	
		
			
				|  |  | +        case CHATADDRESSTYPE_PERSON: // 联系人
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            [self.categoryView selectItemAtIndex:0];
 | 
	
		
			
				|  |  | +            self.selectedIndex = 0;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +            break;
 | 
	
		
			
				|  |  | +        case CHATADDRESSTYPE_GROUP: // 群组
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            [self.categoryView selectItemAtIndex:1];
 | 
	
		
			
				|  |  | +            self.selectedIndex = 1;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +            break;
 | 
	
		
			
				|  |  | +        case CHATADDRESSTYPE_SEARCH:  // 搜索
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            [self searchRequest:searchKey];
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +            break;
 | 
	
		
			
				|  |  | +        default:
 | 
	
		
			
				|  |  | +            break;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (void)searchRequest:(NSString *)searchKey {
 | 
	
		
			
				|  |  | +    if (self.listViewArray.count > self.selectedIndex) {
 | 
	
		
			
				|  |  | +        ChatAddressBodyView *listView = self.listViewArray[self.selectedIndex];
 | 
	
		
			
				|  |  | +        listView.searchKey = searchKey;
 | 
	
		
			
				|  |  | +        [listView refreshAndRequestData];
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (void)viewWillAppear:(BOOL)animated {
 | 
	
		
			
				|  |  | +    [super viewWillAppear:animated];
 | 
	
		
			
				|  |  | +    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
 | 
	
		
			
				|  |  | +    if (self.listViewArray.count > self.categoryView.selectedIndex) {
 | 
	
		
			
				|  |  | +        id value = self.listViewArray[self.categoryView.selectedIndex];
 | 
	
		
			
				|  |  | +        if ([value isKindOfClass:[KSJXBodyView class]]) {
 | 
	
		
			
				|  |  | +            KSJXBodyView *listView = (KSJXBodyView *)value;
 | 
	
		
			
				|  |  | +            [listView beginFirstRefresh];
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (void)viewDidAppear:(BOOL)animated {
 | 
	
		
			
				|  |  | +    [super viewDidAppear:animated];
 | 
	
		
			
				|  |  | +    self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (JXPagerView *)preferredPagingView {
 | 
	
		
			
				|  |  | +    return [[JXPagerListRefreshView alloc] initWithDelegate:self];
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +#pragma mark - JXPagerViewDelegate
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
 | 
	
		
			
				|  |  | +    return [UIView new];
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
 | 
	
		
			
				|  |  | +    return CGFLOAT_MIN;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
 | 
	
		
			
				|  |  | +    return 10;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
 | 
	
		
			
				|  |  | +    return self.categoryView;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
 | 
	
		
			
				|  |  | +    //和categoryView的item数量一致
 | 
	
		
			
				|  |  | +    return self.titles.count;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
 | 
	
		
			
				|  |  | +    ChatAddressBodyView *listView = [[ChatAddressBodyView alloc] init];
 | 
	
		
			
				|  |  | +    listView.naviController = self.navigationController;
 | 
	
		
			
				|  |  | +    listView.isShareImage = YES;
 | 
	
		
			
				|  |  | +    listView.shareImage = self.shareImage;
 | 
	
		
			
				|  |  | +    MJWeakSelf;
 | 
	
		
			
				|  |  | +    [listView shareCallback:^(BOOL isSuccess, NSString * _Nonnull desc) {
 | 
	
		
			
				|  |  | +        if (weakSelf.callback) {
 | 
	
		
			
				|  |  | +            weakSelf.callback(isSuccess, desc);
 | 
	
		
			
				|  |  | +            [weakSelf.navigationController popViewControllerAnimated:YES];
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }];
 | 
	
		
			
				|  |  | +    [self.listViewArray addObject:listView];
 | 
	
		
			
				|  |  | +    if (index == 0) {
 | 
	
		
			
				|  |  | +        listView.selectIndex = 0;
 | 
	
		
			
				|  |  | +    }else if (index == 1) {
 | 
	
		
			
				|  |  | +        listView.selectIndex = 1;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    [listView beginFirstRefresh];
 | 
	
		
			
				|  |  | +    return listView;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +#pragma mark - JXCategoryViewDelegate
 | 
	
		
			
				|  |  | +- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
 | 
	
		
			
				|  |  | +    BOOL scrollPersonTable = index == 0;
 | 
	
		
			
				|  |  | +    [self.headView scrollPersonTable:scrollPersonTable];
 | 
	
		
			
				|  |  | +    self.selectedIndex = index;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +#pragma mark - JXPagerMainTableViewGestureDelegate
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
 | 
	
		
			
				|  |  | +    //禁止categoryView左右滑动的时候,上下和左右都可以滚动
 | 
	
		
			
				|  |  | +    if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
 | 
	
		
			
				|  |  | +        return NO;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (NSMutableArray *)listViewArray {
 | 
	
		
			
				|  |  | +    if (!_listViewArray) {
 | 
	
		
			
				|  |  | +        _listViewArray = [NSMutableArray arrayWithArray:@[@"",@""]];
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    return _listViewArray;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +#pragma mark - JXCategoryListContentViewDelegate
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (UIView *)listView {
 | 
	
		
			
				|  |  | +    return self.view;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +- (ChatAddressHeaderView *)headView {
 | 
	
		
			
				|  |  | +    if (!_headView) {
 | 
	
		
			
				|  |  | +        _headView = [ChatAddressHeaderView shareInstance];
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    return _headView;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +- (void)setSelectedIndex:(NSInteger)selectedIndex {
 | 
	
		
			
				|  |  | +    _selectedIndex = selectedIndex;
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    ChatAddressBodyView *listView = self.listViewArray[selectedIndex];
 | 
	
		
			
				|  |  | +    NSString *searchKey = listView.searchKey;
 | 
	
		
			
				|  |  | +    self.headView.searchField.text = searchKey;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +/*
 | 
	
		
			
				|  |  | +#pragma mark - Navigation
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +// In a storyboard-based application, you will often want to do a little preparation before navigation
 | 
	
		
			
				|  |  | +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 | 
	
		
			
				|  |  | +    // Get the new view controller using [segue destinationViewController].
 | 
	
		
			
				|  |  | +    // Pass the selected object to the new view controller.
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +*/
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +@end
 |