Skip to content

Commit

Permalink
通讯录部分重构ing
Browse files Browse the repository at this point in the history
  • Loading branch information
tbl00c committed Jan 8, 2018
1 parent e46efaa commit cf067b3
Show file tree
Hide file tree
Showing 103 changed files with 1,101 additions and 1,042 deletions.
736 changes: 376 additions & 360 deletions TLChat.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions TLChat/AppControlCenter/TLAccountManager/Models/TLUserGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

@interface TLUserGroup : NSObject

/// tag
@property (nonatomic, assign) NSInteger tag;

@property (nonatomic, strong) NSString *groupName;

@property (nonatomic, strong) NSMutableArray *users;
Expand Down
4 changes: 0 additions & 4 deletions TLChat/AppControlCenter/TLUserManager/TLFriendHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@

@interface TLFriendHelper : NSObject

/// 好友列表默认项
@property (nonatomic, strong) TLUserGroup *defaultGroup;


#pragma mark - # 好友

/// 好友数据(原始)
Expand Down
30 changes: 4 additions & 26 deletions TLChat/AppControlCenter/TLUserManager/TLFriendHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ - (id)init
if (self = [super init]) {
// 初始化好友数据
_friendsData = [self.friendStore friendsDataByUid:[TLUserHelper sharedHelper].userID];
self.data = [[NSMutableArray alloc] initWithObjects:self.defaultGroup, nil];
self.data = [[NSMutableArray alloc] init];
self.sectionHeaders = [[NSMutableArray alloc] initWithObjects:UITableViewIndexSearch, nil];
// 初始化群数据
self.groupsData = [self.groupStore groupsDataByUid:[TLUserHelper sharedHelper].userID];
Expand Down Expand Up @@ -104,13 +104,14 @@ - (void)p_resetFriendData
}];

// 2、分组
NSMutableArray *ansData = [[NSMutableArray alloc] initWithObjects:self.defaultGroup, nil];
NSMutableArray *ansData = [[NSMutableArray alloc] init];
NSMutableArray *ansSectionHeaders = [[NSMutableArray alloc] initWithObjects:UITableViewIndexSearch, nil];
NSMutableDictionary *tagsDic = [[NSMutableDictionary alloc] init];
char lastC = '1';
TLUserGroup *curGroup;
TLUserGroup *othGroup = [[TLUserGroup alloc] init];
[othGroup setGroupName:@"#"];
[othGroup setTag:27];
for (TLUser *user in serializeArray) {
// 获取拼音失败
if (user.pinyin == nil || user.pinyin.length == 0) {
Expand All @@ -131,6 +132,7 @@ - (void)p_resetFriendData
curGroup = [[TLUserGroup alloc] init];
[curGroup setGroupName:[NSString stringWithFormat:@"%c", c]];
[curGroup addObject:user];
[curGroup setTag:(NSInteger)c];
}
else {
[curGroup addObject:user];
Expand Down Expand Up @@ -206,30 +208,6 @@ - (void)p_initTestData
}

#pragma mark - Getter
- (TLUserGroup *)defaultGroup
{
if (_defaultGroup == nil) {
TLUser *item_new = [[TLUser alloc] init];
item_new.userID = @"-1";
item_new.avatarPath = @"friends_new";
item_new.remarkName = @"新的朋友";
TLUser *item_group = [[TLUser alloc] init];
item_group.userID = @"-2";
item_group.avatarPath = @"friends_group";
item_group.remarkName = @"群聊";
TLUser *item_tag = [[TLUser alloc] init];
item_tag.userID = @"-3";
item_tag.avatarPath = @"friends_tag";
item_tag.remarkName = @"标签";
TLUser *item_public = [[TLUser alloc] init];
item_public.userID = @"-4";
item_public.avatarPath = @"friends_public";
item_public.remarkName = @"公共号";
_defaultGroup = [[TLUserGroup alloc] initWithGroupName:nil users:[NSMutableArray arrayWithObjects:item_new, item_group, item_tag, item_public, nil]];
}
return _defaultGroup;
}

- (NSInteger)friendCount
{
return self.friendsData.count;
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// TLContactsSearchResultViewController.h
// TLChat
//
// Created by 李伯坤 on 16/1/25.
// Copyright © 2016年 李伯坤. All rights reserved.
//

#import "TLViewController.h"
#import "TLSearchControllerProtocol.h"

#define HEIGHT_FRIEND_CELL 54.0f

@class TLUser;
@interface TLContactsSearchResultViewController : TLViewController <TLSearchControllerProtocol>

@property (nonatomic, copy) void (^itemSelectedAction)(TLContactsSearchResultViewController *searchVC, TLUser *userModel);

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// TLContactsSearchResultViewController.m
// TLChat
//
// Created by 李伯坤 on 16/1/25.
// Copyright © 2016年 李伯坤. All rights reserved.
//

#import "TLContactsSearchResultViewController.h"
#import "TLContactsItemCell.h"
#import "TLFriendHelper.h"

@interface TLContactsSearchResultViewController ()

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) ZZFLEXAngel *tableViewAngel;

@property (nonatomic, strong) NSMutableArray *friendsData;

@end

@implementation TLContactsSearchResultViewController

- (void)loadView
{
[super loadView];
[self setStatusBarStyle:UIStatusBarStyleDefault];

self.tableView = self.view.addTableView(1)
.backgroundColor([UIColor colorGrayBG]).separatorStyle(UITableViewCellSeparatorStyleNone)
.tableFooterView([UIView new])
.estimatedRowHeight(0).estimatedSectionFooterHeight(0).estimatedSectionHeaderHeight(0)
.masonry(^ (MASConstraintMaker *make) {
make.edges.mas_equalTo(0);
})
.view;

self.tableViewAngel = [[ZZFLEXAngel alloc] initWithHostView:self.tableView];
}

- (void)viewDidLoad
{
[super viewDidLoad];

self.friendsData = [TLFriendHelper sharedFriendHelper].friendsData;
}

//MARK: UISearchResultsUpdating
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
TLContactsItemModel *(^createContactsItemModelWithUserModel)(TLUser *userModel) = ^TLContactsItemModel *(TLUser *userModel){
TLContactsItemModel *model = createContactsItemModel(userModel.avatarPath, userModel.avatarURL, userModel.showName, userModel.detailInfo.remarkInfo, userModel);
return model;
};

// 查找数据
NSString *searchText = [searchController.searchBar.text lowercaseString];
NSMutableArray *data = [[NSMutableArray alloc] init];
for (TLUser *user in self.friendsData) {
if ([user.remarkName containsString:searchText] || [user.username containsString:searchText] || [user.nikeName containsString:searchText] || [user.pinyin containsString:searchText] || [user.pinyinInitial containsString:searchText]) {
TLContactsItemModel *model = createContactsItemModelWithUserModel(user);
[data addObject:model];
}
}

// 更新UI
self.tableViewAngel.clear();
if (data.count > 0) {
self.tableViewAngel.addSection(0);
self.tableViewAngel.setHeader(@"TLContactsHeaderView").toSection(0).withDataModel(@"联系人");
self.tableViewAngel.addCells(@"TLContactsItemCell").toSection(0).withDataModelArray(data).selectedAction(^ (TLContactsItemModel *model) {
if (self.itemSelectedAction) {
self.itemSelectedAction(self, model.userInfo);
}
});
}
[self.tableView reloadData];
}

//MARK: UISearchBarDelegate
- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar
{
[TLUIUtility showAlertWithTitle:@"语音搜索按钮"];
}

@end
32 changes: 32 additions & 0 deletions TLChat/Modules/Contacts/TLContactsViewController/TLContactsAngel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// TLContactsAngel.h
// TLChat
//
// Created by 李伯坤 on 2018/1/8.
// Copyright © 2018年 李伯坤. All rights reserved.
//

#import <ZZFlexibleLayoutFramework/ZZFlexibleLayoutFramework.h>

typedef NS_ENUM(NSInteger, TLContactsVCSectionType) {
TLContactsVCSectionTypeFuncation = -1,
TLContactsVCSectionTypeEnterprise = -2,
};

typedef NS_ENUM(NSInteger, TLContactsVCCellType) {
TLContactsVCCellTypeNew = -1,
TLContactsVCCellTypeGroup = -2,
TLContactsVCCellTypeTag = -3,
TLContactsVCCellTypePublic = -4,
};

@interface TLContactsAngel : ZZFLEXAngel

/// pushAction
@property (nonatomic, copy) void (^pushAction)(__kindof UIViewController *vc);

- (void)resetListWithContactsData:(NSArray *)contactsData sectionHeaders:(NSArray *)sectionHeaders;

- (instancetype)initWithHostView:(__kindof UIScrollView *)hostView pushAction:(void (^)(__kindof UIViewController *vc))pushAction;

@end
120 changes: 120 additions & 0 deletions TLChat/Modules/Contacts/TLContactsViewController/TLContactsAngel.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
//
// TLContactsAngel.m
// TLChat
//
// Created by 李伯坤 on 2018/1/8.
// Copyright © 2018年 李伯坤. All rights reserved.
//

#import "TLContactsAngel.h"
#import "TLUserGroup.h"
#import "TLContactsItemCell.h"

#import "TLNewFriendViewController.h"
#import "TLGroupViewController.h"
#import "TLTagsViewController.h"
#import "TLServiceAccountViewController.h"
#import "TLUserDetailViewController.h"

@interface TLContactsAngel ()

/// header
@property (nonatomic, strong) NSArray *sectionHeaders;

@end

@implementation TLContactsAngel

- (instancetype)initWithHostView:(__kindof UIScrollView *)hostView pushAction:(void (^)(__kindof UIViewController *vc))pushAction
{
if (self = [super initWithHostView:hostView]) {
self.pushAction = pushAction;
}
return self;
}

- (void)resetListWithContactsData:(NSArray *)contactsData sectionHeaders:(NSArray *)sectionHeaders
{
@weakify(self);
self.clear();

/// 功能
self.addSection(TLContactsVCSectionTypeFuncation);
{
TLContactsItemModel *newModel = createContactsItemModelWithTag(TLContactsVCCellTypeNew, @"friends_new", nil, LOCSTR(@"新的朋友"), nil, nil);
TLContactsItemModel *groupModel = createContactsItemModelWithTag(TLContactsVCCellTypeGroup, @"friends_group", nil, LOCSTR(@"群聊"), nil, nil);
TLContactsItemModel *tagModel = createContactsItemModelWithTag(TLContactsVCCellTypeTag, @"friends_tag", nil, LOCSTR(@"标签"), nil, nil);
TLContactsItemModel *publicModel = createContactsItemModelWithTag(TLContactsVCCellTypePublic, @"friends_public", nil, LOCSTR(@"公共号"), nil, nil);
NSArray *funcationData = @[newModel, groupModel, tagModel, publicModel];
self.addCells(NSStringFromClass([TLContactsItemCell class])).toSection(TLContactsVCSectionTypeFuncation).withDataModelArray(funcationData).selectedAction(^ (TLContactsItemModel *model) {
@strongify(self);
if (model.tag == TLContactsVCCellTypeNew) {
TLNewFriendViewController *newFriendVC = [[TLNewFriendViewController alloc] init];
[self tryPushVC:newFriendVC];
}
else if (model.tag == TLContactsVCCellTypeGroup) {
TLGroupViewController *groupVC = [[TLGroupViewController alloc] init];
[self tryPushVC:groupVC];
}
else if (model.tag == TLContactsVCCellTypeTag) {
TLTagsViewController *tagsVC = [[TLTagsViewController alloc] init];
[self tryPushVC:tagsVC];
}
else if (model.tag == TLContactsVCCellTypePublic) {
TLServiceAccountViewController *publicServerVC = [[TLServiceAccountViewController alloc] init];
[self tryPushVC:publicServerVC];
}
});
}
// 企业
self.addSection(TLContactsVCSectionTypeEnterprise);

// 好友
TLContactsItemModel *(^createContactsItemModelWithUserModel)(TLUser *userModel) = ^TLContactsItemModel *(TLUser *userModel){
TLContactsItemModel *model = createContactsItemModel(userModel.avatarPath, userModel.avatarURL, userModel.showName, userModel.detailInfo.remarkInfo, userModel);
return model;
};
for (TLUserGroup *group in contactsData) {
NSInteger sectionTag = group.tag;
self.addSection(sectionTag);
self.setHeader(@"TLContactsHeaderView").toSection(sectionTag).withDataModel(group.groupName);

NSMutableArray *data = [[NSMutableArray alloc]initWithCapacity:group.users.count];
for (TLUser *user in group.users) {
TLContactsItemModel *newModel = createContactsItemModelWithUserModel(user);
[data addObject:newModel];
}
self.addCells(NSStringFromClass([TLContactsItemCell class])).toSection(sectionTag).withDataModelArray(data).selectedAction(^ (TLContactsItemModel *data) {
@strongify(self);
TLUser *user = data.userInfo;
TLUserDetailViewController *detailVC = [[TLUserDetailViewController alloc] initWithUserModel:user];
[self tryPushVC:detailVC];
});
}
}

- (void)tryPushVC:(__kindof UIViewController *)vc
{
if (self.pushAction) {
self.pushAction(vc);
}
}

#pragma mark - # Delegate
// 拼音首字母检索
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return self.sectionHeaders;
}

// 检索时空出搜索框
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
if(index == 0) {
[tableView scrollRectToVisible:CGRectMake(0, 0, tableView.width, tableView.height) animated:NO];
return -1;
}
return index;
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// TLContactsViewController.h
// TLChat
//
// Created by 李伯坤 on 16/1/23.
// Copyright © 2016年 李伯坤. All rights reserved.
//

#import "TLViewController.h"

@interface TLContactsViewController : TLViewController


@end
Loading

0 comments on commit cf067b3

Please sign in to comment.