chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:35:01 +08:00
commit a2e318a963
2974 changed files with 158180 additions and 0 deletions
@@ -0,0 +1,73 @@
//
// TLExpressionGroupModel.h
// TLChat
//
// Created by 李伯坤 on 16/2/19.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "TLChatMacros.h"
#import "TLExpressionModel.h"
typedef NS_ENUM(NSInteger, TLExpressionGroupStatus) {
TLExpressionGroupStatusNet, // 未下载
TLExpressionGroupStatusDownloading, // 正在下载
TLExpressionGroupStatusLocal, // 已下载
};
@interface TLExpressionGroupModel: NSObject
@property (nonatomic, assign) TLEmojiType type;
/// 表情包id
@property (nonatomic, strong) NSString *gId;
/// 表情包名称
@property (nonatomic, strong) NSString *name;
/// 表情包描述
@property (nonatomic, strong) NSString *detail;
/// 表情包icon路径
@property (nonatomic, strong) NSString *iconPath;
/// 表情包iconURL
@property (nonatomic, strong) NSString *iconURL;
/// 表情包bannerId
@property (nonatomic, strong) NSString *bannerId;
/// 表情包bannerURL
@property (nonatomic, strong) NSString *bannerURL;
/// 表情
@property (nonatomic, strong) NSMutableArray *data;
/// 表情总数
@property (nonatomic, assign) NSUInteger count;
/// 详细信息
@property (nonatomic, strong) NSString *groupInfo;
/// 发布日期
@property (nonatomic, strong) NSDate *date;
/// 作者姓名
@property (nonatomic, strong) NSString *authName;
/// 作者Id
@property (nonatomic, strong) NSString *authID;
/// 表情包状态
@property (nonatomic, assign) TLExpressionGroupStatus status;
/// 表情包路径
@property (nonatomic, strong, readonly) NSString *path;
/// 下载进度
@property (nonatomic, assign) CGFloat downloadProgress;
/// 下载进度block
@property (nonatomic, copy) void (^downloadProgressAction)(TLExpressionGroupModel *groupModel, CGFloat progress);
/// 下载完成block
@property (nonatomic, copy) void (^downloadCompleteAction)(TLExpressionGroupModel *groupModel, BOOL success, id data);
- (id)objectAtIndex:(NSUInteger)index;
@end
@@ -0,0 +1,74 @@
//
// TLExpressionGroupModel.m
// TLChat
//
// Created by 李伯坤 on 16/2/19.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLExpressionGroupModel.h"
#import "NSFileManager+TLChat.h"
#import "TLExpressionHelper.h"
@implementation TLExpressionGroupModel
@synthesize path = _path;
+ (NSDictionary *)replacedKeyFromPropertyName
{
return @{
@"gId" : @"eId",
@"iconURL" : @"coverUrl",
@"name" : @"eName",
@"detail" : @"memo1",
@"count" : @"picCount",
@"bannerId" : @"aId",
@"bannerURL" : @"URL",
@"groupInfo" : @"memo",
};
}
- (void)setData:(NSMutableArray *)data
{
_data = data;
self.count = data.count;
[self p_updateExpressionItemGid];
}
- (void)setGId:(NSString *)gId
{
_gId = gId;
[self p_updateExpressionItemGid];
}
- (id)objectAtIndex:(NSUInteger)index
{
return [self.data objectAtIndex:index];
}
#pragma mark - # Private Methods
- (void)p_updateExpressionItemGid
{
for (TLExpressionModel *model in self.data) {
model.gid = self.gId;
}
}
#pragma mark - # Getters
- (NSString *)path
{
if (_path == nil && self.gId != nil) {
_path = [NSFileManager pathExpressionForGroupID:self.gId];
}
return _path;
}
- (NSString *)iconPath
{
if (_iconPath == nil && self.path != nil) {
_iconPath = [NSString stringWithFormat:@"%@icon_%@", self.path, self.gId];
}
return _iconPath;
}
@end
@@ -0,0 +1,45 @@
//
// TLExpressionModel.h
// TLChat
//
// Created by 李伯坤 on 16/2/20.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "TLChatMacros.h"
@interface TLExpressionModel : NSObject
/// 表情类型
@property (nonatomic, assign) TLEmojiType type;
/// 表情包id
@property (nonatomic, strong) NSString *gid;
/// 表情id
@property (nonatomic, strong) NSString *eId;
/// 表情名
@property (nonatomic, strong) NSString *name;
/// 远程url
@property (nonatomic, strong) NSString *url;
/// 本地路径
@property (nonatomic, strong, readonly) NSString *path;
/// 表情大小
@property (nonatomic, assign) CGFloat size;
/**
* 根据eid获取表情url
*/
+ (NSString *)expressionURLWithEid:(NSString *)eid;
/**
* 根据eid获取表情下载url
*/
+ (NSString *)expressionDownloadURLWithEid:(NSString *)eid;
@end
@@ -0,0 +1,47 @@
//
// TLExpressionModel.m
// TLChat
//
// Created by 李伯坤 on 16/2/20.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLExpressionModel.h"
#import "NSFileManager+TLChat.h"
#import "TLMacros.h"
@implementation TLExpressionModel
@synthesize path = _path;
+ (NSString *)expressionURLWithEid:(NSString *)eid
{
return [NSString stringWithFormat:@"%@expre/downloadsuo.do?pId=%@", IEXPRESSION_HOST_URL, eid];
}
+ (NSString *)expressionDownloadURLWithEid:(NSString *)eid
{
return [NSString stringWithFormat:@"%@expre/download.do?pId=%@", IEXPRESSION_HOST_URL, eid];
}
+ (NSDictionary *)replacedKeyFromPropertyName
{
return @{
@"eId" : @"pId",
@"url" : @"Url",
@"name" : @"credentialName",
@"emojiPath" : @"imageFile",
@"size" : @"size",
};
}
#pragma mark - # Getters
- (NSString *)path
{
if (_path == nil) {
NSString *groupPath = [NSFileManager pathExpressionForGroupID:self.gid];
_path = [NSString stringWithFormat:@"%@%@", groupPath, self.eId];
}
return _path;
}
@end
@@ -0,0 +1,18 @@
//
// TLExpressionGroupModel+DetailRequest.h
// TLChat
//
// Created by 李伯坤 on 2018/1/2.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import "TLExpressionGroupModel.h"
@interface TLExpressionGroupModel (DetailRequest)
/**
* 表情详情
*/
- (TLBaseRequest *)requestExpressionGroupDetailByPageIndex:(NSInteger)pageIndex success:(TLRequestSuccessBlock)success failure:(TLRequestFailureBlock)failure;
@end
@@ -0,0 +1,43 @@
//
// TLExpressionGroupModel+DetailRequest.m
// TLChat
//
// Created by 李伯坤 on 2018/1/2.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import "TLExpressionGroupModel+DetailRequest.h"
#import "TLNetworking.h"
#define IEXPRESSION_DETAIL_URL [IEXPRESSION_HOST_URL stringByAppendingString:@"expre/getByeId.do?pageNumber=%ld&eId=%@"]
@implementation TLExpressionGroupModel (DetailRequest)
- (TLBaseRequest *)requestExpressionGroupDetailByPageIndex:(NSInteger)pageIndex success:(TLRequestSuccessBlock)success failure:(TLRequestFailureBlock)failure
{
NSString *urlString = [NSString stringWithFormat:IEXPRESSION_DETAIL_URL, (long)pageIndex, self.gId];
[TLNetworking postUrl:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
NSArray *respArray = [responseObject mj_JSONObject];
NSString *status = respArray[0];
if ([status isEqualToString:@"OK"]) {
NSArray *infoArray = respArray[2];
NSMutableArray *data = [TLExpressionModel mj_objectArrayWithKeyValuesArray:infoArray];
if (success) {
success(data);
}
}
else {
if (failure) {
failure(status);
}
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure(TLNetworkErrorTip);
}
}];
return nil;
}
@end
@@ -0,0 +1,18 @@
//
// TLExpressionDetailViewController.h
// TLChat
//
// Created by 李伯坤 on 16/4/8.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLViewController.h"
@class TLExpressionGroupModel;
@interface TLExpressionDetailViewController : ZZFlexibleLayoutViewController
@property (nonatomic, strong, readonly) TLExpressionGroupModel *groupModel;
- (id)initWithGroupModel:(TLExpressionGroupModel *)groupModel;
@end
@@ -0,0 +1,201 @@
//
// TLExpressionDetailViewController.m
// TLChat
//
// Created by 李伯坤 on 16/4/8.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLExpressionDetailViewController.h"
#import "TLImageExpressionDisplayView.h"
#import "TLExpressionGroupModel+DetailRequest.h"
#import "TLExpressionDetailItemCell.h"
typedef NS_ENUM(NSInteger, TLExpressionDetailVCSectionType) {
TLExpressionDetailVCSectionTypeHeader,
TLExpressionDetailVCSectionTypeItems,
};
@interface TLExpressionDetailViewController ()
@property (nonatomic, assign) NSInteger pageIndex;
@property (nonatomic, strong) TLImageExpressionDisplayView *emojiDisplayView;
@end
@implementation TLExpressionDetailViewController
- (id)initWithGroupModel:(TLExpressionGroupModel *)groupModel
{
if (self = [super init]) {
_pageIndex = 1;
_groupModel = groupModel;
}
return self;
}
- (void)loadView
{
[super loadView];
[self setTitle:self.groupModel.name];
[self.view setBackgroundColor:[UIColor whiteColor]];
// 添加表情长按浏览手势
[self p_addDisplayGesture];
// 加载表情详情cells
[self p_loadGroupDetailCells];
}
- (void)viewDidLoad
{
[super viewDidLoad];
if (self.groupModel.data.count == 0) {
[TLUIUtility showLoading:nil];
[self requestExpressionGroupDetailDataWithPageIndex:1];
}
else {
[self p_showExpressionItemsWithData:self.groupModel.data];
}
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[TLUIUtility hiddenLoading];
}
#pragma mark - # Requests
- (void)requestExpressionGroupDetailDataWithPageIndex:(NSInteger)pageIndex
{
@weakify(self);
[self.groupModel requestExpressionGroupDetailByPageIndex:pageIndex success:^(NSArray *data) {
@strongify(self);
if (!self) {
return;
}
[TLUIUtility hiddenLoading];
self.pageIndex = pageIndex;
if (pageIndex == 1) {
self.groupModel.data = [data mutableCopy];
self.sectionForTag(TLExpressionDetailVCSectionTypeItems).clear();
}
else {
[self.groupModel.data addObjectsFromArray:data];
}
[self p_showExpressionItemsWithData:data];
} failure:^(NSString *error) {
[TLUIUtility hiddenLoading];
}];
}
#pragma mark - # Event Response
- (void)didLongPressScreen:(UILongPressGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateEnded || sender.state == UIGestureRecognizerStateCancelled) { // 长按停止
[self.emojiDisplayView removeFromSuperview];
}
else {
CGPoint point = [sender locationInView:self.collectionView];
for (UICollectionViewCell *cell in self.collectionView.visibleCells) {
if (cell.x <= point.x && cell.y <= point.y && cell.x + cell.width >= point.x && cell.y + cell.height >= point.y) {
NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell];
TLExpressionModel *emoji = [self.groupModel objectAtIndex:indexPath.row];
CGRect rect = cell.frame;
rect.origin.y -= (self.collectionView.contentOffset.y + 13);
[self.emojiDisplayView removeFromSuperview];
[self.emojiDisplayView displayEmoji:emoji atRect:rect];
[self.view addSubview:self.emojiDisplayView];
break;
}
}
}
}
- (void)didTap5TimesScreen:(UITapGestureRecognizer *)sender
{
CGPoint point = [sender locationInView:self.collectionView];
for (UICollectionViewCell *cell in self.collectionView.visibleCells) {
if (cell.x <= point.x && cell.y <= point.y && cell.x + cell.width >= point.x && cell.y + cell.height >= point.y) {
NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell];
TLExpressionModel *emoji = [self.groupModel objectAtIndex:indexPath.row];
[TLUIUtility showLoading:@"正在将表情保存到系统相册"];
NSString *urlString = [TLExpressionModel expressionDownloadURLWithEid:emoji.eId];
NSData *data = [NSData dataWithContentsOfURL:TLURL(urlString)];
if (!data) {
data = [NSData dataWithContentsOfFile:emoji.path];
}
if (data) {
UIImage *image = [UIImage imageWithData:data];
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
}
break;
}
}
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
if (error) {
[TLUIUtility showAlertWithTitle:@"错误" message:[NSString stringWithFormat:@"保存图片到系统相册失败\n%@", [error description]]];
}
else {
[TLUIUtility showSuccessHint:@"已保存到系统相册"];
}
}
#pragma mark - # Private Methods
- (void)p_loadGroupDetailCells
{
self.addSection(TLExpressionDetailVCSectionTypeHeader);
self.addSection(TLExpressionDetailVCSectionTypeItems)
.sectionInsets(UIEdgeInsetsMake(EXP_DETAIL_EDGE, EXP_DETAIL_EDGE, EXP_DETAIL_EDGE, EXP_DETAIL_EDGE))
.minimumLineSpacing(EXP_DETAIL_SPACE).minimumInteritemSpacing(EXP_DETAIL_SPACE);
if (self.groupModel) {
// banner
if (self.groupModel.bannerURL.length > 0) {
self.addCell(@"TLExpressionDetailBannerCell").toSection(TLExpressionDetailVCSectionTypeHeader).withDataModel(self.groupModel.bannerURL);
}
// 介绍
self.addCell(@"TLExpressionDetailInfoCell").toSection(TLExpressionDetailVCSectionTypeHeader).withDataModel(self.groupModel);
// 分割线
self.addCell(@"TLExpressionDetailSeperatorCell").toSection(TLExpressionDetailVCSectionTypeHeader);
[self reloadView];
}
}
- (void)p_addDisplayGesture
{
UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc] init];
[longPressGR setMinimumPressDuration:1.0f];
[longPressGR addTarget:self action:@selector(didLongPressScreen:)];
[self.collectionView addGestureRecognizer:longPressGR];
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] init];
[tapGR setNumberOfTapsRequired:5];
[tapGR setNumberOfTouchesRequired:1];
[tapGR addTarget:self action:@selector(didTap5TimesScreen:)];
[self.collectionView addGestureRecognizer:tapGR];
}
- (void)p_showExpressionItemsWithData:(NSArray *)data
{
// 表情
self.addCells(@"TLExpressionDetailItemCell").toSection(TLExpressionDetailVCSectionTypeItems).withDataModelArray(data);
[self reloadView];
}
#pragma mark - # Getter
- (TLImageExpressionDisplayView *)emojiDisplayView
{
if (_emojiDisplayView == nil) {
_emojiDisplayView = [[TLImageExpressionDisplayView alloc] init];
}
return _emojiDisplayView;
}
@end
@@ -0,0 +1,13 @@
//
// TLExpressionDetailBannerCell.h
// TLChat
//
// Created by 李伯坤 on 2018/1/4.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLExpressionDetailBannerCell : UICollectionViewCell <ZZFlexibleLayoutViewProtocol>
@end
@@ -0,0 +1,49 @@
//
// TLExpressionDetailBannerCell.m
// TLChat
//
// Created by 李伯坤 on 2018/1/4.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import "TLExpressionDetailBannerCell.h"
@interface TLExpressionDetailBannerCell ()
@property (nonatomic, strong) UIImageView *imageView;
@end
@implementation TLExpressionDetailBannerCell
+ (CGSize)viewSizeByDataModel:(id)dataModel
{
return CGSizeMake(SCREEN_WIDTH, SCREEN_WIDTH * 0.45);
}
- (void)setViewDataModel:(NSString *)dataModel
{
if (dataModel) {
[self.imageView tt_setImageWithURL:TLURL(dataModel)];
}
else {
[self.imageView setImage:nil];
}
}
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self setBackgroundColor:[UIColor whiteColor]];
self.imageView = self.addImageView(1)
.clipsToBounds(YES)
.contentMode(UIViewContentModeScaleAspectFill)
.masonry(^(MASConstraintMaker *make){
make.edges.mas_equalTo(0);
})
.view;
}
return self;
}
@end
@@ -0,0 +1,18 @@
//
// TLExpressionDetailInfoCell.h
// TLChat
//
// Created by 李伯坤 on 16/4/11.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TLExpressionGroupModel.h"
#define HEIGHT_EXP_BANNER (SCREEN_WIDTH * 0.45)
@interface TLExpressionDetailInfoCell : UICollectionViewCell <ZZFlexibleLayoutViewProtocol>
@property (nonatomic, strong) TLExpressionGroupModel *groupModel;
@end
@@ -0,0 +1,137 @@
//
// TLExpressionDetailInfoCell.m
// TLChat
//
// Created by 李伯坤 on 16/4/11.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLExpressionDetailInfoCell.h"
#import "TLExpressionGroupModel+Download.h"
#import "TLExpressionDownloadButton.h"
@interface TLExpressionDetailInfoCell ()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) TLExpressionDownloadButton *downloadButton;
@property (nonatomic, strong) UILabel *detailLabel;
@end
@implementation TLExpressionDetailInfoCell
+ (CGSize)viewSizeByDataModel:(TLExpressionGroupModel *)group
{
CGFloat detailHeight = [group.detail boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 30, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:13.0f]} context:nil].size.height;
CGFloat height = 85.0 + detailHeight;
return CGSizeMake(SCREEN_WIDTH, height);
}
- (void)setViewDataModel:(id)dataModel
{
[self setGroupModel:dataModel];
}
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self.contentView addSubview:self.titleLabel];
[self.contentView addSubview:self.downloadButton];
[self.contentView addSubview:self.detailLabel];
[self p_addMasonry];
}
return self;
}
- (void)setGroupModel:(TLExpressionGroupModel *)groupModel
{
_groupModel = groupModel;
[self.titleLabel setText:groupModel.name];
[self.detailLabel setText:groupModel.detail];
if (groupModel.status == TLExpressionGroupStatusLocal) {
[self.downloadButton setStatus:TLExpressionDownloadButtonStatusDownloaded];
}
else if (groupModel.status == TLExpressionGroupStatusDownloading) {
[self.downloadButton setStatus:TLExpressionDownloadButtonStatusDownloading];
}
else {
[self.downloadButton setStatus:TLExpressionDownloadButtonStatusNet];
}
@weakify(self);
[self.downloadButton setProgress:groupModel.downloadProgress];
[groupModel setDownloadProgressAction:^(TLExpressionGroupModel *groupModel, CGFloat progress) {
@strongify(self);
[self.downloadButton setProgress:progress];
}];
[groupModel setDownloadCompleteAction:^(TLExpressionGroupModel *groupModel, BOOL success, id data) {
@strongify(self);
[self setGroupModel:groupModel];
}];
}
#pragma mark - # Private Methods
- (void)p_addMasonry
{
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(25.0f);
make.left.mas_equalTo(15.0f);
make.right.mas_lessThanOrEqualTo(self.downloadButton.mas_right).mas_offset(-15);
}];
[self.downloadButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.titleLabel).mas_offset(-3);
make.right.mas_equalTo(self.contentView).mas_offset(-15.0f);
make.size.mas_equalTo(CGSizeMake(83, 30));
}];
[self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.titleLabel);
make.right.mas_equalTo(self.contentView).mas_offset(-15);
make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(20);
}];
}
#pragma mark - # Getter
- (UILabel *)titleLabel
{
if (_titleLabel == nil) {
_titleLabel = [[UILabel alloc] init];
[_titleLabel setBackgroundColor:[UIColor whiteColor]];
[_titleLabel setClipsToBounds:YES];
}
return _titleLabel;
}
- (TLExpressionDownloadButton *)downloadButton
{
if (_downloadButton == nil) {
_downloadButton = [[TLExpressionDownloadButton alloc] init];
@weakify(self);
[_downloadButton setDownloadButtonClick:^{
@strongify(self);
if (self.groupModel.status == TLExpressionGroupStatusNet) {
[self.groupModel startDownload];
[self setGroupModel:self.groupModel];
}
}];
}
return _downloadButton;
}
- (UILabel *)detailLabel
{
if (_detailLabel == nil) {
_detailLabel = [[UILabel alloc] init];
[_detailLabel setBackgroundColor:[UIColor whiteColor]];
[_detailLabel setClipsToBounds:YES];
[_detailLabel setFont:[UIFont systemFontOfSize:13.0f]];
[_detailLabel setTextColor:[UIColor grayColor]];
[_detailLabel setNumberOfLines:0];
}
return _detailLabel;
}
@end
@@ -0,0 +1,20 @@
//
// TLExpressionDetailItemCell.h
// TLChat
//
// Created by 李伯坤 on 16/4/8.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TLExpressionModel.h"
#define EXP_DETAIL_EDGE 20.0
#define EXP_DETAIL_SPACE 15.0
#define EXP_DETAIL_CELL_WIDTH MIN(((SCREEN_WIDTH - EXP_DETAIL_EDGE * 2 - EXP_DETAIL_SPACE * 3.0) / 4.0), 84)
@interface TLExpressionDetailItemCell : UICollectionViewCell <ZZFlexibleLayoutViewProtocol>
@property (nonatomic, strong) TLExpressionModel *emoji;
@end
@@ -0,0 +1,57 @@
//
// TLExpressionDetailItemCell.m
// TLChat
//
// Created by 李伯坤 on 16/4/8.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLExpressionDetailItemCell.h"
#import <SDWebImage/UIImage+GIF.h>
#import "UIImage+Color.h"
@interface TLExpressionDetailItemCell ()
@property (nonatomic, strong) UIImageView *imageView;
@end
@implementation TLExpressionDetailItemCell
+ (CGSize)viewSizeByDataModel:(id)dataModel
{
return CGSizeMake(EXP_DETAIL_CELL_WIDTH, EXP_DETAIL_CELL_WIDTH);
}
- (void)setViewDataModel:(id)dataModel
{
[self setEmoji:dataModel];
}
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.imageView = self.contentView.addImageView(1)
.cornerRadius(3.0f)
.masonry(^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.contentView);
})
.view;
}
return self;
}
- (void)setEmoji:(TLExpressionModel *)emoji
{
_emoji = emoji;
UIImage *image = [UIImage imageNamed:emoji.path];
if (image) {
[self.imageView setImage:image];
}
else {
[self.imageView tt_setImageWithURL:TLURL(emoji.url)];
}
}
@end
@@ -0,0 +1,13 @@
//
// TLExpressionDetailSeperatorCell.h
// TLChat
//
// Created by 李伯坤 on 2018/1/4.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLExpressionDetailSeperatorCell : UICollectionViewCell <ZZFlexibleLayoutViewProtocol>
@end
@@ -0,0 +1,52 @@
//
// TLExpressionDetailSeperatorCell.m
// TLChat
//
// Created by 李伯坤 on 2018/1/4.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import "TLExpressionDetailSeperatorCell.h"
@implementation TLExpressionDetailSeperatorCell
+ (CGSize)viewSizeByDataModel:(id)dataModel
{
return CGSizeMake(SCREEN_WIDTH, 20);
}
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self p_initUI];
}
return self;
}
- (void)p_initUI
{
UIView *line1 = self.contentView.addView(1).backgroundColor([UIColor colorGrayLine]).view;
UIView *line2 = self.contentView.addView(2).backgroundColor([UIColor colorGrayLine]).view;
UILabel *label = self.contentView.addLabel(3)
.backgroundColor([UIColor whiteColor]).clipsToBounds(YES)
.textColor([UIColor colorGrayLine]).font([UIFont systemFontOfSize:12.0f])
.text(LOCSTR(@"长按表情可预览")).view;
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(-5.0f);
make.left.mas_equalTo(line1.mas_right).mas_offset(5.0f);
make.right.mas_equalTo(line2.mas_left).mas_offset(-5.0f);
}];
[line1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(BORDER_WIDTH_1PX);
make.left.mas_equalTo(15.0f);
make.centerY.mas_equalTo(label);
make.width.mas_equalTo(line2);
}];
[line2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(BORDER_WIDTH_1PX);
make.right.mas_equalTo(-15.0f);
make.centerY.mas_equalTo(label);
}];
}
@end
@@ -0,0 +1,15 @@
//
// TLExpressionGroupModel+Download.h
// TLChat
//
// Created by 李伯坤 on 2018/1/2.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import "TLExpressionGroupModel.h"
@interface TLExpressionGroupModel (Download)
- (void)startDownload;
@end
@@ -0,0 +1,72 @@
//
// TLExpressionGroupModel+Download.m
// TLChat
//
// Created by 李伯坤 on 2018/1/2.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import "TLExpressionGroupModel+Download.h"
#import "TLExpressionGroupModel+DetailRequest.h"
#import "TLExpressionHelper.h"
#import "NSFileManager+TLChat.h"
@implementation TLExpressionGroupModel (Download)
- (void)startDownload
{
self.status = TLExpressionGroupStatusDownloading;
if (self.data.count == 0) {
self.data = @[].mutableCopy;
[self requestDetailInfoWithPageIndex:1];
}
else {
[self p_startDownload];
}
}
- (void)requestDetailInfoWithPageIndex:(NSInteger)pageIndex
{
[self requestExpressionGroupDetailByPageIndex:pageIndex success:^(NSArray *successData) {
if (successData.count > 0) {
[self.data addObjectsFromArray:successData];
[self p_startDownload];
}
else {
self.status = TLExpressionGroupStatusNet;
if (self.downloadCompleteAction) {
self.downloadCompleteAction(self, NO, @"表情包数据错误");
}
}
} failure:^(id failureData) {
self.status = TLExpressionGroupStatusNet;
if (self.downloadCompleteAction) {
self.downloadCompleteAction(self, NO, @"获取表情包信息失败");
}
}];
}
- (void)p_startDownload
{
[[TLExpressionHelper sharedHelper] downloadExpressionsWithGroupInfo:self progress:^(CGFloat progress) {
self.downloadProgress = progress;
if (self.downloadProgressAction) {
self.downloadProgressAction(self, progress);
}
} success:^(TLExpressionGroupModel *group) {
self.status = TLExpressionGroupStatusLocal;
[[TLExpressionHelper sharedHelper] addExpressionGroup:group];
if (self.downloadCompleteAction) {
self.downloadCompleteAction(group, YES, nil);
}
} failure:^(TLExpressionGroupModel *group, NSString *error) {
self.status = TLExpressionGroupStatusNet;
if (self.downloadCompleteAction) {
self.downloadCompleteAction(group, NO, error);
}
}];
}
@end
@@ -0,0 +1,62 @@
//
// TLDBExpressionSQL.h
// TLChat
//
// Created by 李伯坤 on 16/4/9.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#ifndef TLDBExpressionSQL_h
#define TLDBExpressionSQL_h
#pragma mark - # 表情组
#define EXP_GROUP_TABLE_NAME @"expression_group"
#define SQL_CREATE_EXP_GROUP_TABLE @"CREATE TABLE IF NOT EXISTS %@(\
uid TEXT,\
gid TEXT,\
type INTEGER DEFAULT (0), \
name TEXT,\
desc TEXT,\
detail TEXT,\
count INTEGER DEFAULT (0), \
auth_id TEXT,\
auth_name TEXT,\
date TEXT,\
ext1 TEXT,\
ext2 TEXT,\
ext3 TEXT,\
ext4 TEXT,\
ext5 TEXT,\
PRIMARY KEY(uid, gid))"
#define SQL_ADD_EXP_GROUP @"REPLACE INTO %@ ( uid, gid, type, name, desc, detail, count, auth_id, auth_name, date, ext1, ext2, ext3, ext4, ext5) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"
#define SQL_SELECT_EXP_GROUP @"SELECT * FROM %@ WHERE uid = '%@' order by date desc"
#define SQL_DELETE_EXP_GROUP @"DELETE FROM %@ WHERE uid = '%@' and gid = '%@'"
#define SQL_SELECT_COUNT_EXP_GROUP_USERS @"SELECT count(uid) FROM %@ WHERE gid = '%@'"
#pragma mark - # 表情
#define EXPS_TABLE_NAME @"expressions"
#define SQL_CREATE_EXPS_TABLE @"CREATE TABLE IF NOT EXISTS %@(\
gid TEXT,\
eid TEXT, \
name TEXT,\
ext1 TEXT,\
ext2 TEXT,\
ext3 TEXT,\
ext4 TEXT,\
ext5 TEXT,\
PRIMARY KEY(gid, eid))"
#define SQL_ADD_EXP @"REPLACE INTO %@ ( gid, eid, name, ext1, ext2, ext3, ext4, ext5) VALUES ( ?, ?, ?, ?, ?, ?, ?, ? )"
#define SQL_SELECT_EXPS @"SELECT * FROM %@ WHERE gid = '%@'"
#endif /* TLDBExpressionSQL_h */
@@ -0,0 +1,35 @@
//
// TLDBExpressionStore.h
// TLChat
//
// Created by 李伯坤 on 16/4/9.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLDBBaseStore.h"
#import "TLExpressionGroupModel.h"
@interface TLDBExpressionStore : TLDBBaseStore
/**
* 添加表情包
*/
- (BOOL)addExpressionGroup:(TLExpressionGroupModel *)group forUid:(NSString *)uid;
/**
* 查询所有表情包
*/
- (NSArray *)expressionGroupsByUid:(NSString *)uid;
/**
* 删除表情包
*/
- (BOOL)deleteExpressionGroupByID:(NSString *)gid forUid:(NSString *)uid;
/**
* 拥有某表情包的用户数
*/
- (NSInteger)countOfUserWhoHasExpressionGroup:(NSString *)gid;
@end
@@ -0,0 +1,151 @@
//
// TLDBExpressionStore.m
// TLChat
//
// Created by 李伯坤 on 16/4/9.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLDBExpressionStore.h"
#import "TLDBExpressionSQL.h"
#import "TLDBManager.h"
#import "TLMacros.h"
@implementation TLDBExpressionStore
- (id)init
{
if (self = [super init]) {
self.dbQueue = [TLDBManager sharedInstance].commonQueue;
BOOL ok = [self createTable];
if (!ok) {
DDLogError(@"DB: 聊天记录表创建失败");
}
}
return self;
}
- (BOOL)createTable
{
NSString *sqlString = [NSString stringWithFormat:SQL_CREATE_EXP_GROUP_TABLE, EXP_GROUP_TABLE_NAME];
BOOL ok = [self createTable:EXP_GROUP_TABLE_NAME withSQL:sqlString];
if (!ok) {
return NO;
}
sqlString = [NSString stringWithFormat:SQL_CREATE_EXPS_TABLE, EXPS_TABLE_NAME];
ok = [self createTable:EXPS_TABLE_NAME withSQL:sqlString];
return ok;
}
#pragma mark - # 表情组
- (BOOL)addExpressionGroup:(TLExpressionGroupModel *)group forUid:(NSString *)uid
{
// 添加表情包
NSString *sqlString = [NSString stringWithFormat:SQL_ADD_EXP_GROUP, EXP_GROUP_TABLE_NAME];
NSArray *arr = [NSArray arrayWithObjects:
uid,
group.gId,
[NSNumber numberWithInteger:group.type],
TLNoNilString(group.name),
TLNoNilString(group.groupInfo),
TLNoNilString(group.detail),
[NSNumber numberWithInteger:group.count],
TLNoNilString(group.authID),
TLNoNilString(group.authName),
TLTimeStamp(group.date),
@"", @"", @"", @"", @"", nil];
BOOL ok = [self excuteSQL:sqlString withArrParameter:arr];
if (!ok) {
return NO;
}
// 添加表情包里的所有表情
ok = [self addExpressions:group.data toGroupID:group.gId];
return ok;
}
- (NSArray *)expressionGroupsByUid:(NSString *)uid
{
__block NSMutableArray *data = [[NSMutableArray alloc] init];
NSString *sqlString = [NSString stringWithFormat: SQL_SELECT_EXP_GROUP, EXP_GROUP_TABLE_NAME, uid];
// 读取表情包信息
[self excuteQuerySQL:sqlString resultBlock:^(FMResultSet *retSet) {
while ([retSet next]) {
TLExpressionGroupModel *group = [[TLExpressionGroupModel alloc] init];
group.gId = [retSet stringForColumn:@"gid"];
group.type = [retSet intForColumn:@"type"];
group.name = [retSet stringForColumn:@"name"];
group.groupInfo = [retSet stringForColumn:@"desc"];
group.detail = [retSet stringForColumn:@"detail"];
group.count = [retSet intForColumn:@"count"];
group.authID = [retSet stringForColumn:@"auth_id"];
group.authName = [retSet stringForColumn:@"auth_name"];
group.status = TLExpressionGroupStatusLocal;
[data addObject:group];
}
[retSet close];
}];
// 读取表情包的所有表情信息
for (TLExpressionGroupModel *group in data) {
group.data = [self expressionsForGroupID:group.gId];
}
return data;
}
- (BOOL)deleteExpressionGroupByID:(NSString *)gid forUid:(NSString *)uid
{
NSString *sqlString = [NSString stringWithFormat:SQL_DELETE_EXP_GROUP, EXP_GROUP_TABLE_NAME, uid, gid];
return [self excuteSQL:sqlString, nil];
}
- (NSInteger)countOfUserWhoHasExpressionGroup:(NSString *)gid
{
NSString *sqlString = [NSString stringWithFormat:SQL_SELECT_COUNT_EXP_GROUP_USERS, EXP_GROUP_TABLE_NAME, gid];
__block NSInteger count = 0;
[self.dbQueue inDatabase:^(FMDatabase *db) {
count = [db intForQuery:sqlString];
}];
return count;
}
#pragma mark - # 表情
- (BOOL)addExpressions:(NSArray *)expressions toGroupID:(NSString *)groupID
{
for (TLExpressionModel *emoji in expressions) {
NSString *sqlString = [NSString stringWithFormat:SQL_ADD_EXP, EXPS_TABLE_NAME];
NSArray *arr = [NSArray arrayWithObjects:
groupID,
emoji.eId,
TLNoNilString(emoji.name),
@"", @"", @"", @"", @"", nil];
BOOL ok = [self excuteSQL:sqlString withArrParameter:arr];
if (!ok) {
return NO;
}
}
return YES;
}
- (NSMutableArray *)expressionsForGroupID:(NSString *)groupID
{
__block NSMutableArray *data = [[NSMutableArray alloc] init];
NSString *sqlString = [NSString stringWithFormat: SQL_SELECT_EXPS, EXPS_TABLE_NAME, groupID];
[self excuteQuerySQL:sqlString resultBlock:^(FMResultSet *retSet) {
while ([retSet next]) {
TLExpressionModel *emoji = [[TLExpressionModel alloc] init];
emoji.gid = [retSet stringForColumn:@"gid"];
emoji.eId = [retSet stringForColumn:@"eid"];
emoji.name = [retSet stringForColumn:@"name"];
[data addObject:emoji];
}
[retSet close];
}];
return data;
}
@end
@@ -0,0 +1,54 @@
//
// TLExpressionHelper.h
// TLChat
//
// Created by 李伯坤 on 16/3/11.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "TLExpressionGroupModel.h"
@interface TLExpressionHelper : NSObject
/// 默认表情(Face
@property (nonatomic, strong, readonly) TLExpressionGroupModel *defaultFaceGroup;
/// 默认系统Emoji
@property (nonatomic, strong, readonly) TLExpressionGroupModel *defaultSystemEmojiGroup;
/// 用户表情组
@property (nonatomic, strong, readonly) NSArray *userEmojiGroups;
/// 用户收藏的表情
@property (nonatomic, strong, readonly) TLExpressionGroupModel *userPreferEmojiGroup;
+ (TLExpressionHelper *)sharedHelper;
/**
* 根据groupID获取表情包
*/
- (TLExpressionGroupModel *)emojiGroupByID:(NSString *)groupID;
/**
* 添加表情包
*/
- (BOOL)addExpressionGroup:(TLExpressionGroupModel *)emojiGroup;
/**
* 删除表情包
*/
- (BOOL)deleteExpressionGroupByID:(NSString *)groupID;
- (void)updateExpressionGroupModelsStatus:(NSArray *)groupModelArray;
#pragma mark - 下载表情包
- (void)downloadExpressionsWithGroupInfo:(TLExpressionGroupModel *)group
progress:(void (^)(CGFloat progress))progress
success:(void (^)(TLExpressionGroupModel *group))success
failure:(void (^)(TLExpressionGroupModel *group, NSString *error))failure;
@end
@@ -0,0 +1,178 @@
//
// TLExpressionHelper.m
// TLChat
//
// Created by 李伯坤 on 16/3/11.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLExpressionHelper.h"
#import "TLDBExpressionStore.h"
#import "TLEmojiKBHelper.h"
#import "TLUserHelper.h"
#import "NSFileManager+TLChat.h"
@interface TLExpressionHelper ()
@property (nonatomic, strong) TLDBExpressionStore *store;
@end
@implementation TLExpressionHelper
@synthesize defaultFaceGroup = _defaultFaceGroup;
@synthesize defaultSystemEmojiGroup = _defaultSystemEmojiGroup;
@synthesize userEmojiGroups = _userEmojiGroups;
+ (TLExpressionHelper *)sharedHelper
{
static TLExpressionHelper *helper;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
helper = [[TLExpressionHelper alloc] init];
});
return helper;
}
- (NSArray *)userEmojiGroups
{
return [self.store expressionGroupsByUid:[TLUserHelper sharedHelper].userID];
}
- (BOOL)addExpressionGroup:(TLExpressionGroupModel *)emojiGroup
{
BOOL ok = [self.store addExpressionGroup:emojiGroup forUid:[TLUserHelper sharedHelper].userID];
if (ok) { // 通知表情键盘
[[TLEmojiKBHelper sharedKBHelper] updateEmojiGroupData];
}
return ok;
}
- (BOOL)deleteExpressionGroupByID:(NSString *)groupID
{
TLExpressionGroupModel *groupModel = [self emojiGroupByID:groupID];
BOOL ok = [self.store deleteExpressionGroupByID:groupID forUid:[TLUserHelper sharedHelper].userID];
if (ok) { // 通知表情键盘
[[TLEmojiKBHelper sharedKBHelper] updateEmojiGroupData];
BOOL canDeleteFile = ![self didExpressionGroupAlwaysInUsed:groupID];
if (canDeleteFile) {
NSError *error;
ok = [[NSFileManager defaultManager] removeItemAtPath:groupModel.path error:&error];
if (!ok) {
DDLogError(@"删除表情文件失败\n路径:%@\n原因:%@", groupModel.path, [error description]);
}
}
}
return ok;
}
- (BOOL)didExpressionGroupAlwaysInUsed:(NSString *)groupID
{
NSInteger count = [self.store countOfUserWhoHasExpressionGroup:groupID];
return count > 0;
}
- (TLExpressionGroupModel *)emojiGroupByID:(NSString *)groupID;
{
for (TLExpressionGroupModel *group in self.userEmojiGroups) {
if ([group.gId isEqualToString:groupID]) {
return group;
}
}
return nil;
}
- (void)downloadExpressionsWithGroupInfo:(TLExpressionGroupModel *)group
progress:(void (^)(CGFloat))progress
success:(void (^)(TLExpressionGroupModel *))success
failure:(void (^)(TLExpressionGroupModel *, NSString *))failure
{
group.type = TLEmojiTypeImageWithTitle;
dispatch_queue_t downloadQueue = dispatch_queue_create([group.gId UTF8String], nil);
dispatch_group_t downloadGroup = dispatch_group_create();
__block CGFloat p = 0;
for (int i = 0; i <= group.data.count; i++) {
dispatch_group_async(downloadGroup, downloadQueue, ^{
NSString *groupPath = [NSFileManager pathExpressionForGroupID:group.gId];
NSString *emojiPath;
NSData *data = nil;
if (i == group.data.count) {
emojiPath = [NSString stringWithFormat:@"%@icon_%@", groupPath, group.gId];
data = [NSData dataWithContentsOfURL:TLURL(group.iconURL)];
}
else {
TLExpressionModel *emoji = group.data[i];
NSString *urlString = [TLExpressionModel expressionDownloadURLWithEid:emoji.eId];
data = [NSData dataWithContentsOfURL:TLURL(urlString)];
if (data == nil) {
urlString = [TLExpressionModel expressionURLWithEid:emoji.eId];
data = [NSData dataWithContentsOfURL:TLURL(urlString)];
}
emojiPath = [NSString stringWithFormat:@"%@%@", groupPath, emoji.eId];
}
[data writeToFile:emojiPath atomically:YES];
p += 1.0;
dispatch_async(dispatch_get_main_queue(), ^{
if (progress) {
progress(p / group.data.count);
}
});
});
}
dispatch_group_notify(downloadGroup, dispatch_get_main_queue(), ^{
success(group);
});
}
- (void)updateExpressionGroupModelsStatus:(NSArray *)groupModelArray
{
for (TLExpressionGroupModel *group in groupModelArray) {
TLExpressionGroupModel *localEmojiGroup = [[TLExpressionHelper sharedHelper] emojiGroupByID:group.gId];
if (localEmojiGroup) {
group.status = TLExpressionGroupStatusLocal;
}
}
}
#pragma mark - # Getter
- (TLDBExpressionStore *)store
{
if (_store == nil) {
_store = [[TLDBExpressionStore alloc] init];
}
return _store;
}
- (TLExpressionGroupModel *)defaultFaceGroup
{
if (_defaultFaceGroup == nil) {
_defaultFaceGroup = [[TLExpressionGroupModel alloc] init];
_defaultFaceGroup.type = TLEmojiTypeFace;
_defaultFaceGroup.iconPath = @"emojiKB_group_face";
NSString *path = [[NSBundle mainBundle] pathForResource:@"FaceEmoji" ofType:@"json"];
NSData *data = [NSData dataWithContentsOfFile:path];
_defaultFaceGroup.data = [TLExpressionModel mj_objectArrayWithKeyValuesArray:data];
for (TLExpressionModel *emoji in _defaultFaceGroup.data) {
emoji.type = TLEmojiTypeFace;
}
}
return _defaultFaceGroup;
}
- (TLExpressionGroupModel *)defaultSystemEmojiGroup
{
if (_defaultSystemEmojiGroup == nil) {
_defaultSystemEmojiGroup = [[TLExpressionGroupModel alloc] init];
_defaultSystemEmojiGroup.type = TLEmojiTypeEmoji;
_defaultSystemEmojiGroup.iconPath = @"emojiKB_group_face";
NSString *path = [[NSBundle mainBundle] pathForResource:@"SystemEmoji" ofType:@"json"];
NSData *data = [NSData dataWithContentsOfFile:path];
_defaultSystemEmojiGroup.data = [TLExpressionModel mj_objectArrayWithKeyValuesArray:data];
}
return _defaultSystemEmojiGroup;
}
@end
@@ -0,0 +1,18 @@
//
// TLExpressionGroupModel+SearchRequest.h
// TLChat
//
// Created by 李伯坤 on 2018/1/2.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import "TLExpressionGroupModel.h"
@interface TLExpressionGroupModel (SearchRequest)
/**
* 表情搜索
*/
+ (TLBaseRequest *)requestExpressionSearchByKeyword:(NSString *)keyword success:(TLRequestSuccessBlock)success failure:(TLRequestFailureBlock)failure;
@end
@@ -0,0 +1,43 @@
//
// TLExpressionGroupModel+SearchRequest.m
// TLChat
//
// Created by 李伯坤 on 2018/1/2.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import "TLExpressionGroupModel+SearchRequest.h"
#import "TLNetworking.h"
#define IEXPRESSION_SEARCH_URL [IEXPRESSION_HOST_URL stringByAppendingString:@"expre/listBy.do?pageNumber=1&status=Y&eName=%@&seach=yes"]
@implementation TLExpressionGroupModel (SearchRequest)
+ (TLBaseRequest *)requestExpressionSearchByKeyword:(NSString *)keyword success:(TLRequestSuccessBlock)success failure:(TLRequestFailureBlock)failure
{
NSString *urlString = [NSString stringWithFormat:IEXPRESSION_SEARCH_URL, [[keyword urlEncode] urlEncode]];
[TLNetworking postUrl:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
NSArray *respArray = [responseObject mj_JSONObject];
NSString *status = respArray[0];
if ([status isEqualToString:@"OK"]) {
NSArray *infoArray = respArray[2];
NSMutableArray *data = [TLExpressionGroupModel mj_objectArrayWithKeyValuesArray:infoArray];
if (success) {
success(data);
}
}
else {
if (failure) {
failure(status);
}
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure(TLNetworkErrorTip);
}
}];
return nil;
}
@end
@@ -0,0 +1,16 @@
//
// TLExpressionSearchResultViewController.h
// TLChat
//
// Created by 李伯坤 on 16/4/4.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLViewController.h"
#import "TLSearchResultControllerProtocol.h"
@interface TLExpressionSearchResultViewController : TLViewController <TLSearchResultControllerProtocol>
@property (nonatomic, copy) void (^itemClickAction)(TLExpressionSearchResultViewController *searchController, id data);
@end
@@ -0,0 +1,118 @@
//
// TLExpressionSearchResultViewController.m
// TLChat
//
// Created by 李伯坤 on 16/4/4.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLExpressionSearchResultViewController.h"
#import "TLExpressionDetailViewController.h"
#import "TLExpressionGroupModel+SearchRequest.h"
#define HEGIHT_EXPCELL 80
typedef NS_ENUM(NSInteger, TLExpressionSearchVCSectionType) {
TLExpressionSearchVCSectionTypeItems,
};
@interface TLExpressionSearchResultViewController ()
/// 列表
@property (nonatomic, strong) UITableView *tableView;
/// 列表管理器
@property (nonatomic, strong) ZZFLEXAngel *tableViewAngel;
@end
@implementation TLExpressionSearchResultViewController
- (void)loadView
{
[super loadView];
[self setStatusBarStyle:UIStatusBarStyleDefault];
self.tableView = self.view.addTableView(1)
.tableHeaderView([UIView new])
.separatorStyle(UITableViewCellSeparatorStyleNone)
.estimatedRowHeight(0).estimatedSectionFooterHeight(0).estimatedSectionHeaderHeight(0)
.masonry(^ (MASConstraintMaker *make) {
make.edges.mas_equalTo(0);
})
.view;
self.tableViewAngel = [[ZZFLEXAngel alloc] initWithHostView:self.tableView];
}
#pragma mark - # Request
- (void)requsetSearchExpressionGroupWithKeyword:(NSString *)keyword
{
[TLUIUtility showLoading:nil];
@weakify(self);
[TLExpressionGroupModel requestExpressionSearchByKeyword:keyword success:^(NSArray *data) {
[TLUIUtility hiddenLoading];
if (data.count > 0) {
[self p_reloadViewWithData:data];
}
else {
[self p_reloadViewWithData:nil];
[self.tableView showEmptyViewWithTitle:@"未搜索到相关表情包"];
}
} failure:^(NSString *error) {
[TLUIUtility showErrorHint:error];
[self p_reloadViewWithData:nil];
[self.tableView showErrorViewWithTitle:error retryAction:^(id userData) {
@strongify(self);
[self requsetSearchExpressionGroupWithKeyword:keyword];
}];
}];
}
#pragma mark - # Delegate
//MARK: UISearchBarDelegate
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[self.tableView removeTipView];
NSString *keyword = searchBar.text;
if (keyword.length > 0) {
[self requsetSearchExpressionGroupWithKeyword:keyword];
}
}
//MARK: UISearchControllerDelegate
- (void)willPresentSearchController:(UISearchController *)searchController;
{
[self p_clearView];
}
//MARK: UISearchResultsUpdating
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController {
NSString *keyword = searchController.searchBar.text;
if (keyword.length == 0) {
[self p_clearView];
}
}
#pragma mark - # Private Methods
- (void)p_clearView
{
[self.tableView removeTipView];
self.tableViewAngel.clear();
self.tableViewAngel.addSection(TLExpressionSearchVCSectionTypeItems);
[self.tableView reloadData];
}
- (void)p_reloadViewWithData:(NSArray *)data
{
@weakify(self);
self.tableViewAngel.sectionForTag(TLExpressionSearchVCSectionTypeItems).clear();
self.tableViewAngel.addCells(@"TLExpressionItemCell").toSection(TLExpressionSearchVCSectionTypeItems).withDataModelArray(data).selectedAction(^ (TLExpressionGroupModel *model) {
@strongify(self);
if (self.itemClickAction) {
self.itemClickAction(self, model);
}
});
[self.tableView reloadData];
}
@end
@@ -0,0 +1,30 @@
//
// TLExpressionGroupModel+ChosenRequest.h
// TLChat
//
// Created by 李伯坤 on 2018/1/2.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import "TLExpressionGroupModel.h"
#import "TLPictureCarouselProtocol.h"
@interface TLExpressionGroupModel (ChosenRequest)
/**
* 表情精选 - Banner
*/
+ (TLBaseRequest *)requestExpressionChosenBannerSuccess:(TLRequestSuccessBlock)success failure:(TLRequestFailureBlock)failure;
/**
* 表情精选 - 推荐模块
*/
+ (void)requestExpressionRecommentListSuccess:(TLRequestSuccessBlock)success failure:(TLRequestFailureBlock)failure;
/**
* 表情精选 - 更多模块
*/
+ (TLBaseRequest *)requestExpressionChosenListByPageIndex:(NSInteger)page success:(TLRequestSuccessBlock)success failure:(TLRequestFailureBlock)failure;
@end
@@ -0,0 +1,141 @@
//
// TLExpressionGroupModel+ChosenRequest.m
// TLChat
//
// Created by 李伯坤 on 2018/1/2.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import "TLExpressionGroupModel+ChosenRequest.h"
#import "TLNetworking.h"
#define IEXPRESSION_BANNER_URL [IEXPRESSION_HOST_URL stringByAppendingString: @"/advertisement/getAll.do?status=on&versionNumber=2.5.0"]
#define IEXPRESSION_NEW_URL [IEXPRESSION_HOST_URL stringByAppendingString:@"expre/listBy.do?pageNumber=%ld&status=Y&status1=B"]
@implementation TLExpressionGroupModel (ChosenRequest)
+ (TLBaseRequest *)requestExpressionChosenBannerSuccess:(TLRequestSuccessBlock)success failure:(TLRequestFailureBlock)failure
{
NSString *urlString = IEXPRESSION_BANNER_URL;
[TLNetworking postUrl:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
NSArray *respArray = [responseObject mj_JSONObject];
NSString *status = respArray[0];
if ([status isEqualToString:@"OK"]) {
NSArray *infoArray = respArray[2];
NSMutableArray *data = [TLExpressionGroupModel mj_objectArrayWithKeyValuesArray:infoArray];
if (success) {
success(data);
}
}
else {
if (failure) {
failure(status);
}
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure(TLNetworkErrorTip);
}
}];
// TLBaseRequest *request = [TLBaseRequest requestWithMethod:TLRequestMethodPOST url:IEXPRESSION_BANNER_URL parameters:nil];
// [request startRequestWithSuccessAction:^(TLResponse *response) {
// NSArray *respArray = [response.responseData mj_JSONObject];
// NSString *status = respArray[0];
// if ([status isEqualToString:@"OK"]) {
// NSArray *infoArray = respArray[2];
// NSMutableArray *data = [TLExpressionGroupModel mj_objectArrayWithKeyValuesArray:infoArray];
// if (success) {
// success(data);
// }
// }
// else {
// if (failure) {
// failure(status);
// }
// }
// } failureAction:^(TLResponse *response) {
// if (failure) {
// failure(TLNetworkErrorTip);
// }
// }];
// return request;
return nil;
}
+ (TLBaseRequest *)requestExpressionChosenListByPageIndex:(NSInteger)page success:(TLRequestSuccessBlock)success failure:(TLRequestFailureBlock)failure
{
NSString *urlString = [NSString stringWithFormat:IEXPRESSION_NEW_URL, (long)page];
[TLNetworking postUrl:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
NSArray *respArray = [responseObject mj_JSONObject];
NSString *status = respArray[0];
if ([status isEqualToString:@"OK"]) {
NSArray *infoArray = respArray[2];
NSMutableArray *data = [TLExpressionGroupModel mj_objectArrayWithKeyValuesArray:infoArray];
if (success) {
success(data);
}
}
else {
if (failure) {
failure(status);
}
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure(TLNetworkErrorTip);
}
}];
// NSString *urlString = [NSString stringWithFormat:IEXPRESSION_NEW_URL, (long)page];
// TLBaseRequest *request = [TLBaseRequest requestWithMethod:TLRequestMethodPOST url:urlString parameters:nil];
// [request startRequestWithSuccessAction:^(TLResponse *response) {
// NSArray *respArray = [response.responseData mj_JSONObject];
// NSString *status = respArray[0];
// if ([status isEqualToString:@"OK"]) {
// NSArray *infoArray = respArray[2];
// NSMutableArray *data = [TLExpressionGroupModel mj_objectArrayWithKeyValuesArray:infoArray];
// if (success) {
// success(data);
// }
// }
// else {
// if (failure) {
// failure(status);
// }
// }
// } failureAction:^(TLResponse *response) {
// if (failure) {
// failure(TLNetworkErrorTip);
// }
// }];
return nil;
}
+ (void)requestExpressionRecommentListSuccess:(TLRequestSuccessBlock)success failure:(TLRequestFailureBlock)failure
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSArray *jsonArray = @[@{@"eId" : @"241",
@"eName" : @"婉转的骂人",
@"memo1" : @"杀伤力较大,慎用慎用。。。",
@"coverUrl" : @"http://cdn.ibiaoqing.com:80/ibiaoqing/admin/expre/downloadsuo.do?pId=10790",
@"picCount" : @(9).stringValue},
@{@"eId" : @"223",
@"eName" : @"王锡玄",
@"memo1" : @"韩国萌娃,冷笑宝宝王锡玄表情包",
@"coverUrl" : @"http://cdn.ibiaoqing.com:80/ibiaoqing/admin/expre/downloadsuo.do?pId=10482",
@"picCount" : @(12).stringValue},
@{@"eId" : @"117",
@"eName" : @"克里斯蒂娜",
@"memo1" : @"Cristina Fernandez Lee 混血小美女 克里斯提娜 gif 可爱 萌娃",
@"coverUrl" : @"http://cdn.ibiaoqing.com:80/ibiaoqing/admin/expre/downloadsuo.do?pId=6637",
@"picCount" : @(21).stringValue}];
NSArray *data = [TLExpressionGroupModel mj_objectArrayWithKeyValuesArray:jsonArray];
if (success) {
success(data);
}
});
}
@end
@@ -0,0 +1,13 @@
//
// TLExpressionChosenAngel.h
// TLChat
//
// Created by 李伯坤 on 2018/1/2.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import <ZZFLEX/ZZFLEXAngel+UITableView.h>
@interface TLExpressionChosenAngel : ZZFLEXAngel <UITableViewDelegate>
@end
@@ -0,0 +1,25 @@
//
// TLExpressionChosenAngel.m
// TLChat
//
// Created by 李伯坤 on 2018/1/2.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import "TLExpressionChosenAngel.h"
@implementation TLExpressionChosenAngel
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
CGFloat height = [super tableView:tableView heightForHeaderInSection:section];
return height < 0.1 ? 0.00001 : height;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
CGFloat height = [super tableView:tableView heightForFooterInSection:section];
return height < 0.1 ? 0.00001 : height;
}
@end
@@ -0,0 +1,15 @@
//
// TLExpressionChosenViewController.h
// TLChat
//
// Created by 李伯坤 on 16/4/4.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLViewController.h"
@interface TLExpressionChosenViewController : TLViewController
- (void)requestDataIfNeed;
@end
@@ -0,0 +1,249 @@
//
// TLExpressionChosenViewController.m
// TLChat
//
// Created by 李伯坤 on 16/4/4.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLExpressionChosenViewController.h"
#import "TLExpressionSearchResultViewController.h"
#import "TLSearchController.h"
#import "TLExpressionGroupModel+ChosenRequest.h"
#import "TLExpressionHelper.h"
#import "TLExpressionChosenAngel.h"
#import "TLExpressionDetailViewController.h"
typedef NS_ENUM(NSInteger, TLExpressionChosenSectionType) {
TLExpressionChosenSectionTypeBanner,
TLExpressionChosenSectionTypeRec,
TLExpressionChosenSectionTypeChosen,
};
@interface TLExpressionChosenViewController () <UISearchBarDelegate>
@property (nonatomic, assign) NSInteger pageIndex;
/// 列表
@property (nonatomic, strong) UITableView *tableView;
/// 列表管理器
@property (nonatomic, strong) TLExpressionChosenAngel *tableViewAngel;
/// 请求队列
@property (nonatomic, strong) ZZFLEXRequestQueue *requestQueue;
/// 搜索
@property (nonatomic, strong) TLSearchController *searchController;
@end
@implementation TLExpressionChosenViewController
- (void)loadView
{
[super loadView];
[self p_loadUI];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// 更新表情状态
[self.tableView reloadData];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[TLUIUtility hiddenLoading];
}
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
if (!CGRectEqualToRect(self.view.bounds, self.tableView.frame)) {
[self.tableView setFrame:self.view.bounds];
self.tableViewAngel.updateCells.all();
[self.tableView reloadData];
}
}
#pragma mark - # Requests
- (void)requestDataIfNeed
{
if (self.tableViewAngel.sectionForTag(TLExpressionChosenSectionTypeChosen).dataModelArray.count > 0) {
return;
}
if (self.requestQueue.isRuning) {
return;
}
self.requestQueue = [[ZZFLEXRequestQueue alloc] init];
[self.requestQueue addRequestModel:self.bannerRequestModel];
[self.requestQueue addRequestModel:self.recommentRequestModel];
[self.requestQueue addRequestModel:[self listRequestModelWithPageIndex:1]];
[TLUIUtility showLoading:nil];
[self.requestQueue runAllRequestsWithCompleteAction:^(NSArray *data, NSInteger successCount, NSInteger failureCount) {
[TLUIUtility hiddenLoading];
}];
}
#pragma mark - # Event Action
- (void)didSelectedExpressionGroup:(TLExpressionGroupModel *)groupModel
{
TLExpressionDetailViewController *detailVC = [[TLExpressionDetailViewController alloc] initWithGroupModel:groupModel];
PushVC(detailVC);
}
#pragma mark - # Private Methods
- (void)p_loadUI
{
/// 初始化列表
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
self.tableView.zz_make.backgroundColor([UIColor whiteColor])
.separatorStyle(UITableViewCellSeparatorStyleNone)
.tableHeaderView(self.searchController.searchBar)
.tableFooterView([UIView new])
.estimatedRowHeight(0).estimatedSectionFooterHeight(0).estimatedSectionHeaderHeight(0);
[self.view addSubview:self.tableView];
/// 初始化列表管理器
self.tableViewAngel = [[TLExpressionChosenAngel alloc] initWithHostView:self.tableView];
/// 初始化基本模块
self.tableViewAngel.addSection(TLExpressionChosenSectionTypeBanner);
self.tableViewAngel.addSection(TLExpressionChosenSectionTypeRec);
self.tableViewAngel.addSection(TLExpressionChosenSectionTypeChosen);
}
#pragma mark - # Getter
- (TLSearchController *)searchController
{
if (!_searchController) {
@weakify(self);
TLExpressionSearchResultViewController *searchResultVC = [[TLExpressionSearchResultViewController alloc] init];
[searchResultVC setItemClickAction:^(TLExpressionSearchResultViewController *searchController, id data) {
@strongify(self);
[self.searchController setActive:NO];
[self didSelectedExpressionGroup:data];
}];
_searchController = [TLSearchController createWithResultsContrller:searchResultVC];
[_searchController.searchBar setPlaceholder:LOCSTR(@"搜索表情")];
}
return _searchController;
}
- (ZZFLEXRequestModel *)bannerRequestModel
{
@weakify(self);
ZZFLEXRequestModel *requestModel = [ZZFLEXRequestModel requestModelWithTag:TLExpressionChosenSectionTypeBanner requestAction:^(ZZFLEXRequestModel *requestModel) {
[TLExpressionGroupModel requestExpressionChosenBannerSuccess:^(id successData) {
[requestModel executeRequestCompleteMethodWithSuccess:YES data:successData];
} failure:^(id failureData) {
[requestModel executeRequestCompleteMethodWithSuccess:NO data:failureData];
}];
} requestCompleteAction:^(ZZFLEXRequestModel *requestModel) {
@strongify(self);
if (!self) return;
self.tableViewAngel.sectionForTag(TLExpressionChosenSectionTypeBanner).clear();
if (requestModel.success) {
self.tableViewAngel.addCell(@"TLExpressionBannerCell").toSection(requestModel.tag).withDataModel(requestModel.data).eventAction(^id (NSInteger eventType, id data) {
@strongify(self);
[self didSelectedExpressionGroup:data];
return nil;
});
}
else {
[TLUIUtility showErrorHint:requestModel.data];
}
[self.tableView reloadData];
}];
return requestModel;
}
- (ZZFLEXRequestModel *)recommentRequestModel
{
@weakify(self);
ZZFLEXRequestModel *requestModel = [ZZFLEXRequestModel requestModelWithTag:TLExpressionChosenSectionTypeRec requestAction:^(ZZFLEXRequestModel *requestModel) {
[TLExpressionGroupModel requestExpressionRecommentListSuccess:^(id successData) {
[requestModel executeRequestCompleteMethodWithSuccess:YES data:successData];
} failure:^(id failureData) {
[requestModel executeRequestCompleteMethodWithSuccess:NO data:failureData];
}];
} requestCompleteAction:^(ZZFLEXRequestModel *requestModel) {
@strongify(self);
if (!self) return;
self.tableViewAngel.sectionForTag(requestModel.tag).clear();
if (requestModel.success) {
self.tableViewAngel.setHeader(@"TLExpressionTitleView").withDataModel(LOCSTR(@"推荐表情")).toSection(requestModel.tag);
[[TLExpressionHelper sharedHelper] updateExpressionGroupModelsStatus:requestModel.data];
self.tableViewAngel.addCells(@"TLExpressionItemCell").withDataModelArray(requestModel.data).toSection(requestModel.tag).selectedAction(^ (id data) {
@strongify(self);
[self didSelectedExpressionGroup:data];
});
}
[self.tableView reloadData];
}];
return requestModel;
}
- (ZZFLEXRequestModel *)listRequestModelWithPageIndex:(NSInteger)pageIndex
{
self.pageIndex = pageIndex;
@weakify(self);
ZZFLEXRequestModel *requestModel = [ZZFLEXRequestModel requestModelWithTag:TLExpressionChosenSectionTypeChosen requestAction:^(ZZFLEXRequestModel *requestModel) {
@strongify(self);
if (!self) return;
[TLExpressionGroupModel requestExpressionChosenListByPageIndex:pageIndex success:^(id successData) {
[requestModel executeRequestCompleteMethodWithSuccess:YES data:successData];
} failure:^(id failureData) {
[requestModel executeRequestCompleteMethodWithSuccess:NO data:failureData];
}];
} requestCompleteAction:^(ZZFLEXRequestModel *requestModel) {
@strongify(self);
if (!self) return;
if (pageIndex == 1) {
}
if (requestModel.success) {
if (pageIndex == 1) {
self.tableViewAngel.sectionForTag(requestModel.tag).clear();
if ([requestModel.data count] > 0) {
self.tableViewAngel.setHeader(@"TLExpressionTitleView").withDataModel(LOCSTR(@"更多精选")).toSection(requestModel.tag);
}
[self.tableView tt_addLoadMoreFooterWithAction:^{
@strongify(self);
[[self listRequestModelWithPageIndex:self.pageIndex + 1] executeRequestMethod];
}];
}
if ([requestModel.data count] > 0) {
[[TLExpressionHelper sharedHelper] updateExpressionGroupModelsStatus:requestModel.data];
self.tableViewAngel.addCells(@"TLExpressionItemCell").withDataModelArray(requestModel.data).toSection(requestModel.tag).selectedAction(^ (id data) {
@strongify(self);
[self didSelectedExpressionGroup:data];
});
[self.tableView tt_endLoadMore];
}
else {
[self.tableView tt_showNoMoreFooter];
}
}
else {
if (pageIndex == 1) {
[self.view showErrorViewWithTitle:requestModel.data retryAction:^(id userData) {
@weakify(self);
[self requestDataIfNeed];
}];
}
else {
[self.tableView tt_showNoMoreFooter];
}
}
[self.tableView reloadData];
}];
return requestModel;
}
@end
@@ -0,0 +1,25 @@
//
// TLExpressionBannerCell.h
// TLChat
//
// Created by 李伯坤 on 16/4/20.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@protocol TLExpressionBannerCellDelegate <NSObject>
- (void)expressionBannerCellDidSelectBanner:(id)item;
@end
@interface TLExpressionBannerCell : UITableViewCell <ZZFlexibleLayoutViewProtocol>
@property (nonatomic, assign) id<TLExpressionBannerCellDelegate>delegate;
@property (nonatomic, strong) NSArray *data;
@property (nonatomic, copy) void (^bannerClickAction)(id bannerModel);
@end
@@ -0,0 +1,104 @@
//
// TLExpressionBannerCell.m
// TLChat
//
// Created by 李伯坤 on 16/4/20.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLExpressionBannerCell.h"
#import "TLPictureCarouselView.h"
#import "TLExpressionGroupModel.h"
@interface TLExpressionBannerCell ()
@property (nonatomic, strong) TLPictureCarouselView *picCarouselView;
@end
@implementation TLExpressionBannerCell
#pragma mark - # Protocol
+ (CGFloat)viewHeightByDataModel:(id)dataModel
{
return 0.4 * SCREEN_WIDTH;
}
- (void)setViewDataModel:(id)dataModel
{
[self setData:dataModel];
}
- (void)setViewDelegate:(id)delegate
{
[self setDelegate:delegate];
}
- (void)setViewEventAction:(id (^)(NSInteger, id))eventAction
{
[self setBannerClickAction:^(id bannerModel) {
if (eventAction) {
eventAction(0, bannerModel);
}
}];
}
#pragma mark - # Public Methods
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self setSelectionStyle:UITableViewCellSelectionStyleNone];
[self.contentView addSubview:self.picCarouselView];
[self p_addMasonry];
}
return self;
}
- (void)setData:(NSArray *)data
{
_data = data;
[self.picCarouselView setData:data];
}
#pragma mark - # Private Methods
- (void)p_addMasonry
{
[self.picCarouselView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.contentView);
}];
}
#pragma mark - # Getter
- (TLPictureCarouselView *)picCarouselView
{
if (_picCarouselView == nil) {
_picCarouselView = [[TLPictureCarouselView alloc] init];
@weakify(self);
[_picCarouselView setDidSelectItem:^(TLPictureCarouselView *pictureCarouselView, id<TLPictureCarouselProtocol> model){
@strongify(self);
if (self.bannerClickAction) {
self.bannerClickAction(model);
}
if (self.delegate && [self.delegate respondsToSelector:@selector(expressionBannerCellDidSelectBanner:)]) {
[self.delegate expressionBannerCellDidSelectBanner:model];
}
}];
}
return _picCarouselView;
}
@end
#pragma mark - ## TLExpressionGroupModel (TLExpressionBannerCell)
@interface TLExpressionGroupModel (TLExpressionBannerCell) <TLPictureCarouselProtocol>
@end
@implementation TLExpressionGroupModel (TLExpressionBannerCell)
- (NSString *)pictureURL
{
return self.bannerURL;
}
@end
@@ -0,0 +1,25 @@
//
// TLExpressionDownloadButton.h
// TLChat
//
// Created by 李伯坤 on 2018/1/2.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, TLExpressionDownloadButtonStatus) {
TLExpressionDownloadButtonStatusNet,
TLExpressionDownloadButtonStatusDownloading,
TLExpressionDownloadButtonStatusDownloaded,
};
@interface TLExpressionDownloadButton : UIView
@property (nonatomic, assign) TLExpressionDownloadButtonStatus status;
@property (nonatomic, assign) CGFloat progress;
@property (nonatomic, copy) void (^downloadButtonClick)();
@end
@@ -0,0 +1,77 @@
//
// TLExpressionDownloadButton.m
// TLChat
//
// Created by 李伯坤 on 2018/1/2.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import "TLExpressionDownloadButton.h"
@interface TLExpressionDownloadButton ()
@property (nonatomic, strong) UIButton *downloadButton;
@property (nonatomic, strong) UIView *progressView;
@end
@implementation TLExpressionDownloadButton
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self.layer setMasksToBounds:YES];
[self.layer setCornerRadius:3];
[self.layer setBorderWidth:1];
self.progressView = self.addView(1)
.backgroundColor([UIColor colorGreenDefault])
.view;
@weakify(self);
self.downloadButton = self.addButton(2)
.titleFont([UIFont systemFontOfSize:14.0f])
.masonry(^ (MASConstraintMaker *make) {
make.edges.mas_equalTo(0);
})
.eventBlock(UIControlEventTouchUpInside, ^(UIButton *sender) {
@strongify(self);
if (self.downloadButtonClick) {
self.downloadButtonClick();
}
})
.view;
[self setStatus:TLExpressionDownloadButtonStatusNet];
}
return self;
}
- (void)setStatus:(TLExpressionDownloadButtonStatus)status
{
_status = status;
if (status == TLExpressionDownloadButtonStatusNet) {
self.downloadButton.zz_make.title(LOCSTR(@"下载")).titleColor([UIColor colorGreenDefault]).userInteractionEnabled(YES);
[self.layer setBorderColor:[UIColor colorGreenDefault].CGColor];
[self.progressView setHidden:YES];
}
else if (status == TLExpressionDownloadButtonStatusDownloaded) {
self.downloadButton.zz_make.title(LOCSTR(@"已下载")).titleColor([UIColor colorGrayLine]).userInteractionEnabled(NO);
[self.layer setBorderColor:[UIColor colorGrayLine].CGColor];
[self.progressView setHidden:YES];
}
else {
self.downloadButton.zz_make.title(LOCSTR(@"下载中")).titleColor([UIColor whiteColor]).userInteractionEnabled(NO);
[self.layer setBorderColor:[UIColor colorGreenDefault].CGColor];
[self.progressView setHidden:NO];
}
}
- (void)setProgress:(CGFloat)progress
{
_progress = progress;
[self.progressView setFrame:CGRectMake(0, 0, self.frame.size.width * progress, self.frame.size.height)];
}
@end
@@ -0,0 +1,16 @@
//
// TLExpressionItemCell.h
// TLChat
//
// Created by 李伯坤 on 16/4/4.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@class TLExpressionGroupModel;
@interface TLExpressionItemCell : UITableViewCell <ZZFlexibleLayoutViewProtocol>
@property (nonatomic, strong) TLExpressionGroupModel *groupModel;
@end
@@ -0,0 +1,192 @@
//
// TLExpressionItemCell.m
// TLChat
//
// Created by 李伯坤 on 16/4/4.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLExpressionItemCell.h"
#import "TLExpressionGroupModel+Download.h"
#import "TLExpressionDownloadButton.h"
#import "TLExpressionGroupModel.h"
@interface TLExpressionItemCell ()
@property (nonatomic, strong) UIImageView *iconView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *detailLabel;
@property (nonatomic, strong) UIImageView *tagView;
@property (nonatomic, strong) TLExpressionDownloadButton *downloadButton;
@property (nonatomic, copy) id (^eventAction)(NSInteger eventType, id data);
@end
@implementation TLExpressionItemCell
+ (CGFloat)viewHeightByDataModel:(id)dataModel
{
return 80;
}
- (void)setViewDataModel:(id)dataModel
{
[self setGroupModel:dataModel];
}
- (void)setViewEventAction:(id (^)(NSInteger, id))eventAction
{
[self setEventAction:eventAction];
}
- (void)viewIndexPath:(NSIndexPath *)indexPath sectionItemCount:(NSInteger)count
{
self.addSeparator(ZZSeparatorPositionBottom).beginAt(15);
}
#pragma mark - # Public Methods
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self.contentView addSubview:self.iconView];
[self.contentView addSubview:self.titleLabel];
[self.contentView addSubview:self.detailLabel];
[self.contentView addSubview:self.tagView];
[self.contentView addSubview:self.downloadButton];
[self p_addMasonry];
}
return self;
}
- (void)setGroupModel:(TLExpressionGroupModel *)groupModel
{
_groupModel = groupModel;
UIImage *image = [UIImage imageNamed:groupModel.path];
if (image) {
[self.iconView setImage:image];
}
else {
[self.iconView tt_setImageWithURL:TLURL(groupModel.iconURL)];
}
[self.titleLabel setText:groupModel.name];
[self.detailLabel setText:groupModel.detail];
if (groupModel.status == TLExpressionGroupStatusLocal) {
[self.downloadButton setStatus:TLExpressionDownloadButtonStatusDownloaded];
}
else if (groupModel.status == TLExpressionGroupStatusDownloading) {
[self.downloadButton setStatus:TLExpressionDownloadButtonStatusDownloading];
}
else {
[self.downloadButton setStatus:TLExpressionDownloadButtonStatusNet];
}
@weakify(self);
[self.downloadButton setProgress:groupModel.downloadProgress];
[groupModel setDownloadProgressAction:^(TLExpressionGroupModel *groupModel, CGFloat progress) {
@strongify(self);
[self.downloadButton setProgress:progress];
}];
[groupModel setDownloadCompleteAction:^(TLExpressionGroupModel *groupModel, BOOL success, id data) {
@strongify(self);
[self setGroupModel:groupModel];
}];
}
#pragma mark - # Private Methods
- (void)p_addMasonry
{
[self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView).mas_offset(15);
make.top.mas_equalTo(self.contentView).mas_offset(10);
make.bottom.mas_equalTo(self.contentView).mas_offset(-10);
make.width.mas_equalTo(self.iconView.mas_height);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.iconView.mas_centerY).mas_offset(-2.0f);
make.left.mas_equalTo(self.iconView.mas_right).mas_offset(13.0f);
make.right.mas_lessThanOrEqualTo(self.downloadButton.mas_left).mas_offset(-15);
}];
[self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.iconView.mas_centerY).mas_offset(5.0);
make.left.mas_equalTo(self.titleLabel);
make.right.mas_lessThanOrEqualTo(self.downloadButton.mas_left).mas_offset(-15);
}];
[self.tagView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.and.top.mas_equalTo(self.contentView);
}];
[self.downloadButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.contentView).mas_offset(-15);
make.centerY.mas_equalTo(self.contentView);
make.size.mas_equalTo(CGSizeMake(70, 27));
}];
}
#pragma mark - # Getter
- (UIImageView *)iconView
{
if (_iconView == nil) {
_iconView = [[UIImageView alloc] init];
[_iconView setBackgroundColor:[UIColor clearColor]];
[_iconView.layer setMasksToBounds:YES];
[_iconView.layer setCornerRadius:5.0f];
}
return _iconView;
}
- (UILabel *)titleLabel
{
if (_titleLabel == nil) {
_titleLabel = [[UILabel alloc] init];
[_titleLabel setFont:[UIFont systemFontOfSize:16.0f]];
[_titleLabel setBackgroundColor:[UIColor whiteColor]];
[_titleLabel setClipsToBounds:YES];
}
return _titleLabel;
}
- (UILabel *)detailLabel
{
if (_detailLabel == nil) {
_detailLabel = [[UILabel alloc] init];
[_detailLabel setFont:[UIFont systemFontOfSize:13.0f]];
[_detailLabel setTextColor:[UIColor grayColor]];
[_detailLabel setBackgroundColor:[UIColor whiteColor]];
[_detailLabel setClipsToBounds:YES];
}
return _detailLabel;
}
- (UIImageView *)tagView
{
if (_tagView == nil) {
_tagView = [[UIImageView alloc] init];
[_tagView setImage:[UIImage imageNamed:@"icon_corner_new"]];
[_tagView setHidden:YES];
}
return _tagView;
}
- (TLExpressionDownloadButton *)downloadButton
{
if (_downloadButton == nil) {
_downloadButton = [[TLExpressionDownloadButton alloc] init];
@weakify(self);
[_downloadButton setDownloadButtonClick:^{
@strongify(self);
if (self.groupModel.status == TLExpressionGroupStatusNet) {
[self.groupModel startDownload];
[self setGroupModel:self.groupModel];
}
}];
}
return _downloadButton;
}
@end
@@ -0,0 +1,13 @@
//
// TLExpressionTitleView.h
// TLChat
//
// Created by 李伯坤 on 2017/7/23.
// Copyright © 2017年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLExpressionTitleView : UITableViewHeaderFooterView <ZZFlexibleLayoutViewProtocol>
@end
@@ -0,0 +1,64 @@
//
// TLExpressionTitleView.m
// TLChat
//
// Created by 李伯坤 on 2017/7/23.
// Copyright © 2017年 李伯坤. All rights reserved.
//
#import "TLExpressionTitleView.h"
@interface TLExpressionTitleView ()
@property (nonatomic, strong) UILabel *titleLabel;
@end
@implementation TLExpressionTitleView
+ (CGFloat)viewHeightByDataModel:(id)dataModel
{
return 55;
}
- (void)setViewDataModel:(id)dataModel
{
if (dataModel && [dataModel isKindOfClass:[NSString class]]) {
[self.titleLabel setText:dataModel];
}
else {
[self.titleLabel setText:nil];
}
}
#pragma mark - # Public Methods
- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
[bgView setBackgroundColor:[UIColor whiteColor]];
[self setBackgroundView:bgView];
[self setTintColor:[UIColor whiteColor]];
self.titleLabel = self.contentView.addLabel(1)
.backgroundColor([UIColor whiteColor])
.clipsToBounds(YES)
.font([UIFont systemFontOfSize:17])
.masonry(^(MASConstraintMaker *make) {
make.left.mas_equalTo(15);
make.right.mas_lessThanOrEqualTo(-15);
make.bottom.mas_equalTo(-12);
})
.view;
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
self.addSeparator(ZZSeparatorPositionBottom).beginAt(15).length(SCREEN_WIDTH - 15);
}
@end
@@ -0,0 +1,18 @@
//
// TLExpressionGroupModel+MoreRequest.h
// TLChat
//
// Created by 李伯坤 on 2018/1/2.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import "TLExpressionGroupModel.h"
@interface TLExpressionGroupModel (MoreRequest)
/**
* 更多表情 —— 更多列表
*/
+ (TLBaseRequest *)requestExpressionMoreListByPageIndex:(NSInteger)page success:(TLRequestSuccessBlock)success failure:(TLRequestFailureBlock)failure;
@end
@@ -0,0 +1,65 @@
//
// TLExpressionGroupModel+MoreRequest.m
// TLChat
//
// Created by 李伯坤 on 2018/1/2.
// Copyright © 2018年 李伯坤. All rights reserved.
//
#import "TLExpressionGroupModel+MoreRequest.h"
#import "TLNetworking.h"
#define IEXPRESSION_MORE_URL [IEXPRESSION_HOST_URL stringByAppendingString:@"expre/listBy.do?pageNumber=%ld&status=Y&status1=B&count=yes"]
@implementation TLExpressionGroupModel (MoreRequest)
+ (TLBaseRequest *)requestExpressionMoreListByPageIndex:(NSInteger)page success:(TLRequestSuccessBlock)success failure:(TLRequestFailureBlock)failure
{
NSString *urlString = [NSString stringWithFormat:IEXPRESSION_MORE_URL, (long)page];
[TLNetworking postUrl:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
NSArray *respArray = [responseObject mj_JSONObject];
NSString *status = respArray[0];
if ([status isEqualToString:@"OK"]) {
NSArray *infoArray = respArray[2];
NSMutableArray *data = [TLExpressionGroupModel mj_objectArrayWithKeyValuesArray:infoArray];
if (success) {
success(data);
}
}
else {
if (failure) {
failure(status);
}
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure(TLNetworkErrorTip);
}
}];
// NSString *urlString = [NSString stringWithFormat:IEXPRESSION_MORE_URL, (long)page];
// TLBaseRequest *request = [TLBaseRequest requestWithMethod:TLRequestMethodPOST url:urlString parameters:nil];
// [request startRequestWithSuccessAction:^(TLResponse *response) {
// NSArray *respArray = [response.responseData mj_JSONObject];
// NSString *status = respArray[0];
// if ([status isEqualToString:@"OK"]) {
// NSArray *infoArray = respArray[2];
// NSMutableArray *data = [TLExpressionGroupModel mj_objectArrayWithKeyValuesArray:infoArray];
// if (success) {
// success(data);
// }
// }
// else {
// if (failure) {
// failure(status);
// }
// }
// } failureAction:^(TLResponse *response) {
// if (failure) {
// failure(TLNetworkErrorTip);
// }
// }];
// return request;
return nil;
}
@end
@@ -0,0 +1,15 @@
//
// TLExpressionMoreViewController.h
// TLChat
//
// Created by 李伯坤 on 2017/7/18.
// Copyright © 2017年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLExpressionMoreViewController : ZZFlexibleLayoutViewController
- (void)requestDataIfNeed;
@end
@@ -0,0 +1,114 @@
//
// TLExpressionMoreViewController.m
// TLChat
//
// Created by 李伯坤 on 2017/7/18.
// Copyright © 2017年 李伯坤. All rights reserved.
//
#import "TLExpressionMoreViewController.h"
#import "TLExpressionDetailViewController.h"
#import "TLExpressionGroupModel+MoreRequest.h"
typedef NS_ENUM(NSInteger, TLExpressionMoreSectionType) {
TLExpressionMoreSectionTypeSearch,
TLExpressionMoreSectionTypeExprs,
};
@interface TLExpressionMoreViewController ()
@property (nonatomic, assign) NSInteger pageIndex;
@end
@implementation TLExpressionMoreViewController
- (void)loadView
{
[super loadView];
[self.collectionView setBackgroundColor:[UIColor whiteColor]];
@weakify(self);
// 搜索
self.addSection(TLExpressionMoreSectionTypeSearch);
self.addCell(@"TLExpressionMoreSearchCell").toSection(TLExpressionMoreSectionTypeSearch).eventAction(^ id(NSInteger eventType, id data) {
@strongify(self);
[self didSelectedExpressionGroup:data];
return nil;
});
// 表情
self.addSection(TLExpressionMoreSectionTypeExprs).backgrounColor([UIColor whiteColor]).sectionInsets(UIEdgeInsetsMake(15, 15, 0, 15)).minimumInteritemSpacing(15);
}
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
if (!CGRectEqualToRect(self.collectionView.frame, self.view.bounds)) {
[self.collectionView setFrame:self.view.bounds];
self.updateCells.all();
[self.collectionView reloadData];
}
}
- (void)requestDataIfNeed
{
if ([self dataModelArrayForSection:TLExpressionMoreSectionTypeExprs].count == 0) {
[TLUIUtility showLoading:nil];
[self requestExpressionMoreDataWithPageIndex:1];
}
}
#pragma mark - # Event Action
- (void)didSelectedExpressionGroup:(TLExpressionGroupModel *)groupModel
{
TLExpressionDetailViewController *detailVC = [[TLExpressionDetailViewController alloc] initWithGroupModel:groupModel];
PushVC(detailVC);
}
#pragma mark - # Request
- (void)requestExpressionMoreDataWithPageIndex:(NSInteger)pageIndex
{
if (pageIndex == 1) {
[self.collectionView tt_removeLoadMoreFooter];
}
self.pageIndex = pageIndex;
[self removeTipView];
@weakify(self);
[TLExpressionGroupModel requestExpressionMoreListByPageIndex:pageIndex success:^(NSArray *successData) {
@strongify(self);
[TLUIUtility hiddenLoading];
if (pageIndex == 1) {
[self deleteAllItemsForSection:TLExpressionMoreSectionTypeExprs];
}
if (successData.count > 0) {
if (pageIndex == 1) {
[self.collectionView tt_addLoadMoreFooterWithAction:^{
@strongify(self);
[self requestExpressionMoreDataWithPageIndex:self.pageIndex + 1];
}];
}
self.addCells(@"TLExpressionMoreCell").withDataModelArray(successData).toSection(TLExpressionMoreSectionTypeExprs).selectedAction(^ (id data) {
@strongify(self);
[self didSelectedExpressionGroup:data];
});
[self.collectionView tt_endLoadMore];
}
else {
[self.collectionView tt_showNoMoreFooter];
}
[self reloadView];
} failure:^(id failureData) {
@strongify(self);
[TLUIUtility hiddenLoading];
[self.collectionView tt_endLoadMore];
[self.view showErrorViewWithTitle:failureData retryAction:^(id userData) {
@strongify(self);
[self requestDataIfNeed];
}];
}];
}
@end
@@ -0,0 +1,18 @@
//
// TLExpressionMoreCell.h
// TLChat
//
// Created by 李伯坤 on 2017/7/21.
// Copyright © 2017年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TLExpressionGroupModel.h"
#define WIDTH_EXPRESSION_MORE_CELL MIN(((SCREEN_WIDTH - 15 * 4) / 3 - 1), 115)
@interface TLExpressionMoreCell : UICollectionViewCell <ZZFlexibleLayoutViewProtocol>
@property (nonatomic, strong) TLExpressionGroupModel *groupModel;
@end
@@ -0,0 +1,99 @@
//
// TLExpressionMoreCell.m
// TLChat
//
// Created by 李伯坤 on 2017/7/21.
// Copyright © 2017年 李伯坤. All rights reserved.
//
#import "TLExpressionMoreCell.h"
@interface TLExpressionMoreCell ()
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *titleLabel;
@end
@implementation TLExpressionMoreCell
#pragma mark - # Protocol
+ (CGSize)viewSizeByDataModel:(id)dataModel
{
return CGSizeMake(WIDTH_EXPRESSION_MORE_CELL, WIDTH_EXPRESSION_MORE_CELL + 40);
}
- (void)setViewDataModel:(id)dataModel
{
[self setGroupModel:dataModel];
}
#pragma mark - # Public Methods
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self.contentView addSubview:self.imageView];
[self.contentView addSubview:self.titleLabel];
[self p_addMasonry];
}
return self;
}
- (void)setGroupModel:(TLExpressionGroupModel *)groupModel
{
if (_groupModel == groupModel) {
return;
}
_groupModel = groupModel;
[self.titleLabel setText:groupModel.name];
UIImage *image = [UIImage imageWithContentsOfFile:groupModel.iconPath];
if (image) {
[self.imageView setImage:image];
}
else {
[self.imageView tt_setImageWithURL:TLURL(groupModel.iconURL) placeholderImage:[UIImage imageWithColor:[UIColor colorGrayBG]]];
}
}
#pragma mark - # Private Methods
- (void)p_addMasonry
{
[self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.and.top.and.right.mas_equalTo(self.contentView);
make.height.mas_equalTo(self.imageView.mas_width);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.contentView);
make.top.mas_equalTo(self.imageView.mas_bottom).mas_offset(7.0f);
make.width.mas_lessThanOrEqualTo(self.contentView);
}];
}
#pragma mark - # Getters
- (UIImageView *)imageView
{
if (_imageView == nil) {
_imageView = [[UIImageView alloc] init];
[_imageView setBackgroundColor:[UIColor whiteColor]];
[_imageView.layer setMasksToBounds:YES];
[_imageView.layer setCornerRadius:10.0f];
[_imageView.layer setBorderWidth:BORDER_WIDTH_1PX];
[_imageView.layer setBorderColor:[UIColor colorGrayLine].CGColor];
}
return _imageView;
}
- (UILabel *)titleLabel
{
if (_titleLabel == nil) {
_titleLabel = [[UILabel alloc] init];
[_titleLabel setTextAlignment:NSTextAlignmentCenter];
[_titleLabel setFont:[UIFont systemFontOfSize:12.0f]];
[_titleLabel setBackgroundColor:[UIColor whiteColor]];
[_titleLabel setClipsToBounds:YES];
}
return _titleLabel;
}
@end
@@ -0,0 +1,13 @@
//
// TLExpressionMoreSearchCell.h
// TLChat
//
// Created by 李伯坤 on 2017/7/21.
// Copyright © 2017年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLExpressionMoreSearchCell : UICollectionViewCell <ZZFlexibleLayoutViewProtocol>
@end
@@ -0,0 +1,64 @@
//
// TLExpressionMoreSearchCell.m
// TLChat
//
// Created by 李伯坤 on 2017/7/21.
// Copyright © 2017年 李伯坤. All rights reserved.
//
#import "TLExpressionMoreSearchCell.h"
#import "TLExpressionSearchResultViewController.h"
#import "TLSearchController.h"
@interface TLExpressionMoreSearchCell ()
@property (nonatomic, strong) TLSearchController *searchController;
@property (nonatomic, copy) id (^eventAction)(NSInteger, id);
@end
@implementation TLExpressionMoreSearchCell
#pragma mark - # Protocol
+ (CGSize)viewSizeByDataModel:(id)dataModel
{
return CGSizeMake(SCREEN_WIDTH, SEARCHBAR_HEIGHT);
}
- (void)setViewEventAction:(id (^)(NSInteger, id))eventAction
{
self.eventAction = eventAction;
}
#pragma mark - # Public Methods
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self setBackgroundColor:[UIColor whiteColor]];
@weakify(self);
TLExpressionSearchResultViewController *searchResultVC = [[TLExpressionSearchResultViewController alloc] init];
[searchResultVC setItemClickAction:^(TLExpressionSearchResultViewController *searchController, id data) {
@strongify(self);
[self.searchController setActive:NO];
if (self.eventAction) {
self.eventAction(0, data);
}
}];
self.searchController = [TLSearchController createWithResultsContrller:searchResultVC];
[self.searchController.searchBar setPlaceholder:LOCSTR(@"搜索表情")];
[self.contentView addSubview:self.searchController.searchBar];
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
if (!CGSizeEqualToSize(self.bounds.size, self.searchController.searchBar.frame.size)) {
[self.searchController.searchBar setSize:self.bounds.size];
}
}
@end
@@ -0,0 +1,13 @@
//
// TLExpressionViewController.h
// TLChat
//
// Created by 李伯坤 on 16/2/21.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLViewController.h"
@interface TLExpressionViewController : TLViewController
@end
@@ -0,0 +1,109 @@
//
// TLExpressionViewController.m
// TLChat
//
// Created by 李伯坤 on 16/2/21.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLExpressionViewController.h"
#import "TLExpressionChosenViewController.h"
#import "TLExpressionMoreViewController.h"
#import "TLMyExpressionViewController.h"
#define WIDTH_EXPRESSION_SEGMENT SCREEN_WIDTH * 0.55
@interface TLExpressionViewController ()
/// navBar分段控制器
@property (nonatomic, strong) UISegmentedControl *segmentedControl;
/// 精选表情
@property (nonatomic, strong) TLExpressionChosenViewController *expChosenVC;
/// 更多表情
@property (nonatomic, strong) TLExpressionMoreViewController *expMoreVC;
@end
@implementation TLExpressionViewController
- (void)loadView
{
[super loadView];
// navBar分段控制器
[self.navigationItem setTitleView:self.segmentedControl];
// 精选表情
self.expChosenVC = [[TLExpressionChosenViewController alloc] init];
[self.view addSubview:self.expChosenVC.view];
[self addChildViewController:self.expChosenVC];
// 推荐表情
self.expMoreVC = [[TLExpressionMoreViewController alloc] init];
[self addChildViewController:self.expMoreVC];
@weakify(self);
[self addRightBarButtonWithImage:[UIImage imageNamed:@"nav_setting"] actionBlick:^{
@strongify(self);
TLMyExpressionViewController *myExpressionVC = [[TLMyExpressionViewController alloc] init];
PushVC(myExpressionVC);
}];
if (self.navigationController.rootViewController == self) {
[self addLeftBarButtonWithTitle:LOCSTR(@"取消") actionBlick:^{
@strongify(self);
[self dismissViewControllerAnimated:YES completion:nil];
}];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.expChosenVC requestDataIfNeed];
}
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
[self.segmentedControl setWidth:WIDTH_EXPRESSION_SEGMENT];
if (!CGRectEqualToRect(self.expChosenVC.view.frame, self.view.bounds)) {
[self.expChosenVC.view setFrame:self.view.bounds];
}
if (!CGRectEqualToRect(self.expMoreVC.view.frame, self.view.bounds)) {
[self.expMoreVC.view setFrame:self.view.bounds];
}
}
#pragma mark - # Event Response
- (void)segmentedControlChanged:(UISegmentedControl *)segmentedControl
{
if (segmentedControl.selectedSegmentIndex == 0) {
[self transitionFromViewController:self.expMoreVC toViewController:self.expChosenVC duration:0.5 options:UIViewAnimationOptionCurveEaseInOut animations:nil completion:nil];
[self.expChosenVC requestDataIfNeed];
}
else {
[self transitionFromViewController:self.expChosenVC toViewController:self.expMoreVC duration:0.5 options:UIViewAnimationOptionCurveEaseInOut animations:nil completion:nil];
[self.expMoreVC requestDataIfNeed];
}
}
#pragma mark - # Getter
- (UISegmentedControl *)segmentedControl
{
if (_segmentedControl == nil) {
_segmentedControl = [[UISegmentedControl alloc] initWithItems:@[LOCSTR(@"精选表情"), LOCSTR(@"更多表情")]];
[_segmentedControl setWidth:WIDTH_EXPRESSION_SEGMENT];
[_segmentedControl setSelectedSegmentIndex:0];
[_segmentedControl addTarget:self action:@selector(segmentedControlChanged:) forControlEvents:UIControlEventValueChanged];
}
return _segmentedControl;
}
@end
@@ -0,0 +1,13 @@
//
// TLMyExpressionViewController.h
// TLChat
//
// Created by 李伯坤 on 16/3/10.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLMyExpressionViewController : ZZFlexibleLayoutViewController
@end
@@ -0,0 +1,95 @@
//
// TLMyExpressionViewController.m
// TLChat
//
// Created by 李伯坤 on 16/3/10.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLMyExpressionViewController.h"
#import "TLExpressionDetailViewController.h"
#import "TLExpressionHelper.h"
#import "TLMyExpressionCell.h"
typedef NS_ENUM(NSInteger, TLMyExpressionVCSectionType) {
TLMyExpressionVCSectionTypeMine,
TLMyExpressionVCSectionTypeFunction,
};
@interface TLMyExpressionViewController () <TLMyExpressionCellDelegate>
@end
@implementation TLMyExpressionViewController
- (void)loadView
{
[super loadView];
[self setTitle:LOCSTR(@"我的表情")];
[self.view setBackgroundColor:[UIColor colorGrayBG]];
@weakify(self);
[self addRightBarButtonWithTitle:LOCSTR(@"排序") actionBlick:^{
}];
if (self.navigationController.rootViewController == self) {
[self addLeftBarButtonWithTitle:LOCSTR(@"取消") actionBlick:^{
@strongify(self);
[self dismissViewControllerAnimated:YES completion:nil];
}];
}
[self loadMyExpressionVCUI];
}
#pragma mark - # UI
- (void)loadMyExpressionVCUI
{
@weakify(self);
self.clear();
NSArray *expArray = [TLExpressionHelper sharedHelper].userEmojiGroups;
if (expArray.count > 0) {
self.addSection(TLMyExpressionVCSectionTypeMine).sectionInsets(UIEdgeInsetsMake(15, 0, 0, 0));
self.addCells(@"TLMyExpressionCell").toSection(TLMyExpressionVCSectionTypeMine).withDataModelArray(expArray).selectedAction(^ (id data) {
@strongify(self);
TLExpressionDetailViewController *detailVC = [[TLExpressionDetailViewController alloc] initWithGroupModel:data];
PushVC(detailVC);
});
self.addSection(TLMyExpressionVCSectionTypeFunction).sectionInsets(UIEdgeInsetsMake(20, 0, 40, 0));
}
else {
self.addSection(TLMyExpressionVCSectionTypeFunction).sectionInsets(UIEdgeInsetsMake(15, 0, 30, 0));
}
// 添加的表情
self.addCell(CELL_ST_ITEM_NORMAL).toSection(TLMyExpressionVCSectionTypeFunction).withDataModel(TLCreateSettingItem(@"添加的表情")).selectedAction(^ (id data) {
});
// 购买的表情
self.addCell(CELL_ST_ITEM_NORMAL).toSection(TLMyExpressionVCSectionTypeFunction).withDataModel(TLCreateSettingItem(@"购买的表情")).selectedAction(^ (id data) {
});
}
#pragma mark - # Delegate
//MARK: TLMyExpressionCellDelegate
- (void)myExpressionCellDeleteButtonDown:(TLExpressionGroupModel *)group
{
BOOL ok = [[TLExpressionHelper sharedHelper] deleteExpressionGroupByID:group.gId];
if (ok) {
self.deleteCell.byDataModel(group);
if (self.sectionForTag(TLMyExpressionVCSectionTypeMine).dataModelArray.count == 0) {
self.deleteSection(TLMyExpressionVCSectionTypeMine);
self.sectionForTag(TLMyExpressionVCSectionTypeFunction).sectionInsets(UIEdgeInsetsMake(15, 0, 0, 0));
}
[self reloadView];
}
else {
[TLUIUtility showErrorHint:@"表情包删除失败"];
}
}
@end
@@ -0,0 +1,24 @@
//
// TLMyExpressionCell.h
// TLChat
//
// Created by 李伯坤 on 16/3/12.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLSettingItemBaseCell.h"
#import "TLExpressionGroupModel.h"
@protocol TLMyExpressionCellDelegate <NSObject>
- (void)myExpressionCellDeleteButtonDown:(TLExpressionGroupModel *)group;
@end
@interface TLMyExpressionCell : TLSettingItemBaseCell
@property (nonatomic, assign) id<TLMyExpressionCellDelegate>delegate;
@property (nonatomic, strong) TLExpressionGroupModel *group;
@end
@@ -0,0 +1,96 @@
//
// TLMyExpressionCell.m
// TLChat
//
// Created by 李伯坤 on 16/3/12.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLMyExpressionCell.h"
#import "UIImage+Color.h"
@interface TLMyExpressionCell()
@property (nonatomic, strong) UIImageView *iconView;
@property (nonatomic, strong) UILabel *titleLabel;
@end
@implementation TLMyExpressionCell
#pragma mark - # Protocol
+ (CGFloat)viewHeightByDataModel:(id)dataModel
{
return 50;
}
- (void)setViewDataModel:(id)dataModel
{
[self setGroup:dataModel];
}
- (void)setViewDelegate:(id)delegate
{
self.delegate = delegate;
}
#pragma mark - # Cell
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self.arrowView setHidden:YES];
[self setSelectedBackgrounColor:[UIColor colorGrayLine]];
[self p_initMyExpressionCellSubviews];
}
return self;
}
- (void)setGroup:(TLExpressionGroupModel *)group
{
_group = group;
[self.iconView setImage:[UIImage imageNamed:group.iconPath]];
[self.titleLabel setText:group.name];
}
#pragma mark - # UI
- (void)p_initMyExpressionCellSubviews
{
@weakify(self);
self.iconView = self.contentView.addImageView(1)
.masonry(^ (MASConstraintMaker *make) {
make.left.mas_equalTo(15.0f);
make.centerY.mas_equalTo(0);
make.width.and.height.mas_equalTo(35);
})
.view;
UIButton *deleteButton = self.contentView.addButton(2)
.backgroundColor([UIColor colorGrayBG]).backgroundColorHL([UIColor colorGrayLine])
.title(LOCSTR(@"移除")).titleColor([UIColor grayColor]).titleFont([UIFont systemFontOfSize:13.0f])
.cornerRadius(3.0f).border(BORDER_WIDTH_1PX, [UIColor colorGrayLine])
.eventBlock(UIControlEventTouchUpInside, ^(UIButton *sender) {
@strongify(self);
if (self.delegate && [self.delegate respondsToSelector:@selector(myExpressionCellDeleteButtonDown:)]) {
[self.delegate myExpressionCellDeleteButtonDown:self.group];
}
})
.masonry(^ (MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(50, 30));
make.right.mas_equalTo(-15);
make.centerY.mas_equalTo(0);
})
.view;
self.titleLabel = self.addLabel(3)
.masonry(^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(0);
make.left.mas_equalTo(self.iconView.mas_right).mas_offset(10.0f);
make.right.mas_lessThanOrEqualTo(deleteButton.mas_left).mas_offset(-15.0f);
})
.view;
}
@end