私信模块:私信列表页面
This commit is contained in:
@@ -66,6 +66,7 @@
|
||||
189DD75926E6003C00AB55B1 /* Api.m in Sources */ = {isa = PBXBuildFile; fileRef = 189DD75826E6003C00AB55B1 /* Api.m */; };
|
||||
189DD76226E60DDC00AB55B1 /* Api+Login.m in Sources */ = {isa = PBXBuildFile; fileRef = 189DD76126E60DDC00AB55B1 /* Api+Login.m */; };
|
||||
18A61BD7274F7F6900A09A54 /* NetImageConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 18A61BD6274F7F6900A09A54 /* NetImageConfig.m */; };
|
||||
18A61BE8274F9CF000A09A54 /* SessionListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 18A61BE7274F9CF000A09A54 /* SessionListViewController.m */; };
|
||||
18C17A5D26F338F300C48E11 /* XplanFBFlutterViewContainer.m in Sources */ = {isa = PBXBuildFile; fileRef = 18C17A5C26F338F300C48E11 /* XplanFBFlutterViewContainer.m */; };
|
||||
18E7B1B226E8AF980064BC9B /* MainPresenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 18E7B1B126E8AF980064BC9B /* MainPresenter.m */; };
|
||||
18E7B1B726E8B2D10064BC9B /* Api+Main.m in Sources */ = {isa = PBXBuildFile; fileRef = 18E7B1B626E8B2D10064BC9B /* Api+Main.m */; };
|
||||
@@ -94,6 +95,11 @@
|
||||
18E7B31E26F0984C0064BC9B /* UserLevelVo.m in Sources */ = {isa = PBXBuildFile; fileRef = 18E7B31D26F0984C0064BC9B /* UserLevelVo.m */; };
|
||||
18E7B32126F098650064BC9B /* UserInfoSkillVo.m in Sources */ = {isa = PBXBuildFile; fileRef = 18E7B32026F098650064BC9B /* UserInfoSkillVo.m */; };
|
||||
18E7B33226F317A20064BC9B /* XPWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 18E7B33126F317A20064BC9B /* XPWebViewController.m */; };
|
||||
18EE3FDF2750C1F700A452BF /* SessionListCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 18EE3FDE2750C1F700A452BF /* SessionListCell.m */; };
|
||||
18EE3FE22750C29D00A452BF /* NIMBadgeView.m in Sources */ = {isa = PBXBuildFile; fileRef = 18EE3FE12750C29D00A452BF /* NIMBadgeView.m */; };
|
||||
18EE3FEE2750CE6D00A452BF /* NIMMessageUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 18EE3FED2750CE6D00A452BF /* NIMMessageUtils.m */; };
|
||||
18EE3FF12750D2AD00A452BF /* NIMTimeUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 18EE3FF02750D2AD00A452BF /* NIMTimeUtils.m */; };
|
||||
18EE3FF42750FA3700A452BF /* UIView+NIM.m in Sources */ = {isa = PBXBuildFile; fileRef = 18EE3FF32750FA3700A452BF /* UIView+NIM.m */; };
|
||||
73FFADDC93E195344047A2EC /* Pods_xplan_ios.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CACF623970097D653132D69A /* Pods_xplan_ios.framework */; };
|
||||
9B0E1C5926E77022005D4442 /* BaseNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B0E1C5826E77022005D4442 /* BaseNavigationController.m */; };
|
||||
E80487652717DDD9008595F2 /* XPRoomMenuItem.m in Sources */ = {isa = PBXBuildFile; fileRef = E80487642717DDD9008595F2 /* XPRoomMenuItem.m */; };
|
||||
@@ -404,6 +410,8 @@
|
||||
189DD78026E620FE00AB55B1 /* ApiHost.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ApiHost.h; sourceTree = "<group>"; };
|
||||
18A61BD5274F7F6900A09A54 /* NetImageConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NetImageConfig.h; sourceTree = "<group>"; };
|
||||
18A61BD6274F7F6900A09A54 /* NetImageConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NetImageConfig.m; sourceTree = "<group>"; };
|
||||
18A61BE6274F9CF000A09A54 /* SessionListViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SessionListViewController.h; sourceTree = "<group>"; };
|
||||
18A61BE7274F9CF000A09A54 /* SessionListViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SessionListViewController.m; sourceTree = "<group>"; };
|
||||
18C17A5B26F338F300C48E11 /* XplanFBFlutterViewContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XplanFBFlutterViewContainer.h; sourceTree = "<group>"; };
|
||||
18C17A5C26F338F300C48E11 /* XplanFBFlutterViewContainer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XplanFBFlutterViewContainer.m; sourceTree = "<group>"; };
|
||||
18E7B1AE26E8AD760064BC9B /* MainProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MainProtocol.h; sourceTree = "<group>"; };
|
||||
@@ -437,6 +445,16 @@
|
||||
18E7B32026F098650064BC9B /* UserInfoSkillVo.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UserInfoSkillVo.m; sourceTree = "<group>"; };
|
||||
18E7B33026F317A20064BC9B /* XPWebViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPWebViewController.h; sourceTree = "<group>"; };
|
||||
18E7B33126F317A20064BC9B /* XPWebViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPWebViewController.m; sourceTree = "<group>"; };
|
||||
18EE3FDD2750C1F700A452BF /* SessionListCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SessionListCell.h; sourceTree = "<group>"; };
|
||||
18EE3FDE2750C1F700A452BF /* SessionListCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SessionListCell.m; sourceTree = "<group>"; };
|
||||
18EE3FE02750C29D00A452BF /* NIMBadgeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NIMBadgeView.h; sourceTree = "<group>"; };
|
||||
18EE3FE12750C29D00A452BF /* NIMBadgeView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NIMBadgeView.m; sourceTree = "<group>"; };
|
||||
18EE3FEC2750CE6D00A452BF /* NIMMessageUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NIMMessageUtils.h; sourceTree = "<group>"; };
|
||||
18EE3FED2750CE6D00A452BF /* NIMMessageUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NIMMessageUtils.m; sourceTree = "<group>"; };
|
||||
18EE3FEF2750D2AD00A452BF /* NIMTimeUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NIMTimeUtils.h; sourceTree = "<group>"; };
|
||||
18EE3FF02750D2AD00A452BF /* NIMTimeUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NIMTimeUtils.m; sourceTree = "<group>"; };
|
||||
18EE3FF22750FA3700A452BF /* UIView+NIM.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+NIM.h"; sourceTree = "<group>"; };
|
||||
18EE3FF32750FA3700A452BF /* UIView+NIM.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+NIM.m"; sourceTree = "<group>"; };
|
||||
7DB00EC07F1D0ADFF900B38D /* Pods-xplan-ios.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-xplan-ios.debug.xcconfig"; path = "Target Support Files/Pods-xplan-ios/Pods-xplan-ios.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
9B0E1C5726E77022005D4442 /* BaseNavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BaseNavigationController.h; sourceTree = "<group>"; };
|
||||
9B0E1C5826E77022005D4442 /* BaseNavigationController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BaseNavigationController.m; sourceTree = "<group>"; };
|
||||
@@ -1270,6 +1288,18 @@
|
||||
18A61BCC274F72ED00A09A54 /* Message */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
18A61BE6274F9CF000A09A54 /* SessionListViewController.h */,
|
||||
18A61BE7274F9CF000A09A54 /* SessionListViewController.m */,
|
||||
18EE3FDD2750C1F700A452BF /* SessionListCell.h */,
|
||||
18EE3FDE2750C1F700A452BF /* SessionListCell.m */,
|
||||
18EE3FE02750C29D00A452BF /* NIMBadgeView.h */,
|
||||
18EE3FE12750C29D00A452BF /* NIMBadgeView.m */,
|
||||
18EE3FEC2750CE6D00A452BF /* NIMMessageUtils.h */,
|
||||
18EE3FED2750CE6D00A452BF /* NIMMessageUtils.m */,
|
||||
18EE3FEF2750D2AD00A452BF /* NIMTimeUtils.h */,
|
||||
18EE3FF02750D2AD00A452BF /* NIMTimeUtils.m */,
|
||||
18EE3FF22750FA3700A452BF /* UIView+NIM.h */,
|
||||
18EE3FF32750FA3700A452BF /* UIView+NIM.m */,
|
||||
);
|
||||
path = Message;
|
||||
sourceTree = "<group>";
|
||||
@@ -1295,10 +1325,10 @@
|
||||
18E7B22826E8CE100064BC9B /* XCFlutterKeyConst.h */,
|
||||
18E7B22426E8CDCF0064BC9B /* XplanFlutterBoostDelegate.h */,
|
||||
18E7B22326E8CDCF0064BC9B /* XplanFlutterBoostDelegate.m */,
|
||||
18C17A5B26F338F300C48E11 /* XplanFBFlutterViewContainer.h */,
|
||||
18C17A5C26F338F300C48E11 /* XplanFBFlutterViewContainer.m */,
|
||||
18E7B28E26EA0E6B0064BC9B /* FlutterBoost+Xplan.h */,
|
||||
18E7B28F26EA0E6B0064BC9B /* FlutterBoost+Xplan.m */,
|
||||
18C17A5B26F338F300C48E11 /* XplanFBFlutterViewContainer.h */,
|
||||
18C17A5C26F338F300C48E11 /* XplanFBFlutterViewContainer.m */,
|
||||
);
|
||||
path = Match;
|
||||
sourceTree = "<group>";
|
||||
@@ -2251,6 +2281,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
181D7F1B2726CE2A00B7C059 /* StageView.m in Sources */,
|
||||
18EE3FF12750D2AD00A452BF /* NIMTimeUtils.m in Sources */,
|
||||
E8B846D826FDE17300A777FE /* XPMineRechargeProtocol.h in Sources */,
|
||||
E8B846C726FDB45000A777FE /* XPMineUserInfoAlbumProtocol.h in Sources */,
|
||||
E890BC07273CF1800007C46B /* XPGiftCountCollectionViewCell.m in Sources */,
|
||||
@@ -2300,7 +2331,9 @@
|
||||
E8E70D8926F2F58F00F03460 /* XPMineMatchTableViewCell.m in Sources */,
|
||||
E88B5CA826FB089C00DA9178 /* XPMineTeenagePwdViewController.m in Sources */,
|
||||
E81C279626EB39CC0031E639 /* LoginForgetPasswordPresent.m in Sources */,
|
||||
18EE3FF42750FA3700A452BF /* UIView+NIM.m in Sources */,
|
||||
E8AC723526F49939007D6E91 /* XPMineNotificaPresenter.m in Sources */,
|
||||
18EE3FE22750C29D00A452BF /* NIMBadgeView.m in Sources */,
|
||||
E82EE0F8272FDDFA00D15DC1 /* UserPrivacyView.m in Sources */,
|
||||
189DD53426DE255300AB55B1 /* TabbarViewController.m in Sources */,
|
||||
E8EEB91D26FC9D58007C6EBA /* XPMineUserInfoDateView.m in Sources */,
|
||||
@@ -2365,6 +2398,7 @@
|
||||
186A534B26FC6ED900D67B2C /* TTPopupManagerService.m in Sources */,
|
||||
18E7B1B226E8AF980064BC9B /* MainPresenter.m in Sources */,
|
||||
E81366F626F0C0DF0076364C /* LoginFullInfoPresenter.m in Sources */,
|
||||
18A61BE8274F9CF000A09A54 /* SessionListViewController.m in Sources */,
|
||||
E811FFF72742367B00918544 /* XPGiftEmptyCollectionViewCell.m in Sources */,
|
||||
189DD67E26E1FD8900AB55B1 /* UIImage+Utils.m in Sources */,
|
||||
E824545626F5E51900BE8163 /* XPMineVerifIdentityViewController.m in Sources */,
|
||||
@@ -2433,6 +2467,7 @@
|
||||
E81366FC26F0D2980076364C /* UIButton+EnlargeTouchArea.m in Sources */,
|
||||
E824546426F5FF1C00BE8163 /* XPMineResetPayPasswordPresenter.m in Sources */,
|
||||
E884C3722743AEDE00E1EBED /* CustomAttachmentDecoder.m in Sources */,
|
||||
18EE3FEE2750CE6D00A452BF /* NIMMessageUtils.m in Sources */,
|
||||
E8B846BC26FD7C1200A777FE /* UploadImage.m in Sources */,
|
||||
186A534D26FC6ED900D67B2C /* TTActionSheetView.m in Sources */,
|
||||
E83DB481274649FB00D8CBD1 /* XPGiftBannerUserInfoModel.m in Sources */,
|
||||
@@ -2450,6 +2485,7 @@
|
||||
E88B5CC526FB42B000DA9178 /* XPMineUserInfoHeaderView.m in Sources */,
|
||||
E8EEB8FB26FC2874007C6EBA /* XPMineUserInfoTableViewCell.m in Sources */,
|
||||
E8AC721626F46B06007D6E91 /* XPMineSettingTableViewCell.m in Sources */,
|
||||
18EE3FDF2750C1F700A452BF /* SessionListCell.m in Sources */,
|
||||
E80487652717DDD9008595F2 /* XPRoomMenuItem.m in Sources */,
|
||||
189DD75026E21D9000AB55B1 /* GCDHelper.m in Sources */,
|
||||
E84B0E422727EE0A008818C6 /* XPRoomMessageHeaderView.m in Sources */,
|
||||
|
@@ -40,7 +40,12 @@
|
||||
[[NIMSDK sharedSDK] registerWithOption:option];
|
||||
|
||||
// NIM SDK初始化
|
||||
[NIMCustomObject registerCustomDecoder:[[CustomAttachmentDecoder alloc] init]];
|
||||
[NIMCustomObject registerCustomDecoder:[[CustomAttachmentDecoder alloc] init]];
|
||||
|
||||
#ifdef DEBUG
|
||||
[NIMSDKConfig sharedConfig].enabledHttpsForInfo = NO;
|
||||
[NIMSDKConfig sharedConfig].enabledHttpsForMessage = NO;
|
||||
#endif
|
||||
}
|
||||
|
||||
@end
|
||||
|
@@ -96,8 +96,6 @@
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
</array>
|
||||
<key>UIUserInterfaceStyle</key>
|
||||
<string>Light</string>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<false/>
|
||||
</dict>
|
||||
|
18
xplan-ios/Main/Message/NIMBadgeView.h
Normal file
18
xplan-ios/Main/Message/NIMBadgeView.h
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// NIMBadgeView.h
|
||||
// NIMKit
|
||||
//
|
||||
// Created by chris on 15/2/12.
|
||||
// Copyright (c) 2015年 Netease. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface NIMBadgeView : UIView
|
||||
|
||||
@property (nonatomic, copy) NSString *badgeValue;
|
||||
|
||||
+ (instancetype)viewWithBadgeTip:(NSString *)badgeValue;
|
||||
|
||||
|
||||
@end
|
167
xplan-ios/Main/Message/NIMBadgeView.m
Normal file
167
xplan-ios/Main/Message/NIMBadgeView.m
Normal file
@@ -0,0 +1,167 @@
|
||||
//
|
||||
// NIMBadgeView.m
|
||||
// NIMKit
|
||||
//
|
||||
// Created by chris on 15/2/12.
|
||||
// Copyright (c) 2015年 Netease. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#import "NIMBadgeView.h"
|
||||
|
||||
@interface NIMBadgeView ()
|
||||
|
||||
@property (strong) UIColor *badgeBackgroundColor;
|
||||
|
||||
@property (strong) UIColor *borderColor;
|
||||
|
||||
@property (strong) UIColor *badgeTextColor;
|
||||
|
||||
@property (nonatomic) UIFont *badgeTextFont;
|
||||
|
||||
@property (nonatomic) CGFloat badgeTopPadding; //数字顶部到红圈的距离
|
||||
|
||||
@property (nonatomic) CGFloat badgeLeftPadding; //数字左部到红圈的距离
|
||||
|
||||
@property (nonatomic) CGFloat whiteCircleWidth; //最外层白圈的宽度
|
||||
|
||||
@end
|
||||
|
||||
@implementation NIMBadgeView
|
||||
|
||||
+ (instancetype)viewWithBadgeTip:(NSString *)badgeValue{
|
||||
if (!badgeValue) {
|
||||
badgeValue = @"";
|
||||
}
|
||||
NIMBadgeView *instance = [[NIMBadgeView alloc] init];
|
||||
instance.frame = [instance frameWithStr:badgeValue];
|
||||
instance.badgeValue = badgeValue;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
// 0xFF5B55
|
||||
_badgeBackgroundColor = [UIColor colorWithRed:((float)((0xFF5B55 & 0xFF0000) >> 16))/255.0 green:((float)((0xFF5B55 & 0xFF00) >> 8))/255.0 blue:((float)(0xFF5B55 & 0xFF))/255.0 alpha:1.0];
|
||||
_borderColor = [UIColor colorWithRed:((float)((0xFF5B55 & 0xFF0000) >> 16))/255.0 green:((float)((0xFF5B55 & 0xFF00) >> 8))/255.0 blue:((float)(0xFF5B55 & 0xFF))/255.0 alpha:1.0];
|
||||
_badgeTextColor = [UIColor whiteColor];
|
||||
_badgeTextFont = [UIFont boldSystemFontOfSize:11];
|
||||
_whiteCircleWidth = 0.f;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)drawRect:(CGRect)rect
|
||||
{
|
||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||
CGContextSaveGState(context);
|
||||
if ([[self badgeValue] length]) {
|
||||
[self drawWithContent:rect context:context];
|
||||
}else{
|
||||
[self drawWithOutContent:rect context:context];
|
||||
}
|
||||
CGContextRestoreGState(context);
|
||||
}
|
||||
|
||||
- (void)setBadgeValue:(NSString *)badgeValue {
|
||||
_badgeValue = badgeValue;
|
||||
if (_badgeValue.integerValue > 9) {
|
||||
_badgeLeftPadding = 6.f;
|
||||
}else{
|
||||
_badgeLeftPadding = 2.f;
|
||||
}
|
||||
_badgeTopPadding = 2.f;
|
||||
|
||||
self.frame = [self frameWithStr:badgeValue];
|
||||
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
|
||||
- (CGSize)badgeSizeWithStr:(NSString *)badgeValue{
|
||||
if (!badgeValue || badgeValue.length == 0) {
|
||||
return CGSizeZero;
|
||||
}
|
||||
CGSize size = [badgeValue sizeWithAttributes:@{NSFontAttributeName:self.badgeTextFont}];
|
||||
if (size.width < size.height) {
|
||||
size = CGSizeMake(size.height, size.height);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
- (CGRect)frameWithStr:(NSString *)badgeValue{
|
||||
CGSize badgeSize = [self badgeSizeWithStr:badgeValue];
|
||||
CGRect badgeFrame = CGRectMake(self.frame.origin.x, self.frame.origin.y, badgeSize.width + self.badgeLeftPadding * 2 + self.whiteCircleWidth * 2, badgeSize.height + self.badgeTopPadding * 2 + self.whiteCircleWidth * 2);//8=2*2(红圈-文字)+2*2(白圈-红圈)
|
||||
return badgeFrame;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#pragma mark - Private
|
||||
- (void)drawWithContent:(CGRect)rect context:(CGContextRef)context{
|
||||
CGRect bodyFrame = self.bounds;
|
||||
CGRect bkgFrame = CGRectInset(self.bounds, self.whiteCircleWidth, self.whiteCircleWidth);
|
||||
CGRect badgeSize = CGRectInset(self.bounds, self.whiteCircleWidth + self.badgeLeftPadding, self.whiteCircleWidth + self.badgeTopPadding);
|
||||
if ([self badgeBackgroundColor]) {//外白色描边
|
||||
CGContextSetFillColorWithColor(context, [self.borderColor CGColor]);
|
||||
if ([self badgeValue].integerValue > 9) {
|
||||
CGFloat circleWith = bodyFrame.size.height;
|
||||
CGFloat totalWidth = bodyFrame.size.width;
|
||||
CGFloat diffWidth = totalWidth - circleWith;
|
||||
CGPoint originPoint = bodyFrame.origin;
|
||||
CGRect leftCicleFrame = CGRectMake(originPoint.x, originPoint.y, circleWith, circleWith);
|
||||
CGRect centerFrame = CGRectMake(originPoint.x +circleWith/2, originPoint.y, diffWidth, circleWith);
|
||||
CGRect rightCicleFrame = CGRectMake(originPoint.x +(totalWidth - circleWith), originPoint.y, circleWith, circleWith);
|
||||
CGContextFillEllipseInRect(context, leftCicleFrame);
|
||||
CGContextFillRect(context, centerFrame);
|
||||
CGContextFillEllipseInRect(context, rightCicleFrame);
|
||||
|
||||
}else{
|
||||
CGContextFillEllipseInRect(context, bodyFrame);
|
||||
}
|
||||
// badge背景色
|
||||
CGContextSetFillColorWithColor(context, [[self badgeBackgroundColor] CGColor]);
|
||||
if ([self badgeValue].integerValue > 9) {
|
||||
CGFloat circleWith = bkgFrame.size.height;
|
||||
CGFloat totalWidth = bkgFrame.size.width;
|
||||
CGFloat diffWidth = totalWidth - circleWith;
|
||||
CGPoint originPoint = bkgFrame.origin;
|
||||
CGRect leftCicleFrame = CGRectMake(originPoint.x, originPoint.y, circleWith, circleWith);
|
||||
CGRect centerFrame = CGRectMake(originPoint.x +circleWith/2, originPoint.y, diffWidth, circleWith);
|
||||
CGRect rightCicleFrame = CGRectMake(originPoint.x +(totalWidth - circleWith), originPoint.y, circleWith, circleWith);
|
||||
CGContextFillEllipseInRect(context, leftCicleFrame);
|
||||
CGContextFillRect(context, centerFrame);
|
||||
CGContextFillEllipseInRect(context, rightCicleFrame);
|
||||
}else{
|
||||
CGContextFillEllipseInRect(context, bkgFrame);
|
||||
}
|
||||
}
|
||||
|
||||
CGContextSetFillColorWithColor(context, [[self badgeTextColor] CGColor]);
|
||||
NSMutableParagraphStyle *badgeTextStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
|
||||
[badgeTextStyle setLineBreakMode:NSLineBreakByWordWrapping];
|
||||
[badgeTextStyle setAlignment:NSTextAlignmentCenter];
|
||||
|
||||
|
||||
NSDictionary *badgeTextAttributes = @{
|
||||
NSFontAttributeName: [self badgeTextFont],
|
||||
NSForegroundColorAttributeName: [self badgeTextColor],
|
||||
NSParagraphStyleAttributeName: badgeTextStyle,
|
||||
};
|
||||
[[self badgeValue] drawInRect:CGRectMake(self.whiteCircleWidth + self.badgeLeftPadding,
|
||||
self.whiteCircleWidth + self.badgeTopPadding,
|
||||
badgeSize.size.width, badgeSize.size.height)
|
||||
withAttributes:badgeTextAttributes];
|
||||
}
|
||||
|
||||
|
||||
- (void)drawWithOutContent:(CGRect)rect context:(CGContextRef)context{
|
||||
CGRect bodyFrame = self.bounds;
|
||||
CGContextSetFillColorWithColor(context, [[UIColor redColor] CGColor]);
|
||||
CGContextFillEllipseInRect(context, bodyFrame);
|
||||
}
|
||||
|
||||
@end
|
19
xplan-ios/Main/Message/NIMMessageUtils.h
Normal file
19
xplan-ios/Main/Message/NIMMessageUtils.h
Normal file
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// NIMMessageUtils.h
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by zu on 2021/11/26.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <NIMSDK/NIMSDK.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface NIMMessageUtils : NSObject
|
||||
|
||||
+ (NSString *)messageContent:(NIMMessage*)message;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
46
xplan-ios/Main/Message/NIMMessageUtils.m
Normal file
46
xplan-ios/Main/Message/NIMMessageUtils.m
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// NIMMessageUtils.m
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by zu on 2021/11/26.
|
||||
//
|
||||
|
||||
#import "NIMMessageUtils.h"
|
||||
|
||||
@implementation NIMMessageUtils
|
||||
|
||||
+ (NSString *)messageContent:(NIMMessage*)message {
|
||||
NSString *text = @"";
|
||||
switch (message.messageType) {
|
||||
case NIMMessageTypeText:
|
||||
text = message.text;
|
||||
break;
|
||||
case NIMMessageTypeAudio:
|
||||
text = @"[语音]";
|
||||
break;
|
||||
case NIMMessageTypeImage:
|
||||
text = @"[图片]";
|
||||
break;
|
||||
case NIMMessageTypeVideo:
|
||||
text = @"[视频]";
|
||||
break;
|
||||
case NIMMessageTypeLocation:
|
||||
text = @"[位置]";
|
||||
break;
|
||||
case NIMMessageTypeFile:
|
||||
text = @"[文件]";
|
||||
break;
|
||||
case NIMMessageTypeTip:
|
||||
text = message.text;
|
||||
break;
|
||||
case NIMMessageTypeCustom:
|
||||
text = message.text;
|
||||
break;
|
||||
default:
|
||||
text = @"[未知消息]";
|
||||
break;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
@end
|
18
xplan-ios/Main/Message/NIMTimeUtils.h
Normal file
18
xplan-ios/Main/Message/NIMTimeUtils.h
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// NIMTimeUtils.h
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by zu on 2021/11/26.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface NIMTimeUtils : NSObject
|
||||
|
||||
+ (NSString *)showTime:(NSTimeInterval)msglastTime showDetail:(BOOL)showDetail;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
96
xplan-ios/Main/Message/NIMTimeUtils.m
Normal file
96
xplan-ios/Main/Message/NIMTimeUtils.m
Normal file
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// NIMTimeUtils.m
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by zu on 2021/11/26.
|
||||
//
|
||||
|
||||
#import "NIMTimeUtils.h"
|
||||
|
||||
@implementation NIMTimeUtils
|
||||
|
||||
+ (NSString*)showTime:(NSTimeInterval) msglastTime showDetail:(BOOL)showDetail
|
||||
{
|
||||
//今天的时间
|
||||
NSDate * nowDate = [NSDate date];
|
||||
NSDate * msgDate = [NSDate dateWithTimeIntervalSince1970:msglastTime];
|
||||
NSString *result = nil;
|
||||
NSCalendarUnit components = (NSCalendarUnit)(NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitWeekday|NSCalendarUnitHour | NSCalendarUnitMinute);
|
||||
NSDateComponents *nowDateComponents = [[NSCalendar currentCalendar] components:components fromDate:nowDate];
|
||||
NSDateComponents *msgDateComponents = [[NSCalendar currentCalendar] components:components fromDate:msgDate];
|
||||
|
||||
NSInteger hour = msgDateComponents.hour;
|
||||
double OnedayTimeIntervalValue = 24*60*60; //一天的秒数
|
||||
|
||||
result = [self getPeriodOfTime:hour withMinute:msgDateComponents.minute];
|
||||
if (hour > 12)
|
||||
{
|
||||
hour = hour - 12;
|
||||
}
|
||||
|
||||
BOOL isSameMonth = (nowDateComponents.year == msgDateComponents.year) && (nowDateComponents.month == msgDateComponents.month);
|
||||
|
||||
if(isSameMonth && (nowDateComponents.day == msgDateComponents.day)) //同一天,显示时间
|
||||
{
|
||||
result = [[NSString alloc] initWithFormat:@"%@ %zd:%02d",result,hour,(int)msgDateComponents.minute];
|
||||
}
|
||||
else if(isSameMonth && (nowDateComponents.day == (msgDateComponents.day+1)))//昨天
|
||||
{
|
||||
result = showDetail? [[NSString alloc] initWithFormat:@"昨天%@ %zd:%02d",result,hour,(int)msgDateComponents.minute] : @"昨天";
|
||||
}
|
||||
else if(isSameMonth && (nowDateComponents.day == (msgDateComponents.day+2))) //前天
|
||||
{
|
||||
result = showDetail? [[NSString alloc] initWithFormat:@"前天%@ %zd:%02d",result,hour,(int)msgDateComponents.minute] : @"前天";
|
||||
}
|
||||
else if([nowDate timeIntervalSinceDate:msgDate] < 7 * OnedayTimeIntervalValue)//一周内
|
||||
{
|
||||
NSString *weekDay = [self weekdayStr:msgDateComponents.weekday];
|
||||
result = showDetail? [weekDay stringByAppendingFormat:@"%@ %zd:%02d",result,hour,(int)msgDateComponents.minute] : weekDay;
|
||||
}
|
||||
else//显示日期
|
||||
{
|
||||
NSString *day = [NSString stringWithFormat:@"%zd-%zd-%zd", msgDateComponents.year, msgDateComponents.month, msgDateComponents.day];
|
||||
result = showDetail? [day stringByAppendingFormat:@"%@ %zd:%02d",result,hour,(int)msgDateComponents.minute]:day;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
+ (NSString *)getPeriodOfTime:(NSInteger)time withMinute:(NSInteger)minute
|
||||
{
|
||||
NSInteger totalMin = time *60 + minute;
|
||||
NSString *showPeriodOfTime = @"";
|
||||
if (totalMin > 0 && totalMin <= 5 * 60)
|
||||
{
|
||||
showPeriodOfTime = @"凌晨";
|
||||
}
|
||||
else if (totalMin > 5 * 60 && totalMin < 12 * 60)
|
||||
{
|
||||
showPeriodOfTime = @"上午";
|
||||
}
|
||||
else if (totalMin >= 12 * 60 && totalMin <= 18 * 60)
|
||||
{
|
||||
showPeriodOfTime = @"下午";
|
||||
}
|
||||
else if ((totalMin > 18 * 60 && totalMin <= (23 * 60 + 59)) || totalMin == 0)
|
||||
{
|
||||
showPeriodOfTime = @"晚上";
|
||||
}
|
||||
return showPeriodOfTime;
|
||||
}
|
||||
|
||||
+(NSString*)weekdayStr:(NSInteger)dayOfWeek
|
||||
{
|
||||
static NSDictionary *daysOfWeekDict = nil;
|
||||
daysOfWeekDict = @{@(1):@"星期日",
|
||||
@(2):@"星期一",
|
||||
@(3):@"星期二",
|
||||
@(4):@"星期三",
|
||||
@(5):@"星期四",
|
||||
@(6):@"星期五",
|
||||
@(7):@"星期六",};
|
||||
return [daysOfWeekDict objectForKey:@(dayOfWeek)];
|
||||
}
|
||||
|
||||
@end
|
19
xplan-ios/Main/Message/SessionListCell.h
Normal file
19
xplan-ios/Main/Message/SessionListCell.h
Normal file
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// SessionListCell.h
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by zu on 2021/11/26.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <NIMSDK/NIMSDK.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SessionListCell : UITableViewCell
|
||||
|
||||
- (void)renderWithSession:(NIMRecentSession*)recent;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
173
xplan-ios/Main/Message/SessionListCell.m
Normal file
173
xplan-ios/Main/Message/SessionListCell.m
Normal file
@@ -0,0 +1,173 @@
|
||||
//
|
||||
// SessionListCell.m
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by zu on 2021/11/26.
|
||||
//
|
||||
|
||||
#import "SessionListCell.h"
|
||||
#import "NIMBadgeView.h"
|
||||
#import "NetImageView.h"
|
||||
#import "NIMMessageUtils.h"
|
||||
#import "NIMTimeUtils.h"
|
||||
#import "UIView+NIM.h"
|
||||
|
||||
#import "ThemeColor.h"
|
||||
|
||||
#import <Masonry/Masonry.h>
|
||||
|
||||
@interface SessionListCell()
|
||||
|
||||
@property (nonatomic,strong) NetImageView *avatarImageView;
|
||||
|
||||
@property (nonatomic,strong) UILabel *nameLabel;
|
||||
|
||||
@property (nonatomic,strong) UILabel *messageLabel;
|
||||
|
||||
@property (nonatomic,strong) UILabel *timeLabel;
|
||||
|
||||
@property (nonatomic,strong) NIMBadgeView *badgeView;
|
||||
|
||||
@property (nonatomic,strong) UIView *divider;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SessionListCell
|
||||
|
||||
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nullable NSString *)reuseIdentifier {
|
||||
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
|
||||
if (self) {
|
||||
self.backgroundColor = UIColor.clearColor;
|
||||
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||
[self initView];
|
||||
[self initLayout];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)renderWithSession:(NIMRecentSession *)recent {
|
||||
NIMUser *user = [[NIMSDK sharedSDK].userManager userInfo:recent.lastMessage.from];
|
||||
NSString *avatarUrl = user.userInfo.avatarUrl;
|
||||
self.avatarImageView.imageUrl = avatarUrl;
|
||||
self.nameLabel.text = user.userInfo.nickName;
|
||||
[self.nameLabel sizeToFit];
|
||||
self.messageLabel.text = [NIMMessageUtils messageContent:recent.lastMessage];
|
||||
[self.messageLabel sizeToFit];
|
||||
if (recent.lastMessage) {
|
||||
self.timeLabel.text = [NIMTimeUtils showTime:recent.lastMessage.timestamp showDetail:NO];
|
||||
} else {
|
||||
NSTimeInterval timeSecond = recent.updateTime / 1000.0;
|
||||
self.timeLabel.text = [NIMTimeUtils showTime:timeSecond showDetail:NO];
|
||||
}
|
||||
[self.timeLabel sizeToFit];
|
||||
if (recent.unreadCount) {
|
||||
self.badgeView.hidden = NO;
|
||||
self.badgeView.badgeValue = @(recent.unreadCount).stringValue;
|
||||
} else {
|
||||
self.badgeView.hidden = NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)initView {
|
||||
[self.contentView addSubview:self.avatarImageView];
|
||||
[self.contentView addSubview:self.nameLabel];
|
||||
[self.contentView addSubview:self.messageLabel];
|
||||
[self.contentView addSubview:self.timeLabel];
|
||||
[self.contentView addSubview:self.badgeView];
|
||||
[self.contentView addSubview:self.divider];
|
||||
}
|
||||
|
||||
- (void)initLayout {
|
||||
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.offset(20);
|
||||
make.left.mas_offset(15);
|
||||
make.height.width.mas_equalTo(45);
|
||||
}];
|
||||
|
||||
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_offset(26);
|
||||
make.left.mas_equalTo(self.avatarImageView.mas_right).offset(15);
|
||||
}];
|
||||
|
||||
[self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.nameLabel);
|
||||
make.bottom.mas_equalTo(self).offset(-15);
|
||||
}];
|
||||
|
||||
[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.mas_equalTo(self).offset(-15);
|
||||
make.right.mas_equalTo(self).offset(-15);
|
||||
}];
|
||||
|
||||
[self.divider mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.offset(-15);
|
||||
make.left.mas_equalTo(self.nameLabel);
|
||||
make.bottom.mas_equalTo(self);
|
||||
make.height.mas_equalTo(0.5f);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
self.badgeView.nim_right = self.nim_width - 15;
|
||||
self.badgeView.nim_top = 26;
|
||||
}
|
||||
|
||||
- (NetImageView *)avatarImageView {
|
||||
if (!_avatarImageView) {
|
||||
NetImageConfig *config = [[NetImageConfig alloc]init];
|
||||
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
||||
config.radius = CGFLOAT_MAX;
|
||||
_avatarImageView = [[NetImageView alloc] initWithConfig:config];
|
||||
_avatarImageView.layer.masksToBounds = YES;
|
||||
_avatarImageView.layer.cornerRadius = 45.f / 2;
|
||||
}
|
||||
return _avatarImageView;
|
||||
}
|
||||
|
||||
- (UILabel *)nameLabel {
|
||||
if (!_nameLabel) {
|
||||
_nameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||
_nameLabel.backgroundColor = [UIColor clearColor];
|
||||
_nameLabel.font = [UIFont systemFontOfSize:15.f weight:UIFontWeightMedium];
|
||||
_nameLabel.textColor = ThemeColor.mainTextColor;
|
||||
}
|
||||
return _nameLabel;
|
||||
}
|
||||
|
||||
- (UILabel *)messageLabel {
|
||||
if (!_messageLabel) {
|
||||
_messageLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||
_messageLabel.backgroundColor = [UIColor clearColor];
|
||||
_messageLabel.font = [UIFont systemFontOfSize:13.f];
|
||||
_messageLabel.textColor = ThemeColor.secondTextColor;
|
||||
}
|
||||
return _messageLabel;
|
||||
}
|
||||
|
||||
- (UILabel *)timeLabel {
|
||||
if (!_timeLabel) {
|
||||
_timeLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||
_timeLabel.backgroundColor = [UIColor clearColor];
|
||||
_timeLabel.font = [UIFont systemFontOfSize:12.f weight:UIFontWeightLight];
|
||||
_timeLabel.textColor = ThemeColor.textThirdColor;
|
||||
}
|
||||
return _timeLabel;
|
||||
}
|
||||
|
||||
- (NIMBadgeView *)badgeView {
|
||||
if (!_badgeView) {
|
||||
_badgeView = [NIMBadgeView viewWithBadgeTip:@""];
|
||||
}
|
||||
return _badgeView;
|
||||
}
|
||||
|
||||
- (UIView *)divider {
|
||||
if (!_divider) {
|
||||
_divider = [[UIView alloc]init];
|
||||
_divider.backgroundColor = UIColorFromRGB(0x353548);
|
||||
}
|
||||
return _divider;
|
||||
}
|
||||
|
||||
@end
|
20
xplan-ios/Main/Message/SessionListViewController.h
Normal file
20
xplan-ios/Main/Message/SessionListViewController.h
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// SessionListViewController.h
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by zu on 2021/11/25.
|
||||
//
|
||||
// 请注意,这是一次冒险。
|
||||
//
|
||||
|
||||
#import "BaseViewController.h"
|
||||
|
||||
#import <NIMSDK/NIMSDK.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SessionListViewController : BaseViewController
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
234
xplan-ios/Main/Message/SessionListViewController.m
Normal file
234
xplan-ios/Main/Message/SessionListViewController.m
Normal file
@@ -0,0 +1,234 @@
|
||||
//
|
||||
// SessionListViewController.m
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by zu on 2021/11/25.
|
||||
//
|
||||
|
||||
#import "SessionListViewController.h"
|
||||
#import "SessionListCell.h"
|
||||
#import "ThemeColor.h"
|
||||
#import "XPMacro.h"
|
||||
|
||||
#import <Masonry/Masonry.h>
|
||||
|
||||
@interface SessionListViewController ()<UITableViewDataSource, UITableViewDelegate, NIMLoginManagerDelegate, NIMConversationManagerDelegate>
|
||||
|
||||
@property (nonatomic,strong) UIView *customNavigationBar;
|
||||
|
||||
@property (nonatomic,strong) UILabel *titleLabel;
|
||||
|
||||
/**
|
||||
* 会话列表
|
||||
*/
|
||||
@property (nonatomic,strong) UITableView *sessionListView;
|
||||
|
||||
/**
|
||||
* 最近会话集合
|
||||
*/
|
||||
@property (nonatomic,strong) NSMutableArray<NIMRecentSession *> *recentSessions;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SessionListViewController
|
||||
|
||||
- (void)dealloc {
|
||||
[[NIMSDK sharedSDK].conversationManager removeDelegate:self];
|
||||
[[NIMSDK sharedSDK].loginManager removeDelegate:self];
|
||||
}
|
||||
|
||||
- (BOOL)isHiddenNavBar {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
[self initViews];
|
||||
[self initLayout];
|
||||
[self initDatas];
|
||||
|
||||
[[NIMSDK sharedSDK].conversationManager addDelegate:self];
|
||||
[[NIMSDK sharedSDK].loginManager addDelegate:self];
|
||||
}
|
||||
|
||||
- (void)initViews {
|
||||
[self.customNavigationBar addSubview:self.titleLabel];
|
||||
[self.view addSubview:self.customNavigationBar];
|
||||
[self.view addSubview:self.sessionListView];
|
||||
}
|
||||
|
||||
- (void)initLayout {
|
||||
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.center.mas_equalTo(self.customNavigationBar);
|
||||
}];
|
||||
|
||||
[self.sessionListView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.right.bottom.mas_equalTo(self.view);
|
||||
make.top.mas_equalTo(self.customNavigationBar.mas_bottom);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)initDatas {
|
||||
_recentSessions = [[NIMSDK sharedSDK].conversationManager.allRecentSessions mutableCopy];
|
||||
if (!self.recentSessions.count) _recentSessions = [NSMutableArray array];
|
||||
NSMutableArray<NSString *> * uids = [[NSMutableArray alloc] init];
|
||||
[self.recentSessions enumerateObjectsUsingBlock:^(NIMRecentSession * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
[uids addObject:obj.session.sessionId];
|
||||
}];
|
||||
[[NIMSDK sharedSDK].userManager fetchUserInfos:uids completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
|
||||
[self.sessionListView reloadData];
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - UITableViewDelegate
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
||||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
// TODO: 打开私聊
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||||
return 75.f;
|
||||
}
|
||||
|
||||
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return YES;
|
||||
}
|
||||
|
||||
#pragma mark - UITableViewDataSource
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
||||
return self.recentSessions.count;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||||
static NSString * cellId = @"cellId";
|
||||
SessionListCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId];
|
||||
if (!cell) {
|
||||
cell = [[SessionListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
|
||||
}
|
||||
NIMRecentSession *recent = self.recentSessions[indexPath.row];
|
||||
[cell renderWithSession:recent];
|
||||
return cell;
|
||||
}
|
||||
|
||||
#pragma mark - NIMConversationManagerDelegate
|
||||
- (void)didLoadAllRecentSessionCompletion {
|
||||
[self initDatas];
|
||||
[self.sessionListView reloadData];
|
||||
}
|
||||
|
||||
- (void)didAddRecentSession:(NIMRecentSession *)recentSession
|
||||
totalUnreadCount:(NSInteger)totalUnreadCount {
|
||||
[self.recentSessions addObject:recentSession];
|
||||
[self.recentSessions sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
|
||||
NIMRecentSession *item1 = obj1;
|
||||
NIMRecentSession *item2 = obj2;
|
||||
if (item1.lastMessage.timestamp < item2.lastMessage.timestamp) {
|
||||
return NSOrderedDescending;
|
||||
}
|
||||
if (item1.lastMessage.timestamp > item2.lastMessage.timestamp) {
|
||||
return NSOrderedAscending;
|
||||
}
|
||||
return NSOrderedSame;
|
||||
}];
|
||||
[self.sessionListView reloadData];
|
||||
}
|
||||
|
||||
- (void)didUpdateRecentSession:(NIMRecentSession *)recentSession
|
||||
totalUnreadCount:(NSInteger)totalUnreadCount {
|
||||
for (NIMRecentSession *recent in self.recentSessions) {
|
||||
if ([recentSession.session.sessionId isEqualToString:recent.session.sessionId]) {
|
||||
[self.recentSessions removeObject:recent];
|
||||
break;
|
||||
}
|
||||
}
|
||||
NSInteger insert = [self findInsertPlace:recentSession];
|
||||
[self.recentSessions insertObject:recentSession atIndex:insert];
|
||||
[self.sessionListView reloadData];
|
||||
}
|
||||
|
||||
- (void)didRemoveRecentSession:(NIMRecentSession *)recentSession
|
||||
totalUnreadCount:(NSInteger)totalUnreadCount {
|
||||
// 清理本地数据
|
||||
NSUInteger index = [self.recentSessions indexOfObject:recentSession];
|
||||
[self.recentSessions removeObjectAtIndex:index];
|
||||
|
||||
// 如果删除本地会话后就不允许漫游当前会话,则需要进行一次删除服务器会话的操作
|
||||
BOOL deleteRemote = NO;
|
||||
if (deleteRemote) {
|
||||
[[NIMSDK sharedSDK].conversationManager deleteRemoteSessions:@[recentSession.session]
|
||||
completion:nil];
|
||||
}
|
||||
[self.sessionListView reloadData];
|
||||
}
|
||||
|
||||
#pragma mark - NIMLoginManagerDelegate
|
||||
- (void)onLogin:(NIMLoginStep)step {
|
||||
if (step == NIMLoginStepSyncOK) {
|
||||
[self.sessionListView reloadData];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
- (NSInteger)findInsertPlace:(NIMRecentSession *)recentSession{
|
||||
__block NSUInteger matchIdx = 0;
|
||||
__block BOOL find = NO;
|
||||
[self.recentSessions enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||
NIMRecentSession *item = obj;
|
||||
if (item.lastMessage.timestamp <= recentSession.lastMessage.timestamp) {
|
||||
*stop = YES;
|
||||
find = YES;
|
||||
matchIdx = idx;
|
||||
}
|
||||
}];
|
||||
if (find) {
|
||||
return matchIdx;
|
||||
} else {
|
||||
return self.recentSessions.count;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)sort{
|
||||
[self.recentSessions sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
|
||||
NIMRecentSession *item1 = obj1;
|
||||
NIMRecentSession *item2 = obj2;
|
||||
if (item1.lastMessage.timestamp < item2.lastMessage.timestamp) {
|
||||
return NSOrderedDescending;
|
||||
}
|
||||
if (item1.lastMessage.timestamp > item2.lastMessage.timestamp) {
|
||||
return NSOrderedAscending;
|
||||
}
|
||||
return NSOrderedSame;
|
||||
}];
|
||||
}
|
||||
|
||||
- (UIView *)customNavigationBar {
|
||||
if (!_customNavigationBar) {
|
||||
CGRect frame = CGRectMake(0, kStatusBarHeight, KScreenWidth, 44);
|
||||
_customNavigationBar = [[UIView alloc]initWithFrame:frame];
|
||||
}
|
||||
return _customNavigationBar;
|
||||
}
|
||||
|
||||
- (UILabel *)titleLabel {
|
||||
if (!_titleLabel) {
|
||||
_titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||
_titleLabel.backgroundColor = [UIColor clearColor];
|
||||
_titleLabel.font = [UIFont systemFontOfSize:18.f weight:UIFontWeightMedium];
|
||||
_titleLabel.textColor = ThemeColor.mainTextColor;
|
||||
_titleLabel.text = @"消息";
|
||||
}
|
||||
return _titleLabel;
|
||||
}
|
||||
|
||||
- (UITableView *)sessionListView {
|
||||
if (!_sessionListView) {
|
||||
_sessionListView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
||||
_sessionListView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||||
_sessionListView.backgroundColor = UIColor.clearColor;
|
||||
_sessionListView.delegate = self;
|
||||
_sessionListView.dataSource = self;
|
||||
}
|
||||
return _sessionListView;
|
||||
}
|
||||
|
||||
@end
|
78
xplan-ios/Main/Message/UIView+NIM.h
Normal file
78
xplan-ios/Main/Message/UIView+NIM.h
Normal file
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// UIView+NIM.h
|
||||
// NIMKit
|
||||
//
|
||||
// Created by chris.
|
||||
// Copyright (c) 2015年 NetEase. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface UIView (NIMKit)
|
||||
|
||||
@property (nonatomic) CGFloat nim_left;
|
||||
|
||||
/**
|
||||
* Shortcut for frame.origin.y
|
||||
*
|
||||
* Sets frame.origin.y = top
|
||||
*/
|
||||
@property (nonatomic) CGFloat nim_top;
|
||||
|
||||
/**
|
||||
* Shortcut for frame.origin.x + frame.size.width
|
||||
*
|
||||
* Sets frame.origin.x = right - frame.size.width
|
||||
*/
|
||||
@property (nonatomic) CGFloat nim_right;
|
||||
|
||||
/**
|
||||
* Shortcut for frame.origin.y + frame.size.height
|
||||
*
|
||||
* Sets frame.origin.y = bottom - frame.size.height
|
||||
*/
|
||||
@property (nonatomic) CGFloat nim_bottom;
|
||||
|
||||
/**
|
||||
* Shortcut for frame.size.width
|
||||
*
|
||||
* Sets frame.size.width = width
|
||||
*/
|
||||
@property (nonatomic) CGFloat nim_width;
|
||||
|
||||
/**
|
||||
* Shortcut for frame.size.height
|
||||
*
|
||||
* Sets frame.size.height = height
|
||||
*/
|
||||
@property (nonatomic) CGFloat nim_height;
|
||||
|
||||
/**
|
||||
* Shortcut for center.x
|
||||
*
|
||||
* Sets center.x = centerX
|
||||
*/
|
||||
@property (nonatomic) CGFloat nim_centerX;
|
||||
|
||||
/**
|
||||
* Shortcut for center.y
|
||||
*
|
||||
* Sets center.y = centerY
|
||||
*/
|
||||
@property (nonatomic) CGFloat nim_centerY;
|
||||
/**
|
||||
* Shortcut for frame.origin
|
||||
*/
|
||||
@property (nonatomic) CGPoint nim_origin;
|
||||
|
||||
/**
|
||||
* Shortcut for frame.size
|
||||
*/
|
||||
@property (nonatomic) CGSize nim_size;
|
||||
|
||||
//找到自己的vc
|
||||
- (UIViewController *)nim_viewController;
|
||||
|
||||
|
||||
|
||||
@end
|
156
xplan-ios/Main/Message/UIView+NIM.m
Normal file
156
xplan-ios/Main/Message/UIView+NIM.m
Normal file
@@ -0,0 +1,156 @@
|
||||
//
|
||||
// UIView+NIM.m
|
||||
// NIMKit
|
||||
//
|
||||
// Created by chris.
|
||||
// Copyright (c) 2015年 NetEase. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UIView+NIM.h"
|
||||
|
||||
@implementation UIView (NIMKit)
|
||||
|
||||
- (CGFloat)nim_left {
|
||||
return self.frame.origin.x;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (void)setNim_left:(CGFloat)x {
|
||||
CGRect frame = self.frame;
|
||||
frame.origin.x = x;
|
||||
self.frame = frame;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (CGFloat)nim_top {
|
||||
return self.frame.origin.y;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (void)setNim_top:(CGFloat)y {
|
||||
CGRect frame = self.frame;
|
||||
frame.origin.y = y;
|
||||
self.frame = frame;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (CGFloat)nim_right {
|
||||
return self.frame.origin.x + self.frame.size.width;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (void)setNim_right:(CGFloat)right {
|
||||
CGRect frame = self.frame;
|
||||
frame.origin.x = right - frame.size.width;
|
||||
self.frame = frame;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (CGFloat)nim_bottom {
|
||||
return self.frame.origin.y + self.frame.size.height;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (void)setNim_bottom:(CGFloat)bottom {
|
||||
CGRect frame = self.frame;
|
||||
frame.origin.y = bottom - frame.size.height;
|
||||
self.frame = frame;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (CGFloat)nim_centerX {
|
||||
return self.center.x;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (void)setNim_centerX:(CGFloat)centerX {
|
||||
self.center = CGPointMake(centerX, self.center.y);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (CGFloat)nim_centerY {
|
||||
return self.center.y;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (void)setNim_centerY:(CGFloat)centerY {
|
||||
self.center = CGPointMake(self.center.x, centerY);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (CGFloat)nim_width {
|
||||
return self.frame.size.width;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (void)setNim_width:(CGFloat)width {
|
||||
CGRect frame = self.frame;
|
||||
frame.size.width = width;
|
||||
self.frame = frame;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (CGFloat)nim_height {
|
||||
return self.frame.size.height;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (void)setNim_height:(CGFloat)height {
|
||||
CGRect frame = self.frame;
|
||||
frame.size.height = height;
|
||||
self.frame = frame;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (CGPoint)nim_origin {
|
||||
return self.frame.origin;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (void)setNim_origin:(CGPoint)origin {
|
||||
CGRect frame = self.frame;
|
||||
frame.origin = origin;
|
||||
self.frame = frame;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (CGSize)nim_size {
|
||||
return self.frame.size;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (void)setNim_size:(CGSize)size {
|
||||
CGRect frame = self.frame;
|
||||
frame.size = size;
|
||||
self.frame = frame;
|
||||
}
|
||||
|
||||
|
||||
- (UIViewController *)nim_viewController{
|
||||
for (UIView* next = self; next; next = next.superview) {
|
||||
UIResponder* nextResponder = [next nextResponder];
|
||||
if ([nextResponder isKindOfClass:[UIViewController class]]) {
|
||||
return (UIViewController*)nextResponder;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
@@ -26,6 +26,7 @@
|
||||
#import "LoginFullInfoViewController.h"
|
||||
#import "XplanFBFlutterViewContainer.h"
|
||||
#import "XPMineViewController.h"
|
||||
#import "SessionListViewController.h"
|
||||
///Present
|
||||
#import "MainPresenter.h"
|
||||
#import "MainProtocol.h"
|
||||
@@ -139,11 +140,12 @@
|
||||
}
|
||||
|
||||
- (void)initTabs:(BOOL)logined {
|
||||
NSArray *normalImageNames = @[@"tab_game_normal", @"tab_mine_normal"];
|
||||
NSArray *selectImageNames = @[@"tab_game_selected", @"tab_mine_selected"];
|
||||
NSArray *tabLabel = @[@"赛事", @"我的"];
|
||||
NSArray *normalImageNames = @[@"tab_game_normal", @"tab_message_normal", @"tab_mine_normal"];
|
||||
NSArray *selectImageNames = @[@"tab_game_selected", @"tab_message_selected", @"tab_mine_selected"];
|
||||
NSArray *tabLabel = @[@"赛事", @"消息", @"我的"];
|
||||
|
||||
UIViewController *game;
|
||||
UIViewController *msg;
|
||||
UIViewController *me;
|
||||
if (logined) {
|
||||
XplanFBFlutterViewContainer *fvcGame = XplanFBFlutterViewContainer.new;
|
||||
@@ -153,16 +155,19 @@
|
||||
[fvcGame setName:@"/" uniqueId:nil params:nil];
|
||||
#endif
|
||||
game = fvcGame;
|
||||
msg = [[SessionListViewController alloc] init];
|
||||
me = [[XPMineViewController alloc] init];
|
||||
} else {
|
||||
game = [[BaseViewController alloc]init];
|
||||
msg = [[BaseViewController alloc]init];
|
||||
me = [[BaseViewController alloc]init];
|
||||
}
|
||||
|
||||
[self createTabBarItem:game title:tabLabel[0] image:normalImageNames[0] selectedImage:selectImageNames[0]];
|
||||
[self createTabBarItem:me title:tabLabel[1] image:normalImageNames[1] selectedImage:selectImageNames[1]];
|
||||
[self createTabBarItem:msg title:tabLabel[1] image:normalImageNames[1] selectedImage:selectImageNames[1]];
|
||||
[self createTabBarItem:me title:tabLabel[2] image:normalImageNames[2] selectedImage:selectImageNames[2]];
|
||||
|
||||
self.viewControllers = @[game, me];
|
||||
self.viewControllers = @[game, msg, me];
|
||||
|
||||
self.selectedIndex = 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user