123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- //
- // ChatViewController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/17.
- //
- #import "ChatViewController.h"
- #import "ChatNavView.h"
- #import "CreateFansGroupViewController.h"
- #import "ChatAddressViewController.h"
- #import "KSChatListViewController.h"
- #import "KSTabBarViewController.h"
- #import "TXIMLinsenter.h"
- @interface ChatViewController ()<JXCategoryViewDelegate>
- @property (nonatomic, strong) ChatNavView *navView;
- @property (nonatomic, strong) JXCategoryTitleView *myCategoryView;
- @property (nonatomic, assign) NSInteger currentIndex;
- @property (nonatomic, strong) KSChatListViewController *chatListCtrl;
- @property (nonatomic, strong) ChatAddressViewController *contractList;
- @end
- @implementation ChatViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.ks_prefersNavigationBarHidden = YES;
- self.titles = @[@"聊天", @"联系人"];
- [self getUnreadCount];
- [self configUI];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshChatList) name:CHATVIEW_REFRESH object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshMessageStatus:) name:CHATVIEW_REFRESHSTATUS object:nil];
- }
- - (void)getUnreadCount {
- [TXIM_LINSENTER getUnReadCountCallback:^(NSInteger count) {
- dispatch_async(dispatch_get_main_queue(),^{
- if (count >= 1) {
- self.navView.dotView.hidden = NO;
- } else {
- self.navView.dotView.hidden = YES;
- }
- });
- }];
- }
- - (void)refreshMessageStatus:(NSNotification *)notification {
- NSDictionary *msgDic = notification.object; ///
- NSInteger unreadMsgCount = [msgDic ks_integerValueForKey:@"unreadCount"];
- if (unreadMsgCount >= 1) {
- self.navView.dotView.hidden = NO;
- } else {
- self.navView.dotView.hidden = YES;
- }
- }
- - (void)refreshChatList {
- if (self.chatListCtrl && self.currentIndex == 0) {
- [self.chatListCtrl refreshChatListMessage];
- }
- }
- - (void)configUI {
- [self.scrollView removeFromSuperview];
- [self.view addSubview:self.navView];
-
- CGFloat topSpace = kNaviBarHeight;
- self.myCategoryView.frame = CGRectMake(0, topSpace, KPortraitWidth, 10);
- self.myCategoryView.backgroundColor = HexRGB(0xf6f8f9);
- self.myCategoryView.titles = self.titles;
- self.myCategoryView.titleFont = [UIFont systemFontOfSize:16.0f];
- self.myCategoryView.titleSelectedFont = [UIFont systemFontOfSize:16.0f weight:UIFontWeightMedium];
- self.myCategoryView.titleSelectedColor = THEMECOLOR;
- self.myCategoryView.titleColor = HexRGB(0x777777);
- self.myCategoryView.titleColorGradientEnabled = YES;
- self.myCategoryView.hidden = YES;
- [self.view addSubview:self.categoryView];
- [self.view addSubview:self.listContainerView];
- }
- - (void)viewDidLayoutSubviews {
- [super viewDidLayoutSubviews];
- CGFloat topSpace = kNaviBarHeight;
- self.categoryView.frame = CGRectMake(0, topSpace, self.view.bounds.size.width, [self preferredCategoryViewHeight]);
- self.listContainerView.frame = CGRectMake(0, topSpace + [self preferredCategoryViewHeight], self.view.bounds.size.width, self.view.bounds.size.height - topSpace - [self preferredCategoryViewHeight]);
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- // 处于第一个item的时候,才允许屏幕边缘手势返回
- self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
- }
- - (void)scrollToFirstPage {
- [self.myCategoryView selectItemAtIndex:0];
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- // 离开页面的时候,需要恢复屏幕边缘手势,不能影响其他页面
- self.navigationController.interactivePopGestureRecognizer.enabled = YES;
- }
- - (JXCategoryTitleView *)myCategoryView {
- return (JXCategoryTitleView *)self.categoryView;
- }
- - (CGFloat)preferredCategoryViewHeight {
- return CGFLOAT_MIN;
- }
- - (JXCategoryBaseView *)preferredCategoryView {
- return [[JXCategoryTitleView alloc] init];
- }
- #pragma mark - JXCategoryViewDelegate
- // 点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,不关心具体是点击还是滚动选中的。
- - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
- NSLog(@"%@", NSStringFromSelector(_cmd));
- // bool scrollChatTable = index == 0 ? YES : NO;
- // [self.navView scrollChatTable:scrollChatTable];
- // 侧滑手势处理
- self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
- }
- #pragma mark - JXCategoryListContainerViewDelegate
- - (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
- if (index == 0) {
- KSChatListViewController *listVC = [[KSChatListViewController alloc] init];
- listVC.view.frame = CGRectMake(0, 0, KPortraitWidth, KPortraitHeight - kNaviBarHeight - kTabBarHeight);
- self.chatListCtrl = listVC;
- return listVC;
- }
- else {
- ChatAddressViewController *list = [[ChatAddressViewController alloc] init];
- MJWeakSelf;
- [list scrollActionCallback:^(NSInteger scrollIndex) {
- [weakSelf contractScrollIndex:scrollIndex];
- }];
- self.contractList = list;
- list.titles = @[@"群组",@"联系人"];
- return list;
- }
- }
- - (void)contractScrollIndex:(NSInteger)scrollIndex {
- [self.navView scrollChatTableIndex:scrollIndex+1];
- }
- // 返回列表的数量
- - (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
- return self.titles.count;
- }
- #pragma mark - JXCategoryListContainerViewDelegate
- - (void)listContainerViewDidScroll:(UIScrollView *)scrollView{
- if ([self isKindOfClass:[ChatAddressViewController class]]) {
- CGFloat index = scrollView.contentOffset.x/scrollView.bounds.size.width;
- CGFloat absIndex = fabs(index - self.currentIndex);
- if (absIndex >= 1) {
- //”快速滑动的时候,只响应最外层VC持有的scrollView“,说实话,完全可以不用处理这种情况。如果你们的产品经理坚持认为这是个问题,就把这块代码加上吧。
- //嵌套使用的时候,最外层的VC持有的scrollView在翻页之后,就断掉一次手势。解决快速滑动的时候,只响应最外层VC持有的scrollView。子VC持有的scrollView却没有响应
- self.listContainerView.scrollView.panGestureRecognizer.enabled = NO;
- self.listContainerView.scrollView.panGestureRecognizer.enabled = YES;
- _currentIndex = floor(index);
- }
- }
- }
- - (ChatNavView *)navView {
- if (!_navView) {
- _navView = [ChatNavView shareInstance];
- _navView.frame = CGRectMake(0, 0, KPortraitWidth, kNaviBarHeight);
- MJWeakSelf;
- [_navView chatNavAction:^(CHATNAVACTION action) {
- [weakSelf navAction:action];
- }];
- }
- return _navView;
- }
- - (void)navAction:(CHATNAVACTION)action {
- switch (action) {
- case CHATNAVACTION_LIST:
- {
- [self.categoryView selectItemAtIndex:0];
- }
- break;
- case CHATNAVACTION_GROUP: // 群组
- {
- [self.categoryView selectItemAtIndex:1];
- [self.contractList scrollToChatList:NO];
- }
- break;
- case CHATNAVACTION_CONTACTS: // 联系人
- {
- [self.categoryView selectItemAtIndex:1];
- [self.contractList scrollToChatList:YES];
- }
- break;
- case CHATNAVACTION_SEND:
- {
- }
- break;
-
- default:
- break;
- }
- }
- #pragma mark - Custom Accessors
- // 分页菜单视图
- - (JXCategoryBaseView *)categoryView {
- if (!_categoryView) {
- _categoryView = [self preferredCategoryView];
- _categoryView.delegate = self;
-
- // !!!: 将列表容器视图关联到 categoryView
- _categoryView.listContainer = self.listContainerView;
- }
- return _categoryView;
- }
- // 列表容器视图
- - (JXCategoryListContainerView *)listContainerView {
- if (!_listContainerView) {
- _listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
- _listContainerView.scrollView.scrollEnabled = NO;
- }
- return _listContainerView;
- }
- /*
- #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
|