CNMyGifFaceTableViewCell.m
7.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//
// CNMyGifFaceTableViewCell.m
// CNLiveNetAdd
//
// Created by CNLive-zxw on 2019/2/18.
// Copyright © 2019年 cnlive. All rights reserved.
//
#import "CNMyGifFaceTableViewCell.h"
#import "CNGifFaceModel.h"
#import "CNLiveDownLoadManager.h"
#import "CNLiveArchiveManager.h"
//#import "UIColor+CNLiveExtension.h"
#import "CNFaceThemeModel.h"
@interface CNMyGifFaceTableViewCell()
@property (nonatomic, strong) UIImageView *leftImage;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *removeBtn;
@property (nonatomic, strong) UIView *line;
@end
@implementation CNMyGifFaceTableViewCell
static const NSInteger margin = 10;
#pragma mark - Init
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.contentView.backgroundColor = [UIColor whiteColor];
[self setupUI];
}
return self;
}
#pragma mark - Data
- (void)setGroupName:(NSString *)groupName{
_groupName = groupName;
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/GifFace/Download/%@",[UserInformationModel manager].uid,groupName]];
//设置图片
NSString *image = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_left0",groupName]];
_leftImage.image = [UIImage imageNamed:image];
//设置标题
// 将文件数据化
NSData *data = [[NSData alloc] initWithContentsOfFile:[path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.json",groupName]]];
if(data){
// 对数据进行JSON格式化并返回字典形式
NSDictionary *faceDic = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
CNFaceThemeModel *themeModel = [CNFaceThemeModel mj_objectWithKeyValues:faceDic];
_titleLabel.text = themeModel.themeName;
}
}
#pragma mark - UI
- (void)setupUI{
[self.contentView addSubview:self.leftImage];
[self.contentView addSubview:self.titleLabel];
[self.contentView addSubview:self.removeBtn];
[self.contentView addSubview:self.line];
}
- (void)layoutSubviews{
[super layoutSubviews];
[_leftImage mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView.mas_top).with.offset(margin);
make.left.equalTo(self.contentView.mas_left).with.offset(margin);
make.width.offset(30*RATIO);
make.height.offset(40*RATIO);
}];
[_titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(_leftImage.mas_centerY);
make.left.equalTo(_leftImage.mas_right).with.offset(margin);
make.height.offset(30*RATIO);
}];
[_removeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.contentView.mas_right).with.offset(-margin);
make.centerY.equalTo(_leftImage.mas_centerY);
make.height.offset(30*RATIO);
make.width.offset(60*RATIO);
}];
[_line mas_remakeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-0);
make.right.equalTo(self.contentView);
make.left.equalTo(self.contentView.mas_right).with.offset(margin);
make.height.offset(0.5);
}];
}
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#pragma mark - Private Methods
#pragma mark - Action
- (void)clickRemoveBtn:(UIButton *)btn{
[QMUITips showLoading:@"移除中..." inView:AppKeyWindow];
//1先删除plist文件
NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath1 = [docPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/GifFace/%@",[UserInformationModel manager].uid,@"GifFaceList.plist"]];
///var/mobile/Containers/Data/Application/94E0C70B-9F4D-4716-8EAF-7BF0C53AEAEE/Documents/10514405/GifFace/GifFaceList.plist
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL result1 = [fileManager fileExistsAtPath:filePath1];
if(result1){
//读取已存在的表情包列表
NSMutableArray *data = [NSMutableArray arrayWithContentsOfFile:filePath1];
[data removeObject:_groupName];
if([data writeToFile:filePath1 atomically:YES]){
NSLog(@"删除plist文件的数据并写入成功");
[[NSNotificationCenter defaultCenter] postNotificationName:@"GifFaceDownLoadSuccess" object:nil];
}
}
//2然后删除文件夹中的表情包
NSString *filePath2 = [docPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/GifFace/Download/%@",[UserInformationModel manager].uid,_groupName]];
BOOL result2 = [fileManager fileExistsAtPath:filePath2];
if(result2){
//读取已存在的表情包列表
if([fileManager removeItemAtPath:filePath2 error:nil]){
NSLog(@"删除表情包的数据成功");
}
}
if (self.delegate && [self.delegate respondsToSelector:@selector(refreshGifFaceTableView:)]) {
[self.delegate refreshGifFaceTableView:self];
[[NSNotificationCenter defaultCenter] postNotificationName:@"RemoveGifFacePackageSuccess" object:nil userInfo:@{@"sectionId":_groupName}];
}
[QMUITips hideAllTipsInView:AppKeyWindow];
// QMUITips *tips = [QMUITips showSucceed:@"移除成功" inView:AppKeyWindow hideAfterDelay:1];
// tips.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.6];
}
#pragma mark - Lazy loading
- (UIImageView *)leftImage{
if (!_leftImage) {
_leftImage = [[UIImageView alloc] init];
_leftImage.userInteractionEnabled = YES;
// _leftImage.contentMode = UIViewContentModeScaleAspectFill;
// _leftImage.layer.masksToBounds = YES;
}
return _leftImage;
}
- (UILabel *)titleLabel{
if(_titleLabel == nil){
_titleLabel = [[UILabel alloc] init];
_titleLabel.textColor = [UIColor blackColor];
_titleLabel.font = UIFontCNMake(17);
_titleLabel.userInteractionEnabled = YES;
}
return _titleLabel;
}
- (UIButton *)removeBtn{
if(_removeBtn == nil){
_removeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_removeBtn.titleLabel.font = UIFontCNMake(14);
_removeBtn.backgroundColor = CNLiveColorWithHexString(@"FAFAFA");
_removeBtn.layer.cornerRadius = 15*RATIO;
_removeBtn.layer.masksToBounds = YES;
_removeBtn.layer.borderColor = CNLiveColorWithHexString(@"C6C6C6").CGColor;
_removeBtn.layer.borderWidth = 1;
[_removeBtn addTarget:self action:@selector(clickRemoveBtn:) forControlEvents:UIControlEventTouchUpInside];
[_removeBtn setTitle:@"移除" forState:UIControlStateNormal];
[_removeBtn setTitleColor:CNLiveColorWithHexString(@"999999") forState:UIControlStateNormal];
}
return _removeBtn;
}
- (UIView *)line{
if(_line == nil){
_line = [[UIView alloc] init];
_line.backgroundColor = [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1.0];
}
return _line;
}
@end