Initial commit

This commit is contained in:
ifish
2017-08-15 16:59:01 +08:00
commit bdc83e07ef
5766 changed files with 423223 additions and 0 deletions
@@ -0,0 +1,17 @@
//
// NTESMutiClientsCell.h
// NIM
//
// Created by chris on 15/7/22.
// Copyright (c) 2015年 Netease. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface NTESMutiClientsCell : UITableViewCell
@property (nonatomic,strong) IBOutlet UIButton *kickBtn;
- (void)refreshWidthCilent:(NIMLoginClient *)client;
@end
@@ -0,0 +1,41 @@
//
// NTESMutiClientsCell.m
// NIM
//
// Created by chris on 15/7/22.
// Copyright (c) 2015年 Netease. All rights reserved.
//
#import "NTESMutiClientsCell.h"
#import "NTESClientUtil.h"
#import "UIView+NTES.h"
@implementation NTESMutiClientsCell
- (void)awakeFromNib{
[super awakeFromNib];
self.textLabel.font = [UIFont systemFontOfSize:17.f];
self.textLabel.textColor = UIColorFromRGB(0x333333);
}
- (void)refreshWidthCilent:(NIMLoginClient *)client{
self.textLabel.text = [self nameWithClient:client];
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
CGRect hitRect = self.kickBtn.frame;
return CGRectContainsPoint(hitRect, point) ? self : nil;
}
- (NSString *)nameWithClient:(NIMLoginClient *)client{
NSString *name = [NTESClientUtil clientName:client.type];
return name.length? [NSString stringWithFormat:@"正在使用云信%@版",name] : @"正在使用云信未知版本";
}
- (void)layoutSubviews{
[super layoutSubviews];
[self.textLabel sizeToFit];
self.textLabel.centerY = self.height * .5f;
}
@end
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="NTESMutiClientsCell"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="47" id="KGk-i7-Jjw" customClass="NTESMutiClientsCell">
<rect key="frame" x="0.0" y="0.0" width="320" height="47"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="46.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="OeB-zB-Acr">
<rect key="frame" x="252" y="10" width="60" height="28"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<state key="normal" title="下线" backgroundImage="icon_cell_red_normal">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
</button>
</subviews>
</tableViewCellContentView>
<connections>
<outlet property="kickBtn" destination="OeB-zB-Acr" id="Iq0-Cm-vJL"/>
</connections>
<point key="canvasLocation" x="250" y="254.5"/>
</tableViewCell>
</objects>
<resources>
<image name="icon_cell_red_normal" width="304" height="45"/>
</resources>
</document>
@@ -0,0 +1,39 @@
//
// NTESSessionListHeader.h
// NIM
//
// Created by chris on 15/3/23.
// Copyright (c) 2015年 Netease. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, NTESListHeaderType) {
ListHeaderTypeCommonText = 1,
ListHeaderTypeNetStauts,
ListHeaderTypeLoginClients,
};
@protocol NTESListHeaderView <NSObject>
@required
- (void)setContentText:(NSString *)content;
@end
@protocol NTESListHeaderDelegate <NSObject>
@optional
- (void)didSelectRowType:(NTESListHeaderType)type;
@end
@interface NTESListHeader : UIView
@property (nonatomic,weak) id<NTESListHeaderDelegate> delegate;
- (void)refreshWithType:(NTESListHeaderType)type value:(id)value;
@end
@@ -0,0 +1,155 @@
//
// NTESSessionListHeader.m
// NIM
//
// Created by chris on 15/3/23.
// Copyright (c) 2015年 Netease. All rights reserved.
//
#import "NTESListHeader.h"
#import "UIView+NTES.h"
#import "Reachability.h"
#import "NTESClientUtil.h"
@interface NTESListHeader()
@end
@implementation NTESListHeader
- (void)refreshWithType:(NTESListHeaderType)type value:(id)value{
switch (type) {
case ListHeaderTypeCommonText:
[self refreshWithCommonText:value];
break;
case ListHeaderTypeNetStauts:
[self refreshWithNetStatus:[value integerValue]];
break;
case ListHeaderTypeLoginClients:
[self refreshWithClients:value];
break;
default:
break;
}
[self sizeToFit];
}
- (CGSize)sizeThatFits:(CGSize)size{
CGFloat height = 0;
for (UIView *subView in self.subviews) {
[subView sizeToFit];
height += subView.height;
}
return CGSizeMake(self.width,height);
}
- (void)layoutSubviews{
[super layoutSubviews];
CGFloat top = 0;
for (UIView *subView in self.subviews) {
subView.top = top;
top = top + subView.height;
subView.centerX = self.width * .5f;
}
}
#pragma mark - Private
- (void)refreshWithClients:(NSArray *)clients{
NSString *text = nil;
if (clients.count) {
//目前的踢人逻辑是web和pc不能共存,移动端不能共存,所以这里取第一个显示就可以了
NIMLoginClient *client = clients.firstObject;
NSString *name = [NTESClientUtil clientName:client.type];
text = name.length? [NSString stringWithFormat:@"正在使用云信%@版",name] : @"正在使用云信未知版本";
}
[self addRow:ListHeaderTypeLoginClients content:text viewClassName:@"NTESMutiClientsHeaderView"];
}
- (void)refreshWithNetStatus:(NIMLoginStep)step{
NSString *text = nil;
switch (step) {
case NIMLoginStepLinkFailed:
text = @"当前网络不可用,请检查网络设置";
break;
case NIMLoginStepLoginFailed:
text = @"登录失败";
break;
case NIMLoginStepNetChanged:
{
if ([[Reachability reachabilityForInternetConnection] isReachable])
{
text = @"网络正在切换,识别中....";
}
else
{
text = @"当前网络不可用";
}
}
break;
default:
break;
}
[self refreshWithCommonText:text];
}
- (void)refreshWithCommonText:(NSString *)text{
[self addRow:ListHeaderTypeCommonText content:text viewClassName:@"NTESTextHeaderView"];
}
//参数viewClassName的Class 必须是UIControl的子类并实现<NTESSessionListHeaderView>协议
- (void)addRow:(NTESListHeaderType)type content:(NSString *)content viewClassName:(NSString *)viewClassName{
UIControl<NTESListHeaderView> *rowView = (UIControl<NTESListHeaderView> *)[self viewWithTag:type];
if ([content length])
{
if (!rowView) {
Class clazz = NSClassFromString(viewClassName);
rowView = [[clazz alloc] initWithFrame:CGRectMake(0, 0, self.width, 0)];
rowView.backgroundColor = [self fillBackgroundColor:type];
__block NSInteger insert = self.subviews.count;
[self.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
UIView *view = obj;
if (view.tag > type) {
insert = idx;
*stop = YES;
}
}];
rowView.tag = type;
[self insertSubview:rowView atIndex:insert];
[rowView addTarget:self action:@selector(didSelectRow:) forControlEvents:UIControlEventTouchUpInside];
}
[rowView setContentText:content];
}
else
{
[rowView removeFromSuperview];
}
}
- (void)didSelectRow:(id)sender{
UIControl *view = sender;
if ([self.delegate respondsToSelector:@selector(didSelectRowType:)]) {
[self.delegate didSelectRowType:view.tag];
}
}
- (UIColor *) fillBackgroundColor:(NTESListHeaderType)type{
NSDictionary *dict = @{
@(ListHeaderTypeNetStauts) : [UIColor yellowColor],
@(ListHeaderTypeCommonText) : UIColorFromRGB(0xefefef),
@(ListHeaderTypeLoginClients) : UIColorFromRGB(0xefefef)
};
return dict[@(type)];
}
@end
@@ -0,0 +1,13 @@
//
// NTESMutiClientsHeaderView.h
// NIM
//
// Created by chris on 15/7/22.
// Copyright (c) 2015年 Netease. All rights reserved.
//
#import "NTESListHeader.h"
@interface NTESMutiClientsHeaderView : UIButton<NTESListHeaderView>
@end
@@ -0,0 +1,71 @@
//
// NTESMutiClientsHeaderView.m
// NIM
//
// Created by chris on 15/7/22.
// Copyright (c) 2015年 Netease. All rights reserved.
//
#import "NTESMutiClientsHeaderView.h"
#import "UIView+NTES.h"
@interface NTESMutiClientsHeaderView()
@property (nonatomic,strong) UIImageView *icon;
@property (nonatomic,strong) UILabel *label;
@property (nonatomic,strong) UIButton *accessoryBtn;
@end
@implementation NTESMutiClientsHeaderView
- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_icon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_muti_clients"]];
[self addSubview:_icon];
_label = [[UILabel alloc] initWithFrame:CGRectZero];
_label.textColor = UIColorFromRGB(0x888888);
_label.font = [UIFont boldSystemFontOfSize:14.f];
[self addSubview:_label];
_accessoryBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_accessoryBtn setImage:[UIImage imageNamed:@"icon_arrow"] forState:UIControlStateNormal];
[_accessoryBtn sizeToFit];
[self addSubview:_accessoryBtn];
}
return self;
}
CGFloat TextPadding = 17.f;
- (CGSize)sizeThatFits:(CGSize)size{
[self.label sizeToFit];
CGSize contentSize = self.label.frame.size;
return CGSizeMake(self.width, contentSize.height + TextPadding * 2);
}
#pragma mark - NTESSessionListHeaderView
- (void)setContentText:(NSString *)content{
self.label.text = content;
}
CGFloat IconLeft = 10.f;
CGFloat IconAndContentSpacing = 10.f;
CGFloat ArrowRight = 12.f;
- (void)layoutSubviews{
[super layoutSubviews];
self.icon.left = IconLeft;
self.icon.centerY = self.height * .5f;
self.label.left = self.icon.right + IconAndContentSpacing;
self.label.centerY = self.height * .5f;
self.accessoryBtn.right = self.width - ArrowRight;
self.accessoryBtn.centerY = self.height * .5f;
}
@end
@@ -0,0 +1,15 @@
//
// NTESNetStatusHeaderView.h
// NIM
//
// Created by chris on 15/7/22.
// Copyright (c) 2015年 Netease. All rights reserved.
//
#import "NTESListHeader.h"
@interface NTESTextHeaderView : UIButton<NTESListHeaderView>
@property (nonatomic,strong) UILabel *label;
@end
@@ -0,0 +1,43 @@
//
// NTESNetStatusHeaderView.m
// NIM
//
// Created by chris on 15/7/22.
// Copyright (c) 2015年 Netease. All rights reserved.
//
#import "NTESTextHeaderView.h"
#import "UIView+NTES.h"
@implementation NTESTextHeaderView
- (instancetype) initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_label = [[UILabel alloc] initWithFrame:CGRectZero];
_label.textColor = UIColorFromRGB(0x888888);
_label.font = [UIFont systemFontOfSize:14.f];
[self addSubview:_label];
}
return self;
}
- (void)setContentText:(NSString *)content{
self.label.text = content;
}
#define SessionListRowContentTopPadding 10
- (CGSize)sizeThatFits:(CGSize)size{
[self.label sizeToFit];
CGSize contentSize = self.label.frame.size;
return CGSizeMake(self.width, contentSize.height + SessionListRowContentTopPadding * 2);
}
- (void)layoutSubviews{
[super layoutSubviews];
self.label.centerX = self.width * .5f;
self.label.centerY = self.height * .5f;
}
@end
@@ -0,0 +1,23 @@
//
// NTESClientsTableViewController.h
// NIM
//
// Created by amao on 6/1/15.
// Copyright (c) 2015 Netease. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface NTESClientsTableViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) UITableView *tableView;
@end
@interface NTESClientsTableHeader : UIView
@property (nonatomic,strong) UIImageView *icon;
@end
@@ -0,0 +1,187 @@
//
// NTESClientsTableViewController.m
// NIM
//
// Created by amao on 6/1/15.
// Copyright (c) 2015 Netease. All rights reserved.
//
#import "NTESClientsTableViewController.h"
#import <NIMSDK/NIMSDK.h>
#import "NTESSessionUtil.h"
#import "UIView+NTES.h"
#import "NTESMutiClientsCell.h"
#import "Toast+UIView.h"
NSString *Identifier = @"client_cell";
@interface NTESClientsTableViewController ()<NIMLoginManagerDelegate>
@property (nonatomic,strong) NSArray *clients;
@end
@implementation NTESClientsTableViewController
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[[NIMSDK sharedSDK].loginManager addDelegate:self];
}
return self;
}
- (void)dealloc{
[[NIMSDK sharedSDK].loginManager removeDelegate:self];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"多端登录管理";
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.tableView.backgroundColor = UIColorFromRGB(0xecf1f5);
[self.tableView registerNib:[UINib nibWithNibName:@"NTESMutiClientsCell" bundle:nil] forCellReuseIdentifier:Identifier];
self.tableView.tableFooterView = [[UIView alloc] init];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
self.clients = [[[NIMSDK sharedSDK] loginManager] currentLoginClients];
}
- (void)viewDidLayoutSubviews{
NTESClientsTableHeader *header = [[NTESClientsTableHeader alloc] initWithFrame:CGRectZero];
CGSize size = [header sizeThatFits:self.view.size];
header.size = size;
self.tableView.tableHeaderView = header;
}
- (void)reload
{
self.clients = [[[NIMSDK sharedSDK] loginManager] currentLoginClients];
[self.tableView reloadData];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [_clients count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 60;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NTESMutiClientsCell *cell = [tableView dequeueReusableCellWithIdentifier:Identifier];
NIMLoginClient *client = [_clients objectAtIndex:[indexPath row]];
[cell refreshWidthCilent:client];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
__weak typeof(self) weakSelf = self;
NIMLoginClient *client = [_clients objectAtIndex:[indexPath row]];
[[[NIMSDK sharedSDK] loginManager] kickOtherClient:client
completion:^(NSError *error) {
[weakSelf reload];
}];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NIMLoginClient *client = [_clients objectAtIndex:[indexPath row]];
__weak typeof(self) wself = self;
[[NIMSDK sharedSDK].loginManager kickOtherClient:client completion:^(NSError *error) {
if (error) {
[wself.view makeToast:@"踢出失败"
];
}
[wself reload];
}];
}
#pragma mark - NIMLoginManagerDelegate
- (void)onMultiLoginClientsChanged{
self.clients = [[[NIMSDK sharedSDK] loginManager] currentLoginClients];
if (self.clients.count) {
[self reload];
}else{
[self.navigationController.view makeToast:@"已没有其他设备连接"
];
[self.navigationController popViewControllerAnimated:YES];
}
}
#pragma mark - 旋转处理 (iOS7)
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
UIView *header = self.tableView.tableHeaderView;
CGSize size = [header sizeThatFits:self.view.size];
header.size = size;
self.tableView.tableHeaderView = header;
}
#pragma mark - 旋转处理 (iOS8 or above)
- (void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
UIView *header = self.tableView.tableHeaderView;
CGSize headerSize = [header sizeThatFits:size];
header.size = headerSize;
self.tableView.tableHeaderView = header;
}
@end
@implementation NTESClientsTableHeader
- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
_icon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_clients"]];
[self addSubview:_icon];
}
return self;
}
CGFloat TableHeaderBottom = 75.f;
CGFloat NavBarHeight = 44.f;
- (CGSize)sizeThatFits:(CGSize)size{
CGFloat height = size.height - NavBarHeight - [UIApplication sharedApplication].statusBarFrame.size.height - TableHeaderBottom;
return CGSizeMake(size.width, height);
}
CGFloat IconTop = 73.f;
- (void)layoutSubviews{
[super layoutSubviews];
self.icon.top = IconTop;
self.icon.centerX = self.width * .5f;
}
@end
@@ -0,0 +1,15 @@
//
// NTESSessionListViewController.h
// NIMDemo
//
// Created by chris on 15/2/2.
// Copyright (c) 2015年 Netease. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface NTESSessionListViewController : NIMSessionListViewController
@property (nonatomic,strong) UILabel *emptyTipLabel;
@end
@@ -0,0 +1,334 @@
//
// NTESSessionListViewController.m
// NIMDemo
//
// Created by chris on 15/2/2.
// Copyright (c) 2015年 Netease. All rights reserved.
//
#import "NTESSessionListViewController.h"
#import "NSString+JSON.h"
//#import "NTESSessionViewController.h"
#import "IfishSessionViewController.h"
#import "UIView+NTES.h"
#import "NTESBundleSetting.h"
#import "NTESListHeader.h"
#import "NTESClientsTableViewController.h"
#import "NTESSnapchatAttachment.h"
#import "NTESJanKenPonAttachment.h"
#import "NTESChartletAttachment.h"
#import "NTESWhiteboardAttachment.h"
#import "NTESSessionUtil.h"
#import "NTESPersonalCardViewController.h"
#define SessionListTitle @"消息"
#import "IfishNomassageView.h"
#import "InfoViewController.h"
@interface NTESSessionListViewController ()<NIMLoginManagerDelegate,NTESListHeaderDelegate>
@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) NTESListHeader *header;
@property(nonatomic,strong) IfishNomassageView *nomassagView;
@end
@implementation NTESSessionListViewController
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.autoRemoveRemoteSession = [[NTESBundleSetting sharedConfig] autoRemoveRemoteSession];
}
return self;
}
- (void)dealloc{
[[NIMSDK sharedSDK].loginManager removeDelegate:self];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
NSInteger count = [[[NIMSDK sharedSDK] conversationManager] allUnreadCount];
count ==0 ? (self.navigationController.tabBarItem.badgeValue =nil):(self.navigationController.tabBarItem.badgeValue = [NSString stringWithFormat:@"%ld",(long)count]);
}
- (void)viewDidLoad{
[super viewDidLoad];
[[NIMSDK sharedSDK].loginManager addDelegate:self];
self.header = [[NTESListHeader alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 0)];
self.header.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.header.delegate = self;
//title 加用户名
//[self.view addSubview:self.header];
self.emptyTipLabel = [[UILabel alloc] init];
self.emptyTipLabel.text = @"还没有会话";
[self.emptyTipLabel sizeToFit];
self.emptyTipLabel.hidden = self.recentSessions.count;
//[self.view addSubview:self.emptyTipLabel];
//NSString *userID = [[[NIMSDK sharedSDK] loginManager] currentAccount];
//self.navigationItem.titleView = [self titleView:userID];
self.nomassagView = [[IfishNomassageView alloc] initWithFrame:CGRectMake(0,self.view.frame.size.height/2 -40, kScreenSize.width, 80)];
self.nomassagView.hidden = self.recentSessions.count;
//self.nomassagView.backgroundColor = IFISHMASSAGE_BACKGROUD_COLOR;
self.nomassagView.backgroundColor = TABLE_BACKGROUD_COLOR;
[self.view addSubview:self.nomassagView];
self.view.backgroundColor = TABLE_BACKGROUD_COLOR;
//消息列表不在tab栏中时设置返回按钮
UIButton *bakbutton = [UIButton buttonWithType:UIButtonTypeCustom];
bakbutton.frame = CGRectMake(0,0,48,44);
[bakbutton setImage:[UIImage imageNamed:@"arrow_l"] forState:UIControlStateNormal];
[bakbutton addTarget: self action: @selector(backAction) forControlEvents: UIControlEventTouchUpInside];
UIBarButtonItem *backTem=[[UIBarButtonItem alloc] initWithCustomView:bakbutton];
self.navigationItem.leftBarButtonItem=backTem;
[self addTitleViewWithTitle:@"消息"];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
}
- (void)addTitleViewWithTitle:(NSString *)title{
UILabel*labe=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60, 44)];
labe.text=title;
labe.textAlignment=NSTextAlignmentCenter;
labe.textColor=[UIColor whiteColor];
labe.font = [UIFont systemFontOfSize:19];
self.navigationItem.titleView=labe;
}
-(void)backAction{
// [self dismissViewControllerAnimated:YES completion:^{
//
// }];
[self.navigationController popViewControllerAnimated:YES];
}
- (void)reload{
[super reload];
self.emptyTipLabel.hidden = self.recentSessions.count;
self.nomassagView.hidden = self.recentSessions.count;
}
- (void)onSelectedRecent:(NIMRecentSession *)recent atIndexPath:(NSIndexPath *)indexPath{
//需要获取当前id 在 爱鱼奇用户系统中的名字 爱鱼奇系统的id 是云信用户系统的Acount 即账号
//还可以判断是否有用户扩展ziduan {"user_type":"official"} 有是爱鱼奇官方 无则为普通用户
IfishSessionViewController *vc = [[IfishSessionViewController alloc] initWithSession:recent.session];
// if ([recent.session.sessionId isEqualToString:@"ifish"]) {
//
// vc.isAiYuQi = YES;
//
//
// }else{
//
// vc.isAiYuQi = NO;
//
// }
NSArray *userArr=@[recent.session.sessionId];
[[NIMSDK sharedSDK].userManager fetchUserInfos:userArr completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
NIMUser *user=users[0];
NSLog(@"fetchUserInfoleftUserext:%@",user.userInfo.ext);
if (error!=nil) {
NSString *tost=[NSString stringWithFormat:@"获取用户信息错误:%@",error];
[self.view makeToast:tost];
return ;
}
if (![user.userInfo.ext isKindOfClass:[NSNull class]]) {
NSString *extstr=user.userInfo.ext;
NSDictionary *extDic=[extstr parseJSONStringToNSDictionary:extstr];
NSString *usertype=extDic[@"user_type"];
if ([usertype isEqualToString:@"official"]) {
vc.isAiYuQi = YES;
}else{
vc.isAiYuQi = NO;
}
}else{
vc.isAiYuQi = NO;
}
//vc.isAiYuQi = [user.userInfo.ext isKindOfClass:[NSNull class]] ? NO : YES;
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
//self.hidesBottomBarWhenPushed = NO;
}];
}
- (void)onSelectedAvatar:(NIMRecentSession *)recent
atIndexPath:(NSIndexPath *)indexPath{
if (recent.session.sessionType == NIMSessionTypeP2P) {
// NTESPersonalCardViewController *vc = [[NTESPersonalCardViewController alloc] initWithUserId:recent.session.sessionId];
//若点击头像进入 资料卡 打开下面
// self.hidesBottomBarWhenPushed = YES;
// InfoViewController *vc =[[InfoViewController alloc] init];
// [self.navigationController pushViewController:vc animated:YES];
// self.hidesBottomBarWhenPushed = NO;
}
}
- (void)onDeleteRecentAtIndexPath:(NIMRecentSession *)recent atIndexPath:(NSIndexPath *)indexPath{
[super onDeleteRecentAtIndexPath:recent atIndexPath:indexPath];
self.emptyTipLabel.hidden = self.recentSessions.count;
self.nomassagView.hidden = self.recentSessions.count;
}
- (void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
[self refreshSubview];
}
- (NSString *)nameForRecentSession:(NIMRecentSession *)recent{
if ([recent.session.sessionId isEqualToString:[[NIMSDK sharedSDK].loginManager currentAccount]]) {
return @"我的电脑";
}
return [super nameForRecentSession:recent];
}
#pragma mark - SessionListHeaderDelegate
- (void)didSelectRowType:(NTESListHeaderType)type{
//多人登录
switch (type) {
case ListHeaderTypeLoginClients:{
NTESClientsTableViewController *vc = [[NTESClientsTableViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:vc animated:YES];
break;
}
default:
break;
}
}
#pragma mark - NIMLoginManagerDelegate
- (void)onLogin:(NIMLoginStep)step{
[super onLogin:step];
switch (step) {
case NIMLoginStepLinkFailed:
self.titleLabel.text = [SessionListTitle stringByAppendingString:@"(未连接)"];
break;
case NIMLoginStepLinking:
self.titleLabel.text = [SessionListTitle stringByAppendingString:@"(连接中)"];
break;
case NIMLoginStepLinkOK:
case NIMLoginStepSyncOK:
self.titleLabel.text = SessionListTitle;
break;
case NIMLoginStepSyncing:
self.titleLabel.text = [SessionListTitle stringByAppendingString:@"(同步数据)"];
break;
default:
break;
}
[self.titleLabel sizeToFit];
self.titleLabel.centerX = self.navigationItem.titleView.width * .5f;
[self.header refreshWithType:ListHeaderTypeNetStauts value:@(step)];
[self.view setNeedsLayout];
}
- (void)onMultiLoginClientsChanged
{
[self.header refreshWithType:ListHeaderTypeLoginClients value:[NIMSDK sharedSDK].loginManager.currentLoginClients];
[self.view setNeedsLayout];
}
#pragma mark - Private
- (void)refreshSubview{
[self.titleLabel sizeToFit];
self.titleLabel.centerX = self.navigationItem.titleView.width * .5f;
self.tableView.top = self.header.height;
self.tableView.height = self.view.height - self.tableView.top;
self.header.bottom = self.tableView.top + self.tableView.contentInset.top;
self.emptyTipLabel.centerX = self.view.width * .5f;
self.emptyTipLabel.centerY = self.tableView.height * .5f;
}
- (UIView*)titleView:(NSString*)userID{
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.titleLabel.text = SessionListTitle;
self.titleLabel.font = [UIFont boldSystemFontOfSize:15.f];
[self.titleLabel sizeToFit];
UILabel *subLabel = [[UILabel alloc] initWithFrame:CGRectZero];
subLabel.textColor = [UIColor grayColor];
subLabel.font = [UIFont systemFontOfSize:12.f];
subLabel.text = userID;
subLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[subLabel sizeToFit];
UIView *titleView = [[UIView alloc] init];
titleView.width = subLabel.width;
titleView.height = self.titleLabel.height + subLabel.height;
subLabel.bottom = titleView.height;
[titleView addSubview:self.titleLabel];
[titleView addSubview:subLabel];
return titleView;
}
- (NSString *)contentForRecentSession:(NIMRecentSession *)recent{
if (recent.lastMessage.messageType == NIMMessageTypeCustom) {
NIMCustomObject *object = recent.lastMessage.messageObject;
NSString *text = @"";
if ([object.attachment isKindOfClass:[NTESSnapchatAttachment class]]) {
text = @"[阅后即焚]";
}
else if ([object.attachment isKindOfClass:[NTESJanKenPonAttachment class]]) {
text = @"[猜拳]";
}
else if ([object.attachment isKindOfClass:[NTESChartletAttachment class]]) {
text = @"[贴图]";
}
else if ([object.attachment isKindOfClass:[NTESWhiteboardAttachment class]]) {
text = @"[白板]";
}else{
text = @"[未知消息]";
}
if (recent.session.sessionType == NIMSessionTypeP2P) {
return text;
}else{
NSString *nickName = [NTESSessionUtil showNick:recent.lastMessage.from inSession:recent.lastMessage.session];
return nickName.length ? [nickName stringByAppendingFormat:@" : %@",text] : @"";
}
}
return [super contentForRecentSession:recent];
}
@end