SKChatMembersViewController.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. //
  2. // SKChatMembersViewController.m
  3. // Kido SKChatMembers
  4. //
  5. // Created by 振兴 刘 on 2017/11/28.
  6. // Copyright © 2017年 BaH Cy. All rights reserved.
  7. //
  8. #import "SKChatMembersViewController.h"
  9. #import "BaseCollectionViewCell.h"
  10. #import "EDefines.h"
  11. #import "WatchHeaderReusableView.h"
  12. #import <UMMobClick/MobClick.h>
  13. #import <CDDGroupAvatar/DCAvatar.h>
  14. #define CM_ROW_SIZE 4
  15. @interface SKChatMembersViewController ()<UICollectionViewDelegateFlowLayout>
  16. @end
  17. @implementation SKChatMembersViewController
  18. static NSString * const CellReuseIdentifier = @"BaseCollectionViewCellID";
  19. static NSString * const HeaderReuseIdentifier = @"SKChatMembersHeaderID";
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.82]];
  23. [self.navigationController.navigationBar setTintColor:[UIColor colorWithRed:0/255.0f green:1/255.0f blue:75/255.0f alpha:1]];
  24. self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
  25. [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:0/255.0f green:1/255.0f blue:75/255.0f alpha:1],NSForegroundColorAttributeName,nil]];
  26. if (@available(iOS 11.0, *)) {
  27. self.navigationController.navigationBar.prefersLargeTitles = YES;
  28. [self.navigationItem setLargeTitleDisplayMode:UINavigationItemLargeTitleDisplayModeNever];
  29. [self.navigationController.navigationBar setLargeTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:0/255.0f green:1/255.0f blue:75/255.0f alpha:1], NSForegroundColorAttributeName,[UIFont systemFontOfSize:32.0f weight:UIFontWeightMedium],NSFontAttributeName,nil]];
  30. } else {
  31. // Fallback on earlier versions
  32. }
  33. [self.navigationController setNavigationBarHidden:NO];
  34. self.edgesForExtendedLayout = UIRectEdgeNone;
  35. self.automaticallyAdjustsScrollViewInsets = NO;
  36. self.collectionView.alwaysBounceVertical = YES;
  37. [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([WatchHeaderReusableView class]) bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:HeaderReuseIdentifier];
  38. }
  39. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  40. return 2;
  41. }
  42. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  43. if (section == 0)
  44. return 1;
  45. else
  46. return ([self.mSessionModel getMembers].count-1)/CM_ROW_SIZE * CM_ROW_SIZE + CM_ROW_SIZE;
  47. }
  48. // 表头尺寸
  49. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
  50. if (section == 0) {
  51. return CGSizeMake(SCREEN_WIDTH, 0);
  52. }
  53. return CGSizeMake(SCREEN_WIDTH, 34);
  54. }
  55. // 显示表头的数据
  56. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  57. if (indexPath.section == 1 && kind == UICollectionElementKindSectionHeader) {
  58. WatchHeaderReusableView *reusableView = [self.collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:HeaderReuseIdentifier forIndexPath:indexPath];
  59. if(reusableView == nil)
  60. reusableView = [[WatchHeaderReusableView alloc] init];
  61. reusableView.mHeaderTitle.text = NSLocalizedString(@"SKChat.Members", nil);
  62. return reusableView;
  63. }
  64. return nil;
  65. }
  66. //设置每个子视图的缩进
  67. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
  68. return UIEdgeInsetsMake(0, 0, 0, 0);
  69. }
  70. //设置子视图上下之间的距离
  71. -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  72. return 0;
  73. }
  74. //设置子视图左右之间的距离
  75. -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  76. return 0;
  77. }
  78. //返回每个子视图的大小
  79. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  80. if (indexPath.section == 0) {
  81. return CGSizeMake(SCREEN_WIDTH, 124);
  82. }else {
  83. CGFloat itemWidth = SCREEN_WIDTH / CM_ROW_SIZE ;
  84. return CGSizeMake(itemWidth, 100);
  85. }
  86. }
  87. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  88. BaseCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellReuseIdentifier forIndexPath:indexPath];
  89. if (indexPath.row >= [self.mSessionModel getMembers].count)
  90. return cell;
  91. if (indexPath.section == 0) {
  92. [cell.mHeaderLabel setText:self.mSessionModel.name];
  93. NSArray* avatars = [self.mSessionModel getMembersAvatars];
  94. [cell.mHeaderImage dc_setImageAvatarWithGroupId:self.mSessionModel.sid Source:avatars itemPlaceholder:kIMAGE(@"avatar") options:DCGroupAvatarCachedRefresh completed:^(NSString *groupId, UIImage *groupImage, NSArray<UIImage *> *itemImageArray, NSString *cacheId) {
  95. }];
  96. } else {
  97. SessionMemberModel* model = [[self.mSessionModel getMembers] objectAtIndex:indexPath.row];
  98. NSString* titleName = model.name;
  99. NSString* avatarHttp = model.avatarHttp;
  100. NSInteger avatarLocal = model.avatarLocal;
  101. [cell.mIconLabel setText:NSLocalizedString(titleName, nil)];
  102. if (avatarHttp.length > 0) {
  103. [EUtil setURLImage:cell.mIconImage placeHolderName:@"avatar" imageURL:avatarHttp cornerRadius:cell.mIconImage.frame.size.width/2];
  104. } else if (avatarLocal > 0) {
  105. NSString *imageImg = [NSString stringWithFormat:@"contact_family_%ld", (long)avatarLocal];
  106. [cell.mIconImage setImage:[UIImage imageNamed:imageImg]];
  107. } else {
  108. [cell.mIconImage setImage:[UIImage imageNamed:@"avatar"]];
  109. }
  110. }
  111. [cell.mHeaderView setHidden:indexPath.section != 0];
  112. [cell.mIconView setHidden:indexPath.section == 0];
  113. return cell;
  114. }
  115. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  116. if ([ServerManager getServerType] >= 1) {
  117. [self showVideo:indexPath.row];
  118. }
  119. }
  120. - (void)showVideo:(NSInteger)index {
  121. @weakify(self);
  122. UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"SKChat.Video.Title", nil) message:NSLocalizedString(@"SKChat.Video.Content", nil) preferredStyle:UIAlertControllerStyleAlert];
  123. [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"SK.Cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  124. }]];
  125. [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"SK.Confirm", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  126. [weak_self showVideoEx:index];
  127. }]];
  128. [self presentViewController:alert animated:YES completion:nil];
  129. }
  130. - (void)showVideoEx:(NSInteger)index {
  131. SessionMemberModel* model = [[self.mSessionModel getMembers] objectAtIndex:index];
  132. ChildModel* childModel = [[DataManager shared] getChild:model.refId];
  133. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  134. [[VideoManager shared] videoStart:self.mSessionModel.sid ticket:childModel.device.ticket dial:1];
  135. });
  136. }
  137. @end