123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- //
- // SKChatMembersViewController.m
- // Kido SKChatMembers
- //
- // Created by 振兴 刘 on 2017/11/28.
- // Copyright © 2017年 BaH Cy. All rights reserved.
- //
- #import "SKChatMembersViewController.h"
- #import "BaseCollectionViewCell.h"
- #import "EDefines.h"
- #import "WatchHeaderReusableView.h"
- #import <UMMobClick/MobClick.h>
- #import <CDDGroupAvatar/DCAvatar.h>
- #define CM_ROW_SIZE 4
- @interface SKChatMembersViewController ()<UICollectionViewDelegateFlowLayout>
- @end
- @implementation SKChatMembersViewController
- static NSString * const CellReuseIdentifier = @"BaseCollectionViewCellID";
- static NSString * const HeaderReuseIdentifier = @"SKChatMembersHeaderID";
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.82]];
- [self.navigationController.navigationBar setTintColor:[UIColor colorWithRed:0/255.0f green:1/255.0f blue:75/255.0f alpha:1]];
- self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
- [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:0/255.0f green:1/255.0f blue:75/255.0f alpha:1],NSForegroundColorAttributeName,nil]];
-
- if (@available(iOS 11.0, *)) {
- self.navigationController.navigationBar.prefersLargeTitles = YES;
- [self.navigationItem setLargeTitleDisplayMode:UINavigationItemLargeTitleDisplayModeNever];
- [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]];
- } else {
- // Fallback on earlier versions
- }
-
-
- [self.navigationController setNavigationBarHidden:NO];
-
- self.edgesForExtendedLayout = UIRectEdgeNone;
- self.automaticallyAdjustsScrollViewInsets = NO;
-
- self.collectionView.alwaysBounceVertical = YES;
- [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([WatchHeaderReusableView class]) bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:HeaderReuseIdentifier];
- }
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 2;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- if (section == 0)
- return 1;
- else
- return ([self.mSessionModel getMembers].count-1)/CM_ROW_SIZE * CM_ROW_SIZE + CM_ROW_SIZE;
- }
- // 表头尺寸
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
- if (section == 0) {
- return CGSizeMake(SCREEN_WIDTH, 0);
- }
- return CGSizeMake(SCREEN_WIDTH, 34);
- }
- // 显示表头的数据
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 1 && kind == UICollectionElementKindSectionHeader) {
- WatchHeaderReusableView *reusableView = [self.collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:HeaderReuseIdentifier forIndexPath:indexPath];
- if(reusableView == nil)
- reusableView = [[WatchHeaderReusableView alloc] init];
- reusableView.mHeaderTitle.text = NSLocalizedString(@"SKChat.Members", nil);
- return reusableView;
- }
- return nil;
- }
- //设置每个子视图的缩进
- -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
- return UIEdgeInsetsMake(0, 0, 0, 0);
- }
- //设置子视图上下之间的距离
- -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
- return 0;
- }
- //设置子视图左右之间的距离
- -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
- return 0;
- }
- //返回每个子视图的大小
- -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
-
- if (indexPath.section == 0) {
- return CGSizeMake(SCREEN_WIDTH, 124);
- }else {
- CGFloat itemWidth = SCREEN_WIDTH / CM_ROW_SIZE ;
- return CGSizeMake(itemWidth, 100);
- }
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- BaseCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellReuseIdentifier forIndexPath:indexPath];
- if (indexPath.row >= [self.mSessionModel getMembers].count)
- return cell;
-
- if (indexPath.section == 0) {
- [cell.mHeaderLabel setText:self.mSessionModel.name];
- NSArray* avatars = [self.mSessionModel getMembersAvatars];
- [cell.mHeaderImage dc_setImageAvatarWithGroupId:self.mSessionModel.sid Source:avatars itemPlaceholder:kIMAGE(@"avatar") options:DCGroupAvatarCachedRefresh completed:^(NSString *groupId, UIImage *groupImage, NSArray<UIImage *> *itemImageArray, NSString *cacheId) {
- }];
- } else {
- SessionMemberModel* model = [[self.mSessionModel getMembers] objectAtIndex:indexPath.row];
- NSString* titleName = model.name;
- NSString* avatarHttp = model.avatarHttp;
- NSInteger avatarLocal = model.avatarLocal;
-
- [cell.mIconLabel setText:NSLocalizedString(titleName, nil)];
- if (avatarHttp.length > 0) {
- [EUtil setURLImage:cell.mIconImage placeHolderName:@"avatar" imageURL:avatarHttp cornerRadius:cell.mIconImage.frame.size.width/2];
- } else if (avatarLocal > 0) {
- NSString *imageImg = [NSString stringWithFormat:@"contact_family_%ld", (long)avatarLocal];
- [cell.mIconImage setImage:[UIImage imageNamed:imageImg]];
- } else {
- [cell.mIconImage setImage:[UIImage imageNamed:@"avatar"]];
- }
- }
- [cell.mHeaderView setHidden:indexPath.section != 0];
- [cell.mIconView setHidden:indexPath.section == 0];
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- if ([ServerManager getServerType] >= 1) {
- [self showVideo:indexPath.row];
- }
- }
- - (void)showVideo:(NSInteger)index {
- @weakify(self);
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"SKChat.Video.Title", nil) message:NSLocalizedString(@"SKChat.Video.Content", nil) preferredStyle:UIAlertControllerStyleAlert];
- [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"SK.Cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- }]];
- [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"SK.Confirm", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
- [weak_self showVideoEx:index];
- }]];
- [self presentViewController:alert animated:YES completion:nil];
- }
- - (void)showVideoEx:(NSInteger)index {
- SessionMemberModel* model = [[self.mSessionModel getMembers] objectAtIndex:index];
- ChildModel* childModel = [[DataManager shared] getChild:model.refId];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [[VideoManager shared] videoStart:self.mSessionModel.sid ticket:childModel.device.ticket dial:1];
- });
- }
- @end
|