修复消息页面部分bug
This commit is contained in:
@@ -17,6 +17,7 @@ Strong UIButton *bgBtn;
|
||||
{
|
||||
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
|
||||
if (self) {
|
||||
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||
[self loadSubViews];
|
||||
}
|
||||
return self;
|
||||
@@ -159,6 +160,8 @@ Strong UIButton *bgBtn;
|
||||
self.bgBtn.selected = YES;
|
||||
}else
|
||||
{
|
||||
self.bgBtn.selected = NO;
|
||||
self.deleteBtn.selected = NO;
|
||||
self.deleteBtn.hidden = !isShowDelte;
|
||||
self.bgBtn.hidden = !isShowDelte;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,9 @@ Assign BOOL isShowDelete;//是否显示删除按钮
|
||||
Strong MessageAlertView *comboxView;
|
||||
Strong UIView *deleteView;
|
||||
Strong UIButton *deleteBtn;
|
||||
|
||||
Strong UIAlertController *alertController;
|
||||
Strong UIAlertAction *okAction;
|
||||
Strong UIAlertAction *cancelAction;
|
||||
@end
|
||||
extern BOOL launchedByNotification;
|
||||
@implementation IfishMessageViewController
|
||||
@@ -157,23 +159,24 @@ extern BOOL launchedByNotification;
|
||||
[self.deleteBtn setTitleColor:RGB(178, 178, 178) forState:UIControlStateNormal];
|
||||
[self.deleteBtn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
|
||||
[self.deleteBtn addTarget:self action:@selector(deleBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[_deleteView addSubview:self.deleteBtn];
|
||||
[self.deleteView addSubview:self.deleteBtn];
|
||||
|
||||
UIButton *allDeleteBtn = InitObject(UIButton);
|
||||
[allDeleteBtn setTitle:@"全选" forState:UIControlStateNormal];
|
||||
[allDeleteBtn setTitle:@"取消" forState:UIControlStateSelected];
|
||||
[allDeleteBtn.titleLabel setFont:SYSTEMSIZE(34)];
|
||||
[allDeleteBtn setTitleColor:RGB(4, 99, 201) forState:UIControlStateNormal];
|
||||
[allDeleteBtn addTarget:self action:@selector(allDeleteBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[_deleteView addSubview:allDeleteBtn];
|
||||
[self.deleteView addSubview:allDeleteBtn];
|
||||
|
||||
[self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerY.mas_equalTo(self.deleteView);
|
||||
make.left.mas_equalTo(0);
|
||||
make.width.mas_equalTo(screen_width/2);
|
||||
make.height.mas_equalTo(self.deleteView);
|
||||
make.top.height.mas_equalTo(self.deleteView);
|
||||
}];
|
||||
[allDeleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.height.mas_equalTo(self.deleteBtn);
|
||||
make.top.width.height.mas_equalTo(self.deleteBtn);
|
||||
make.left.mas_equalTo(self.deleteBtn.mas_right);
|
||||
}];
|
||||
|
||||
@@ -185,9 +188,7 @@ extern BOOL launchedByNotification;
|
||||
make.left.mas_equalTo(kSizeFrom750(30));
|
||||
make.right.mas_equalTo(-kSizeFrom750(30));
|
||||
make.height.mas_equalTo(ONE_PIXEL_SIZE);
|
||||
|
||||
}];
|
||||
|
||||
}
|
||||
#pragma mark --buttonClick
|
||||
-(void)deleBtnClick:(UIButton *)sender{
|
||||
@@ -196,7 +197,7 @@ extern BOOL launchedByNotification;
|
||||
[SVProgressHUD showInfoWithStatus:@"请先选择要删除的消息"];
|
||||
}else{
|
||||
//调用删除接口,删除选中的消息内容
|
||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"确认删除选中消息么" preferredStyle:UIAlertControllerStyleAlert];
|
||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"确认删除所有选中消息么" preferredStyle:UIAlertControllerStyleAlert];
|
||||
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
|
||||
NSLog(@"cancel Action");
|
||||
}];
|
||||
@@ -210,16 +211,22 @@ extern BOOL launchedByNotification;
|
||||
}
|
||||
}
|
||||
-(void)allDeleteBtnClick:(UIButton *)sender{
|
||||
|
||||
//全部为选中状态
|
||||
self.isDelteAll = YES;
|
||||
self.deleteBtn.selected = YES;
|
||||
[self.deleteArray removeAllObjects];
|
||||
for (NSArray *arr in self.dataSource) {
|
||||
for (PushmessageModel *model in arr) {
|
||||
[self.deleteArray addObject:model.pushId];
|
||||
if (!sender.selected) {//全选
|
||||
//全部为选中状态
|
||||
self.isDelteAll = YES;
|
||||
self.deleteBtn.selected = YES;
|
||||
[self.deleteArray removeAllObjects];
|
||||
for (NSArray *arr in self.dataSource) {
|
||||
for (PushmessageModel *model in arr) {
|
||||
[self.deleteArray addObject:model.pushId];
|
||||
}
|
||||
}
|
||||
}else{//取消全选
|
||||
[self.deleteArray removeAllObjects];
|
||||
self.isDelteAll = NO;
|
||||
self.deleteBtn.selected = NO;
|
||||
}
|
||||
sender.selected = !sender.selected;
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
#pragma mark --comboxView显示与隐藏
|
||||
@@ -259,20 +266,7 @@ extern BOOL launchedByNotification;
|
||||
-(void)getRequest
|
||||
{
|
||||
[SVProgressHUD show];
|
||||
NSDictionary *resalutDic = [CommonUtils getCacheDataWithKey:Cache_Message];
|
||||
if (resalutDic==nil) {
|
||||
self.pushId = @"";
|
||||
}else{
|
||||
NSArray *dataArray = [resalutDic objectForKey:@"data"];
|
||||
PushmessageModel *model = [PushmessageModel yy_modelWithJSON:dataArray.firstObject];
|
||||
self.pushId = model.pushId;
|
||||
for (int i=0; i<dataArray.count; i++) {
|
||||
PushmessageModel *cacheModel = [PushmessageModel yy_modelWithJSON:[dataArray objectAtIndex:i]];
|
||||
[cacheModel getCellHeight];
|
||||
[self.oldMessageArr addObject:cacheModel];
|
||||
}
|
||||
|
||||
}
|
||||
self.pushId = @"";
|
||||
UserModel*userModel=[dataContorl getUserInfo];
|
||||
NSDictionary *reqDic = @{@"pushId":self.pushId,
|
||||
@"userId":userModel.userId,
|
||||
@@ -284,28 +278,21 @@ extern BOOL launchedByNotification;
|
||||
NSString *totalCount = [successDic objectForKey:@"total"];
|
||||
NSArray *dataArray = [successDic objectForKey:@"data"];
|
||||
if ([totalCount integerValue]>0) {
|
||||
//判断是否已经有缓存
|
||||
NSDictionary *resalutDic = [CommonUtils getCacheDataWithKey:Cache_Message];
|
||||
if (resalutDic!=nil) {
|
||||
//原有缓存中的数据
|
||||
NSArray *cacheDataArray = [resalutDic objectForKey:@"data"];
|
||||
//新消息列表
|
||||
NSMutableArray *newDataArray = [NSMutableArray arrayWithArray:dataArray];
|
||||
[newDataArray addObjectsFromArray:cacheDataArray];
|
||||
NSMutableDictionary *newDic = InitObject(NSMutableDictionary);
|
||||
[newDic setObject:newDataArray forKey:@"data"];
|
||||
[CommonUtils SetCacheDataWithObject:newDic WithPathName:Cache_Message];
|
||||
}else{
|
||||
[CommonUtils SetCacheDataWithObject:successDic WithPathName:Cache_Message];
|
||||
}
|
||||
NSMutableArray *newMessageArray = InitObject(NSMutableArray);
|
||||
NSMutableArray *oldMessageArray = InitObject(NSMutableArray);
|
||||
for (int i=0; i<dataArray.count; i++) {
|
||||
PushmessageModel *cacheModel = [PushmessageModel yy_modelWithJSON:[dataArray objectAtIndex:i]];
|
||||
[cacheModel getCellHeight];
|
||||
[self.messageArray addObject:cacheModel];
|
||||
PushmessageModel *messageModel = [PushmessageModel yy_modelWithJSON:[dataArray objectAtIndex:i]];
|
||||
[messageModel getCellHeight];
|
||||
|
||||
if ([messageModel.isRead integerValue]==1) {//未读消息
|
||||
[newMessageArray addObject:messageModel];
|
||||
}else{
|
||||
[oldMessageArray addObject:messageModel];
|
||||
}
|
||||
}
|
||||
[self.dataSource addObject:newMessageArray];
|
||||
[self.dataSource addObject:oldMessageArray];
|
||||
}
|
||||
[self.dataSource addObject:self.messageArray];
|
||||
[self.dataSource addObject:self.oldMessageArr];
|
||||
[self.tableView reloadData];
|
||||
|
||||
|
||||
@@ -314,7 +301,63 @@ extern BOOL launchedByNotification;
|
||||
}];
|
||||
|
||||
}
|
||||
//删除接口
|
||||
//发送已读记录
|
||||
-(void)postReadMessageRequestWithIndexPath:(NSIndexPath *)indexPath{
|
||||
UserModel*userModel=[dataContorl getUserInfo];
|
||||
PushmessageModel *model = [[self.dataSource objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
|
||||
if([model.isRead integerValue]==1)//未读消息
|
||||
{
|
||||
NSMutableDictionary *deleteDic = InitObject(NSMutableDictionary);
|
||||
[deleteDic setValue:model.pushId forKey:@"pushId"];
|
||||
NSDictionary *reqDic = @{@"userId":userModel.userId,
|
||||
@"pushId":model.pushId
|
||||
};
|
||||
[[AFNOHeaderHttpTool sharedInstance] postRequestWihtUrl:Push_Message_Readed params:reqDic success:^(NSDictionary *successDic) {
|
||||
|
||||
NSString *result = [successDic objectForKey:RESPONSE_CODE];
|
||||
if ([result integerValue]==kReqSuccess) {
|
||||
//已读
|
||||
}else{
|
||||
|
||||
}
|
||||
} failure:^(NSDictionary *errorDic) {
|
||||
|
||||
}];
|
||||
}
|
||||
}
|
||||
//单独删除某一条消息
|
||||
-(void)deleteSingleMessageWithIndex:(NSIndexPath *)indexPath{
|
||||
|
||||
UserModel*userModel=[dataContorl getUserInfo];
|
||||
PushmessageModel *model = [[self.dataSource objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
|
||||
NSMutableDictionary *deleteDic = InitObject(NSMutableDictionary);
|
||||
[deleteDic setValue:model.pushId forKey:@"pushId"];
|
||||
NSDictionary *reqDic = @{@"userId":userModel.userId,
|
||||
@"pushIds":[CommonUtils arrayToJSONString:@[deleteDic]]
|
||||
};
|
||||
[SVProgressHUD show];
|
||||
[[AFNOHeaderHttpTool sharedInstance] postRequestWihtUrl:Push_Message_Delete_Url params:reqDic success:^(NSDictionary *successDic) {
|
||||
|
||||
NSString *result = [successDic objectForKey:RESPONSE_CODE];
|
||||
if ([result integerValue]==kReqSuccess) {
|
||||
[[self.dataSource objectAtIndex:indexPath.section] removeObjectAtIndex:indexPath.row];
|
||||
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
|
||||
// //刷新页面
|
||||
// [self.tableView reloadData];
|
||||
// [self.tableView scrollsToTop];
|
||||
}else{
|
||||
[SVProgressHUD showInfoWithStatus:@"删除失败"];
|
||||
}
|
||||
} failure:^(NSDictionary *errorDic) {
|
||||
[SVProgressHUD showInfoWithStatus:@"删除失败"];
|
||||
// self.deleteBtn.selected = NO;
|
||||
// [self.deleteView setHidden:YES];
|
||||
// [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
// make.bottom.mas_equalTo(self.view);
|
||||
// }];
|
||||
}];
|
||||
}
|
||||
//删除接口(多选删除)
|
||||
-(void)deleteMessage{
|
||||
UserModel*userModel=[dataContorl getUserInfo];
|
||||
NSMutableArray *deleteArray = InitObject(NSMutableArray);
|
||||
@@ -333,43 +376,19 @@ extern BOOL launchedByNotification;
|
||||
NSString *result = [successDic objectForKey:RESPONSE_CODE];
|
||||
if ([result integerValue]==kReqSuccess) {
|
||||
self.deleteBtn.selected = NO;
|
||||
NSDictionary *cacheDic = [CommonUtils getCacheDataWithKey:Cache_Message];
|
||||
NSArray *cacheArray = [cacheDic objectForKey:@"data"];
|
||||
NSMutableArray *newCacheArray = InitObject(NSMutableArray);
|
||||
//从缓存中删除已经删除的消息
|
||||
for (int i=0; i<cacheArray.count; i++) {
|
||||
NSDictionary *dic = [cacheArray objectAtIndex:i];
|
||||
NSString *cachePushId =[NSString stringWithFormat:@"%@",[dic objectForKey:@"pushId"]];
|
||||
if ([self.deleteArray containsObject:cachePushId]) {
|
||||
|
||||
}else{
|
||||
[newCacheArray addObject:dic];
|
||||
for (int i=0;i< self.dataSource.count;i++) {
|
||||
NSArray *arr = [self.dataSource objectAtIndex:i];
|
||||
NSMutableArray *newArray = InitObject(NSMutableArray);
|
||||
for (int j=0; j<arr.count; j++) {
|
||||
PushmessageModel *model = [arr objectAtIndex:j];
|
||||
if ([self.deleteArray containsObject:model.pushId]) {
|
||||
|
||||
}else{
|
||||
[newArray addObject:model];
|
||||
}
|
||||
}
|
||||
[self.dataSource setObject:newArray atIndexedSubscript:i];
|
||||
}
|
||||
[self.dataSource removeAllObjects];
|
||||
NSMutableArray *newArray = InitObject(NSMutableArray);
|
||||
NSMutableArray *oldArray = InitObject(NSMutableArray);
|
||||
//从新消息列表中剔除
|
||||
for (int i=0; i<self.messageArray.count; i++) {
|
||||
PushmessageModel *model = [self.messageArray objectAtIndex:i];
|
||||
if ([self.deleteArray containsObject:model.pushId]) {
|
||||
|
||||
}else{
|
||||
[newArray addObject:model];
|
||||
}
|
||||
}
|
||||
//从旧消息列表中剔除
|
||||
for (int i=0; i<self.oldMessageArr.count; i++) {
|
||||
PushmessageModel *model = [self.oldMessageArr objectAtIndex:i];
|
||||
if ([self.deleteArray containsObject:model.pushId]) {
|
||||
|
||||
}else{
|
||||
[oldArray addObject:model];
|
||||
}
|
||||
}
|
||||
[self.dataSource addObject:newArray];
|
||||
[self.dataSource addObject:oldArray];
|
||||
[CommonUtils SetCacheDataWithObject:[NSDictionary dictionaryWithObjectsAndKeys:newCacheArray,@"data", nil] WithPathName:Cache_Message];
|
||||
//走删除接口之后,清空删除内容数组
|
||||
[self.deleteArray removeAllObjects];
|
||||
self.isDelteAll = NO;
|
||||
@@ -498,25 +517,24 @@ extern BOOL launchedByNotification;
|
||||
//
|
||||
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
||||
|
||||
// [tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
[self.deleteArray removeAllObjects];
|
||||
[self.deleteView setHidden:YES];
|
||||
[self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.mas_equalTo(self.view);
|
||||
}];
|
||||
PushmessageModel *model = [[self.dataSource objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
|
||||
[self.deleteArray addObject:model.pushId];
|
||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"确认删除该消息么" preferredStyle:UIAlertControllerStyleAlert];
|
||||
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
|
||||
NSLog(@"cancel Action");
|
||||
}];
|
||||
UIAlertAction *delteActicon = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
||||
NSLog(@"delete Action");
|
||||
[self deleteMessage];
|
||||
}];
|
||||
[alertController addAction:cancelAction];
|
||||
[alertController addAction:delteActicon];
|
||||
[self presentViewController:alertController animated:YES completion:nil];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
[self postReadMessageRequestWithIndexPath:indexPath];
|
||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"确认删除该消息么" preferredStyle:UIAlertControllerStyleAlert];
|
||||
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
|
||||
NSLog(@"cancel Action");
|
||||
}];
|
||||
WEAK_SELF;
|
||||
UIAlertAction *delteActicon = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
||||
[weakSelf deleteSingleMessageWithIndex:indexPath];
|
||||
}];
|
||||
[alertController addAction:cancelAction];
|
||||
[alertController addAction:delteActicon];
|
||||
[weakSelf presentViewController:alertController animated:YES completion:nil];
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
-(void)viewWillAppear:(BOOL)animated{
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
Copy NSString *phoneType;
|
||||
//推送类型
|
||||
Copy NSString *jpushStatus;
|
||||
|
||||
Copy NSString *isRead;//1、未读 0 已读
|
||||
//创建时间
|
||||
@property(nonatomic,copy) NSString *createTime;
|
||||
//设备id
|
||||
|
||||
Reference in New Issue
Block a user