Initial commit
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// NTESContactDataMember.h
|
||||
// NIM
|
||||
//
|
||||
// Created by chris on 15/9/21.
|
||||
// Copyright © 2015年 Netease. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface NTESContactDataMember : NSObject
|
||||
|
||||
@property (nonatomic,strong) NIMKitInfo *info;
|
||||
|
||||
@end
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// NTESContactDataMember.m
|
||||
// NIM
|
||||
//
|
||||
// Created by chris on 15/9/21.
|
||||
// Copyright © 2015年 Netease. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NTESContactDataMember.h"
|
||||
#import "NTESSpellingCenter.h"
|
||||
|
||||
@implementation NTESContactDataMember
|
||||
|
||||
- (CGFloat)uiHeight{
|
||||
return 50;
|
||||
}
|
||||
|
||||
//userId和Vcname必有一个有值,根据有值的状态push进不同的页面
|
||||
|
||||
- (NSString *)vcName{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSString *)reuseId{
|
||||
return @"NTESContactDataItem";
|
||||
}
|
||||
|
||||
- (NSString *)cellName{
|
||||
return @"NIMContactDataCell";
|
||||
}
|
||||
|
||||
- (NSString *)badge{
|
||||
return @"";
|
||||
}
|
||||
|
||||
- (NSString *)groupTitle {
|
||||
NSString *title = [[NTESSpellingCenter sharedCenter] firstLetter:self.info.showName].capitalizedString;
|
||||
unichar character = [title characterAtIndex:0];
|
||||
if (character >= 'A' && character <= 'Z') {
|
||||
return title;
|
||||
}else{
|
||||
return @"#";
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)userId{
|
||||
return self.info.infoId;
|
||||
}
|
||||
|
||||
- (UIImage *)icon{
|
||||
return self.info.avatarImage;
|
||||
}
|
||||
|
||||
- (NSString *)avatarUrl{
|
||||
return self.info.avatarUrlString;
|
||||
}
|
||||
|
||||
- (NSString *)memberId{
|
||||
return self.info.infoId;
|
||||
}
|
||||
|
||||
- (NSString *)showName{
|
||||
return self.info.showName;
|
||||
}
|
||||
|
||||
- (BOOL)showAccessoryView{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (id)sortKey {
|
||||
return [[NTESSpellingCenter sharedCenter] spellingForString:self.info.showName].shortSpelling;
|
||||
}
|
||||
|
||||
- (BOOL)isEqual:(id)object{
|
||||
if (![object isKindOfClass:[self class]]) {
|
||||
return NO;
|
||||
}
|
||||
return [self.info.infoId isEqualToString:[[object info] infoId]];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// NTESGroupedContacts.h
|
||||
// NIM
|
||||
//
|
||||
// Created by Xuhui on 15/3/2.
|
||||
// Copyright (c) 2015年 Netease. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NTESGroupedDataCollection.h"
|
||||
|
||||
@class NTESContactsManager;
|
||||
|
||||
@interface NTESGroupedContacts : NTESGroupedDataCollection
|
||||
|
||||
@end
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// NTESGroupedContacts.m
|
||||
// NIM
|
||||
//
|
||||
// Created by Xuhui on 15/3/2.
|
||||
// Copyright (c) 2015年 Netease. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NTESGroupedContacts.h"
|
||||
#import "NTESContactDataMember.h"
|
||||
|
||||
@interface NTESGroupedContacts ()
|
||||
|
||||
@end
|
||||
|
||||
@implementation NTESGroupedContacts
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
self.groupTitleComparator = ^NSComparisonResult(NSString *title1, NSString *title2) {
|
||||
if ([title1 isEqualToString:@"#"]) {
|
||||
return NSOrderedDescending;
|
||||
}
|
||||
if ([title2 isEqualToString:@"#"]) {
|
||||
return NSOrderedAscending;
|
||||
}
|
||||
return [title1 compare:title2];
|
||||
};
|
||||
self.groupMemberComparator = ^NSComparisonResult(NSString *key1, NSString *key2) {
|
||||
return [key1 compare:key2];
|
||||
};
|
||||
[self update];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)update{
|
||||
NSMutableArray *contacts = [NSMutableArray array];
|
||||
for (NIMUser *user in [NIMSDK sharedSDK].userManager.myFriends) {
|
||||
NIMKitInfo *info = [[NIMKit sharedKit] infoByUser:user.userId];
|
||||
NTESContactDataMember *contact = [[NTESContactDataMember alloc] init];
|
||||
contact.info = info;
|
||||
[contacts addObject:contact];
|
||||
}
|
||||
[self setMembers:contacts];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// NTESGroupedDataCollection.h
|
||||
// NIM
|
||||
//
|
||||
// Created by Xuhui on 15/3/2.
|
||||
// Copyright (c) 2015年 Netease. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@protocol NTESGroupMemberProtocol <NSObject>
|
||||
|
||||
- (NSString *)groupTitle;
|
||||
- (NSString *)memberId;
|
||||
- (id)sortKey;
|
||||
|
||||
@end
|
||||
|
||||
@interface NTESGroupedDataCollection : NSObject
|
||||
|
||||
@property (nonatomic, strong) NSArray *members;
|
||||
@property (nonatomic, copy) NSComparator groupTitleComparator;
|
||||
@property (nonatomic, copy) NSComparator groupMemberComparator;
|
||||
@property (nonatomic, readonly) NSArray *sortedGroupTitles;
|
||||
|
||||
- (void)addGroupMember:(id<NTESGroupMemberProtocol>)member;
|
||||
|
||||
- (void)removeGroupMember:(id<NTESGroupMemberProtocol>)member;
|
||||
|
||||
- (void)addGroupAboveWithTitle:(NSString *)title members:(NSArray *)members;
|
||||
|
||||
- (NSString *)titleOfGroup:(NSInteger)groupIndex;
|
||||
|
||||
- (NSArray *)membersOfGroup:(NSInteger)groupIndex;
|
||||
|
||||
- (id<NTESGroupMemberProtocol>)memberOfIndex:(NSIndexPath *)indexPath;
|
||||
|
||||
- (id<NTESGroupMemberProtocol>)memberOfId:(NSString *)uid;
|
||||
|
||||
- (NSInteger)groupCount;
|
||||
|
||||
- (NSInteger)memberCountOfGroup:(NSInteger)groupIndex;
|
||||
|
||||
@end
|
||||
+237
@@ -0,0 +1,237 @@
|
||||
//
|
||||
// NTESGroupedDataCollection.m
|
||||
// NIM
|
||||
//
|
||||
// Created by Xuhui on 15/3/2.
|
||||
// Copyright (c) 2015年 Netease. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NTESGroupedDataCollection.h"
|
||||
|
||||
@interface Pair : NSObject
|
||||
|
||||
@property (nonatomic, strong) id first;
|
||||
@property (nonatomic, strong) id second;
|
||||
|
||||
@end
|
||||
|
||||
@implementation Pair
|
||||
|
||||
- (instancetype)initWithFirst:(id)first second:(id)second {
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_first = first;
|
||||
_second = second;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface NTESGroupedDataCollection () {
|
||||
NSMutableOrderedSet *_specialGroupTtiles;
|
||||
NSMutableOrderedSet *_specialGroups;
|
||||
NSMutableOrderedSet *_groupTtiles;
|
||||
NSMutableOrderedSet *_groups;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NTESGroupedDataCollection
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_specialGroupTtiles = [[NSMutableOrderedSet alloc] init];
|
||||
_specialGroups = [[NSMutableOrderedSet alloc] init];
|
||||
_groupTtiles = [[NSMutableOrderedSet alloc] init];
|
||||
_groups = [[NSMutableOrderedSet alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSArray *)sortedGroupTitles
|
||||
{
|
||||
return [_groupTtiles array];
|
||||
}
|
||||
|
||||
- (void)setMembers:(NSArray *)members
|
||||
{
|
||||
NSMutableDictionary *tmp = [NSMutableDictionary dictionary];
|
||||
NSString *me = [[NIMSDK sharedSDK].loginManager currentAccount];
|
||||
for (id<NTESGroupMemberProtocol>member in members) {
|
||||
if ([[member memberId] isEqualToString:me]) {
|
||||
continue;
|
||||
}
|
||||
NSString *groupTitle = [member groupTitle];
|
||||
NSMutableArray *groupedMembers = [tmp objectForKey:groupTitle];
|
||||
if(!groupedMembers) {
|
||||
groupedMembers = [NSMutableArray array];
|
||||
}
|
||||
[groupedMembers addObject:member];
|
||||
[tmp setObject:groupedMembers forKey:groupTitle];
|
||||
}
|
||||
[_groupTtiles removeAllObjects];
|
||||
[_groups removeAllObjects];
|
||||
|
||||
[tmp enumerateKeysAndObjectsUsingBlock:^(NSString *groupTitle, NSMutableArray *groupedMembers, BOOL *stop) {
|
||||
if (groupTitle.length) {
|
||||
unichar character = [groupTitle characterAtIndex:0];
|
||||
if (character >= 'A' && character <= 'Z') {
|
||||
[_groupTtiles addObject:groupTitle];
|
||||
}else{
|
||||
[_groupTtiles addObject:@"#"];
|
||||
}
|
||||
[_groups addObject:[[Pair alloc] initWithFirst:groupTitle second:groupedMembers]];
|
||||
}
|
||||
}];
|
||||
[self sort];
|
||||
}
|
||||
|
||||
- (void)addGroupMember:(id<NTESGroupMemberProtocol>)member
|
||||
{
|
||||
NSString *groupTitle = [member groupTitle];
|
||||
NSInteger groupIndex = [_groupTtiles indexOfObject:groupTitle];
|
||||
Pair *pair = [_groups objectAtIndex:groupIndex];
|
||||
if(!pair) {
|
||||
NSMutableArray *members = [NSMutableArray array];
|
||||
pair = [[Pair alloc] initWithFirst:groupTitle second:members];
|
||||
}
|
||||
NSMutableArray *members = pair.second;
|
||||
[members addObject:member];
|
||||
[_groupTtiles addObject:groupTitle];
|
||||
[_groups addObject:pair];
|
||||
[self sort];
|
||||
}
|
||||
|
||||
- (void)removeGroupMember:(id<NTESGroupMemberProtocol>)member{
|
||||
NSString *groupTitle = [member groupTitle];
|
||||
NSInteger groupIndex = [_groupTtiles indexOfObject:groupTitle];
|
||||
Pair *pair = [_groups objectAtIndex:groupIndex];
|
||||
[pair.second removeObject:member];
|
||||
if (![pair.second count]) {
|
||||
[_groups removeObject:pair];
|
||||
}
|
||||
[self sort];
|
||||
}
|
||||
|
||||
- (void)addGroupAboveWithTitle:(NSString *)title members:(NSArray *)members {
|
||||
Pair *pair = [[Pair alloc] initWithFirst:title second:members];
|
||||
[_specialGroupTtiles addObject:title];
|
||||
[_specialGroups addObject:pair];
|
||||
}
|
||||
|
||||
- (NSString *)titleOfGroup:(NSInteger)groupIndex
|
||||
{
|
||||
if(groupIndex >= 0 && groupIndex < _specialGroupTtiles.count) {
|
||||
return [_specialGroupTtiles objectAtIndex:groupIndex];
|
||||
}
|
||||
groupIndex -= _specialGroupTtiles.count;
|
||||
if(groupIndex >= 0 && groupIndex < _groupTtiles.count) {
|
||||
return [_groupTtiles objectAtIndex:groupIndex];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSArray *)membersOfGroup:(NSInteger)groupIndex
|
||||
{
|
||||
if(groupIndex >= 0 && groupIndex < _specialGroups.count) {
|
||||
Pair *pair = [_specialGroups objectAtIndex:groupIndex];
|
||||
return pair.second;
|
||||
}
|
||||
groupIndex -= _specialGroups.count;
|
||||
if(groupIndex >= 0 && groupIndex < _groups.count) {
|
||||
Pair *pair = [_groups objectAtIndex:groupIndex];
|
||||
return pair.second;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id<NTESGroupMemberProtocol>)memberOfIndex:(NSIndexPath *)indexPath
|
||||
{
|
||||
NSArray *members = nil;
|
||||
NSInteger groupIndex = indexPath.section;
|
||||
if(groupIndex >= 0 && groupIndex < _specialGroups.count) {
|
||||
Pair *pair = [_specialGroups objectAtIndex:groupIndex];
|
||||
members = pair.second;
|
||||
}
|
||||
groupIndex -= _specialGroups.count;
|
||||
if(groupIndex >= 0 && groupIndex < _groups.count) {
|
||||
Pair *pair = [_groups objectAtIndex:groupIndex];
|
||||
members = pair.second;
|
||||
}
|
||||
NSInteger memberIndex = indexPath.row;
|
||||
if(memberIndex < 0 || memberIndex >= members.count) return nil;
|
||||
return [members objectAtIndex:memberIndex];
|
||||
}
|
||||
|
||||
- (id<NTESGroupMemberProtocol>)memberOfId:(NSString *)uid{
|
||||
for (Pair *pair in _groups) {
|
||||
NSArray *members = pair.second;
|
||||
for (id<NTESGroupMemberProtocol> member in members) {
|
||||
if ([[member memberId] isEqualToString:uid]) {
|
||||
return member;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSInteger)groupCount
|
||||
{
|
||||
return _specialGroupTtiles.count + _groupTtiles.count;
|
||||
}
|
||||
|
||||
- (NSInteger)memberCountOfGroup:(NSInteger)groupIndex
|
||||
{
|
||||
NSArray *members = nil;
|
||||
if(groupIndex >= 0 && groupIndex < _specialGroups.count) {
|
||||
Pair *pair = [_specialGroups objectAtIndex:groupIndex];
|
||||
members = pair.second;
|
||||
}
|
||||
groupIndex -= _specialGroups.count;
|
||||
if(groupIndex >= 0 && groupIndex < _groups.count) {
|
||||
Pair *pair = [_groups objectAtIndex:groupIndex];
|
||||
members = pair.second;
|
||||
}
|
||||
return members.count;
|
||||
}
|
||||
|
||||
- (void)sort
|
||||
{
|
||||
[self sortGroupTitle];
|
||||
[self sortGroupMember];
|
||||
}
|
||||
|
||||
- (void)sortGroupTitle
|
||||
{
|
||||
[_groupTtiles sortUsingComparator:_groupTitleComparator];
|
||||
[_groups sortUsingComparator:^NSComparisonResult(Pair *pair1, Pair *pair2) {
|
||||
return _groupTitleComparator(pair1.first, pair2.first);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)sortGroupMember
|
||||
{
|
||||
[_groups enumerateObjectsUsingBlock:^(Pair *obj, NSUInteger idx, BOOL *stop) {
|
||||
NSMutableArray *groupedMembers = obj.second;
|
||||
[groupedMembers sortUsingComparator:^NSComparisonResult(id<NTESGroupMemberProtocol> member1, id<NTESGroupMemberProtocol> member2) {
|
||||
return _groupMemberComparator([member1 sortKey], [member2 sortKey]);
|
||||
}];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setGroupTitleComparator:(NSComparator)groupTitleComparator
|
||||
{
|
||||
_groupTitleComparator = groupTitleComparator;
|
||||
[self sortGroupTitle];
|
||||
}
|
||||
|
||||
- (void)setGroupMemberComparator:(NSComparator)groupMemberComparator
|
||||
{
|
||||
_groupMemberComparator = groupMemberComparator;
|
||||
[self sortGroupMember];
|
||||
}
|
||||
|
||||
@end
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// NTESGroupedUsrInfo.h
|
||||
// NIM
|
||||
//
|
||||
// Created by Xuhui on 15/3/24.
|
||||
// Copyright (c) 2015年 Netease. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NTESGroupedDataCollection.h"
|
||||
|
||||
@interface NTESGroupedUsrInfo : NTESGroupedDataCollection
|
||||
|
||||
- (instancetype)initWithContacts:(NSArray *)contacts;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface NTESGroupedTeamInfo : NTESGroupedDataCollection
|
||||
|
||||
- (instancetype)initWithTeams:(NSArray *)teams;
|
||||
|
||||
@end
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// NTESGroupedUsrInfo.m
|
||||
// NIM
|
||||
//
|
||||
// Created by Xuhui on 15/3/24.
|
||||
// Copyright (c) 2015年 Netease. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NTESGroupedUsrInfo.h"
|
||||
#import "NIMTeamInfoData.h"
|
||||
@implementation NTESGroupedUsrInfo
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
self.groupTitleComparator = ^NSComparisonResult(NSString *title1, NSString *title2) {
|
||||
return [title1 localizedCompare:title2];
|
||||
};
|
||||
self.groupMemberComparator = ^NSComparisonResult(NSString *key1, NSString *key2) {
|
||||
return [key1 localizedCompare:key2];
|
||||
};
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithContacts:(NSArray *)contacts {
|
||||
self = [self init];
|
||||
if(self) {
|
||||
self.members = contacts;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@implementation NTESGroupedTeamInfo
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
self.groupTitleComparator = ^NSComparisonResult(NSString *title1, NSString *title2) {
|
||||
return [title1 localizedCompare:title2];
|
||||
};
|
||||
self.groupMemberComparator = ^NSComparisonResult(NSString *key1, NSString *key2) {
|
||||
return [key1 localizedCompare:key2];
|
||||
};
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithTeams:(NSArray *)teams{
|
||||
self = [self init];
|
||||
if(self) {
|
||||
NSMutableArray *array = [[NSMutableArray alloc] init];
|
||||
for (NIMTeam *team in teams) {
|
||||
NIMTeamInfoData *teamInfo = [[NIMTeamInfoData alloc] initWithTeam:team];
|
||||
[array addObject:teamInfo];
|
||||
}
|
||||
self.members = array;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user