| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534 |
- //
- // BGConversationSegmentController.m
- // BuguLive
- //
- // Created by 朱庆彬 on 2017/8/22.
- // Copyright © 2017年 xfg. All rights reserved.
- //
- #import "BGConversationSegmentController.h"
- #import "BGChatSegmentScrollController.h"
- #import "BGConversationListController.h"
- #import "BGConversationStrangerController.h"
- #import "BGConversationTradeController.h"
- static NSString const *kChatTrade = @"交易";
- static NSString const *kChatFriend = @"好友";
- static NSString const *kChatStranger = @"未关注";
- NSInteger kSelectedSegmentIndex = 1; // segmentedControl默认选中的index
- @interface BGConversationSegmentController () <UIScrollViewDelegate, ConversationListViewDelegate, FWConversationStrangerViewDelegate>
- {
- int _selectIndex; //1.交易 2.好友 3.未关注
- BGConversationListController *_conversationListVC;
- BGConversationStrangerController *_conversationStrangerVC;
- BGConversationTradeController *_conversationTradeVC;
- }
- @property (nonatomic, assign) int tag;
- @property (nonatomic, assign) BOOL isClickedSegmented;// 是否点击了Segmented的滑块
- @property (nonatomic, strong) BGChatSegmentScrollController *scrollView;
- @property (nonatomic, strong) HMSegmentedControl *segmentedControl;
- @property (nonatomic, strong) UIView *navView;
- @property (nonatomic, strong) NSMutableArray *itemMutableArray;
- @end
- @implementation BGConversationSegmentController
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [self.navigationController setNavigationBarHidden:YES animated:NO];
- }
- - (void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- if (!_mbhalf)
- {
- [self.navigationController setNavigationBarHidden:NO animated:NO];
- }
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IMChatMsgNotficationInList:) name:g_notif_chatmsg object:nil];
- }
- #pragma mrak-- ------------------------消息通知-- ------------------------
- - (void)IMChatMsgNotficationInList:(NSNotification *)notfication
- {
- if (![NSThread isMainThread])
- {
- [self performSelectorOnMainThread:@selector(IMChatMsgNotficationInList:) withObject:notfication waitUntilDone:NO];
- return;
- }
- [self loadBtnBadageData];
- }
- - (void)initFWUI
- {
- [super initFWUI];
- self.BuguLive = [GlobalVariables sharedInstance];
- if ([self.BuguLive.appModel.open_pai_module intValue] == 1 || [self.BuguLive.appModel.shopping_goods integerValue] == 1)
- {
- self.itemMutableArray = [NSMutableArray arrayWithObjects:kChatTrade, ASLocalizedString(kChatFriend), ASLocalizedString(kChatStranger), nil];
- kSelectedSegmentIndex = 1;
- }
- else
- {
- self.itemMutableArray = [NSMutableArray arrayWithObjects:ASLocalizedString(kChatFriend), ASLocalizedString(kChatStranger), nil];
- kSelectedSegmentIndex = 0;
- }
- CGFloat viewWidth = kScreenW;
- CGFloat viewHeight = kScreenH;
- CGFloat navPointY = 0.0f;
- CGFloat scrollViewHeight = viewHeight - 64;
- CGFloat childViewPointY = 0;
- CGFloat navHeight;
- if (_mbhalf == YES)
- {
- navHeight = 44;
- scrollViewHeight = viewHeight / 2 - 44;
- }
- else
- {
- navHeight = kNavigationBarHeight+kStatusBarHeight;
- }
- _navView = [[UIView alloc] initWithFrame:CGRectMake(0, navPointY, kScreenW, navHeight)];
- _navView.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:_navView];
- UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, navHeight - 0.5, kScreenW, 0.5f)];
- lineView.backgroundColor = kAppSpaceColor;
- [_navView addSubview:lineView];
- UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, navHeight - 44, 22, 44)];
- [backBtn setImage:[UIImage imageNamed:@"com_arrow_vc_back"] forState:UIControlStateNormal];
- [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
- [_navView addSubview:backBtn];
- self.segmentedControl = [[HMSegmentedControl alloc] initWithFrame:CGRectMake(kScreenW / 2 - 100, navHeight - 41, 200, 40)];
- self.segmentedControl.sectionTitles = self.itemMutableArray;
- self.segmentedControl.selectedSegmentIndex = kSelectedSegmentIndex;
- self.segmentedControl.backgroundColor = kWhiteColor;
- self.segmentedControl.titleTextAttributes = @{NSForegroundColorAttributeName: kAppGrayColor3, NSFontAttributeName: [UIFont systemFontOfSize:15]};
- self.segmentedControl.selectedTitleTextAttributes = @{NSForegroundColorAttributeName: kAppGrayColor1, NSBackgroundColorAttributeName: kClearColor, NSFontAttributeName: [UIFont systemFontOfSize:15]};
- self.segmentedControl.selectionIndicatorColor = kAppGrayColor1;
- self.segmentedControl.selectionIndicatorHeight = 3;
- self.segmentedControl.selectionIndicatorBoxColor = kClearColor;
- self.segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleTextWidthStripe;
- self.segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
- self.segmentedControl.segmentEdgeInset = UIEdgeInsetsMake(0, 10, 0, 10);
- FWWeakify(self)
- [self.segmentedControl setIndexChangeBlock:^(NSInteger index) {
- FWStrongify(self)
- [self.scrollView scrollRectToVisible:CGRectMake(viewWidth * index, 0, viewWidth, CGRectGetHeight(self.scrollView.frame))
- animated:YES];
- self.isClickedSegmented = YES;
- }];
- [_navView addSubview:_segmentedControl];
- UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(kScreenW - 70, navHeight - 36, 60, 30)];
- [rightBtn setTitle:ASLocalizedString(@"忽略未读")forState:UIControlStateNormal];
- [rightBtn.titleLabel setFont:[UIFont systemFontOfSize:13]];
- [rightBtn setTitleColor:kAppMainColor forState:UIControlStateNormal];
- [rightBtn addTarget:self action:@selector(clickedunread:) forControlEvents:UIControlEventTouchUpInside];
- [_navView addSubview:rightBtn];
- self.scrollView = [[BGChatSegmentScrollController alloc] initWithFrame:CGRectMake(0, lineView.bottom, viewWidth, scrollViewHeight)];
- self.scrollView.delegate = self;
- self.scrollView.backgroundColor = kClearColor;
- self.scrollView.pagingEnabled = YES;
- self.scrollView.showsHorizontalScrollIndicator = NO;
- self.scrollView.bounces = NO;
- [self.scrollView setDelaysContentTouches:NO];
- [self.scrollView setCanCancelContentTouches:NO];
- self.scrollView.contentSize = CGSizeMake(viewWidth * [self.itemMutableArray count], CGRectGetHeight(self.scrollView.frame));
- [self.scrollView scrollRectToVisible:CGRectMake(kSelectedSegmentIndex * viewWidth, 0, viewWidth, CGRectGetHeight(self.scrollView.frame)) animated:NO];
- [self.view addSubview:self.scrollView];
- // 交易
- if ([self.itemMutableArray containsObject:kChatTrade])
- {
- _conversationTradeVC = [[BGConversationTradeController alloc] init];
- _conversationTradeVC.isHaveLive = _mbhalf;
- _conversationTradeVC.view.frame = CGRectMake(viewWidth * [self.itemMutableArray indexOfObject:kChatTrade], childViewPointY, viewWidth, _scrollView.bounds.size.height);
- [_conversationTradeVC updateTableViewFrame];
- [_scrollView addSubview:_conversationTradeVC.view];
- }
- // 好友
- if ([self.itemMutableArray containsObject:ASLocalizedString(kChatFriend)])
- {
- _conversationListVC = [[BGConversationListController alloc] init];
- _conversationListVC.view.frame = CGRectMake(viewWidth * [self.itemMutableArray indexOfObject:ASLocalizedString(kChatFriend)], childViewPointY, viewWidth, _scrollView.bounds.size.height);
- _conversationListVC.isHaveLive = _mbhalf;
- _conversationListVC.delegate = self;
- [_conversationListVC updateTableViewFrame];
- [_scrollView addSubview:_conversationListVC.view];
- }
- if ([self.itemMutableArray containsObject:ASLocalizedString(kChatStranger)])
- {
- _conversationStrangerVC = [[BGConversationStrangerController alloc] init];
- _conversationStrangerVC.view.frame = CGRectMake(viewWidth * [self.itemMutableArray indexOfObject:ASLocalizedString(kChatStranger)], childViewPointY, viewWidth, _scrollView.bounds.size.height);
- _conversationStrangerVC.isHaveLive = _mbhalf;
- _conversationStrangerVC.delegate = self;
- [_conversationStrangerVC updateTableViewFrame];
- [_scrollView addSubview:_conversationStrangerVC.view];
- }
- CGFloat badgeBtnPointX;
- CGFloat badgeBtn2PointX;
- if (_itemMutableArray.count == 2)
- {
- badgeBtnPointX = self.segmentedControl.width / 2 - 35;
- badgeBtn2PointX = badgeBtnPointX +105;
- }
- else
- {
- badgeBtnPointX = self.segmentedControl.width / 3 * 2 - 20;
- badgeBtn2PointX = badgeBtnPointX +75;
- }
- UIButton *friendBtn = [[UIButton alloc] initWithFrame:CGRectMake(badgeBtnPointX, 10, 10, 10)];
- friendBtn.backgroundColor = [UIColor clearColor];
- [_segmentedControl addSubview:friendBtn];
- [self initFriendBadgeBtn:friendBtn];
-
- UIButton *strangerBtn = [[UIButton alloc] initWithFrame:CGRectMake(badgeBtn2PointX, 10, 10, 10)];
- strangerBtn.backgroundColor = [UIColor clearColor];
- [_segmentedControl addSubview:strangerBtn];
- [self initStrangerBadgeBtn:strangerBtn];
- //[self loadBtnBadageData];
- }
- //忽略未读点击事件
- - (void)clickedunread:(UIButton *)sender
- {
- [SVProgressHUD showWithStatus:ASLocalizedString(@"操作中...")];
- NSArray *friendConversationArr = _conversationListVC.conversationArr;
- NSArray *strangerConversationArr = _conversationStrangerVC.conversationArr;
- [SFriendObj ignoreMsg:friendConversationArr
- block:^(SResBase *resb) {
- if (resb.msuccess)
- {
- [SVProgressHUD showSuccessWithStatus:resb.mmsg];
- kNotifPost(@"clearJsbadge", nil);
- self.badgeFriend.badgeText = nil;
- [_conversationListVC.mTableView reloadData];
- }
- else
- [SVProgressHUD showErrorWithStatus:resb.mmsg];
- }];
- [SFriendObj ignoreMsg:strangerConversationArr
- block:^(SResBase *resb) {
- if (resb.msuccess)
- {
- [SVProgressHUD showSuccessWithStatus:resb.mmsg];
- self.badgeStranger.badgeText = nil;
- [_conversationStrangerVC.mTableView reloadData];
- }
- else
- [SVProgressHUD showErrorWithStatus:resb.mmsg];
- }];
- }
- #pragma mark - ----------------------- segment代理 -----------------------
- #pragma mark 解决Segmented的滑块快速滑动时的延迟,同时把点击滑块的情况排除在外
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView
- {
- if (!self.isClickedSegmented)
- {
- CGFloat pageWidth = scrollView.frame.size.width;
- NSInteger tmpPage = scrollView.contentOffset.x / pageWidth;
- float tmpPage2 = scrollView.contentOffset.x / pageWidth;
- NSInteger page = tmpPage2 - tmpPage >= 0.5 ? tmpPage + 1 : tmpPage;
-
- if (kSelectedSegmentIndex != page)
- {
- [self.segmentedControl setSelectedSegmentIndex:page animated:YES];
- kSelectedSegmentIndex = page;
- }
- }
- }
- #pragma mark 页面滚动,同时调起Segmented的滑块滑动起来等
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
- {
- CGFloat pageWidth = scrollView.frame.size.width;
- NSInteger page = scrollView.contentOffset.x / pageWidth;
- self.isClickedSegmented = NO;
- [self.segmentedControl setSelectedSegmentIndex:page animated:YES];
- }
- - (void)backClick
- {
- //1
- kNotifPost(@"reloadunread", nil);
- //2
- if (self.mbhalf == YES)
- {
- [self goNextVCBlock:1:nil]; //1 返回
- }
- else
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- #pragma mark----------------------- 半VC 相关部分 ----------------------------
- #pragma mark -goNextVC 半VC去下个半界面block
- /**
- * @author Yue
- *
- * @brief 半VC 去下个界面
- * @discussion 1.不能push/present,因弹出半Vc,保证直播VC还能点击,addChildVC处理的
- * 2.vc。view 切动画弹出,达到push效果
- */
- - (void)goNextVCBlock:(int)tag:(SFriendObj *)friend_Obj
- {
- NSLog(@"%s", __func__);
- if (self.goNextVCBlock)
- {
- self.goNextVCBlock(tag, friend_Obj);
- }
- }
- #pragma mark - 创建半ChatVC
- /**
- * @author Yue
- *
- * @brief 创建半VC,成为直播VC的子VC,并把View加到直播view,动画切出来半VC.View
- * @prama1.0 imChat_VC nib加载
- * @prama1.1 mbhalf 最好创建完就设置,如果写在block完成后,会有问题
- * @prama1.2 frame 先放到屏幕下方
- * @prama1.3 animate 动画切出。类似模态弹出效果
- *
- * @prama2.0 live_VC 不直接传,是因为要考虑重播。。这个为啥没区分重播???
- * @prama2.1 child 子VC 子View 并 置前
- */
- //ykk 半VC 成为子VC 加载到直播VC
- + (BGConversationSegmentController *)createIMChatVCWithHalf:(UIViewController *)full_VC isRelive:(BOOL)sender
- {
- //1.0
- BGConversationSegmentController *conversationListVC = [[BGConversationSegmentController alloc] init];
- //1.2
- conversationListVC.mbhalf = YES;
- //1.1
- conversationListVC.view.frame = CGRectMake(0, kScreenH, kScreenW, kScreenH / 2);
- //1.3
- [UIView animateWithDuration:kHalfVCViewanimation
- animations:^{
- //移动到 半下方 不用transform 容易出问题
- conversationListVC.view.y = kScreenH / 2;
- }
- completion:^(BOOL finished){
- }];
- //2.
- BGLiveServiceController *live_VC = (BGLiveServiceController *) full_VC;
- [live_VC addChildViewController:conversationListVC];
- [live_VC.view addSubview:conversationListVC.view];
- [live_VC.view bringSubviewToFront:conversationListVC.view];
- return conversationListVC;
- }
- + (void)showIMChatInVCWithHalf:(UIViewController *)vc inView:(UIView *)inView
- {
- BGConversationSegmentController *conListVC = [[BGConversationSegmentController alloc] init];
- conListVC.mbhalf = YES;
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:conListVC];
- //[vc addChildViewController:nav];
- nav.navigationBarHidden = YES;
- nav.view.backgroundColor = [UIColor clearColor];
- //[vc.view addSubview:nav.view];
- nav.modalPresentationStyle = UIModalPresentationCustom;
- [vc presentViewController:nav
- animated:NO
- completion:^{
- CGRect fff = nav.view.frame;
- fff.origin.y = inView.bounds.size.height / 3.0f;
- fff.size.height = inView.bounds.size.height * (2.0f / 3.0f);
- nav.view.frame = fff;
- UIButton *bt = [[UIButton alloc] initWithFrame:CGRectMake(0, -fff.origin.y, inView.bounds.size.width, fff.origin.y)];
- bt.backgroundColor = [UIColor yellowColor];
- [bt addTarget:conListVC action:@selector(halfbtclicked:) forControlEvents:UIControlEventTouchUpInside];
- // [nav.view.window addSubview:bt];
- }];
- }
- - (void)loadBtnBadageData
- {
- [SFriendObj getMyFocusFriendUnReadMsgNumIsFriend:1
- block:^(int unReadNum) {
- int scount = unReadNum;
- if (scount)
- {
- if (scount > 98)
- {
- self.badgeFriend.badgeText = @"99+";
- }
- else
- {
- self.badgeFriend.badgeText = [NSString stringWithFormat:@"%d", scount];
- }
- }
- else
- {
- self.badgeFriend.badgeText = nil;
- }
- }];
-
- [SFriendObj getMyFocusFriendUnReadMsgNumIsFriend:2
- block:^(int unReadNum) {
- int scount = unReadNum;
- if (scount)
- {
- if (scount > 98)
- {
- self.badgeStranger.badgeText = @"99+";
- }
- else
- {
- self.badgeStranger.badgeText = [NSString stringWithFormat:@"%d", scount];
- }
- }
- else
- {
- self.badgeStranger.badgeText = nil;
- }
- }];
- }
- /**
- 设置 角标
-
- @param sender 对应的控件
- */
- - (void)initFriendBadgeBtn:(UIButton *)sender
- {
- //-好友
- self.badgeFriend = [[JSBadgeView alloc] initWithParentView:sender alignment:JSBadgeViewAlignmentTopRight];
- }
- - (void)initStrangerBadgeBtn:(UIButton *)sender
- {
- self.badgeStranger = [[JSBadgeView alloc] initWithParentView:sender alignment:JSBadgeViewAlignmentTopRight];
- }
- - (void)clickFriendItem:(SFriendObj *)obj
- {
- [self goNextVCBlock:2:obj];
- }
- - (void)reloadChatBadge:(int)selectItem
- {
- [SFriendObj getMyFocusFriendUnReadMsgNumIsFriend:selectItem-1
- block:^(int unReadNum) {
- int scount = unReadNum;
- if (selectItem == 2)
- {
- if (scount)
- {
- if (scount > 98)
- {
- self.badgeFriend.badgeText = @"99+";
- }
- else
- {
- self.badgeFriend.badgeText = [NSString stringWithFormat:@"%d", scount];
- }
- }
- else
- {
- self.badgeFriend.badgeText = nil;
- }
- }
- else if (selectItem == 3)
- {
- if (scount)
- {
- if (scount > 98)
- {
- self.badgeStranger.badgeText = @"99+";
- }
- else
- {
- self.badgeStranger.badgeText = [NSString stringWithFormat:@"%d", scount];
- }
- }
- else
- {
- self.badgeStranger.badgeText = nil;
- }
- }
-
- }];
- }
- - (void)updateChatFriendBadge:(int)unReadNum
- {
- if (unReadNum)
- {
- if (unReadNum > 98)
- {
- self.badgeFriend.badgeText = @"99+";
- }
- else
- {
- self.badgeFriend.badgeText = [NSString stringWithFormat:@"%d", unReadNum];
- }
- }
- else
- {
- self.badgeFriend.badgeText = nil;
- }
- }
- - (void)updateChatStrangerBadge:(int)unReadNum
- {
- if (unReadNum)
- {
- if (unReadNum > 98)
- {
- self.badgeStranger.badgeText = @"99+";
- }
- else
- {
- self.badgeStranger.badgeText = [NSString stringWithFormat:@"%d", unReadNum];
- }
- }
- else
- {
- self.badgeStranger.badgeText = nil;
- }
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #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
|