You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
425 lines
16 KiB
425 lines
16 KiB
// |
|
// MessageViewController.m |
|
// watch |
|
// |
|
// Created by xTT on 2017/7/13. |
|
// Copyright © 2017年 xTT. All rights reserved. |
|
// |
|
|
|
#import "RemindMessageViewController.h" |
|
#import "MessageTableViewCell.h" |
|
|
|
|
|
@interface RemindMessageViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate> |
|
|
|
@property (nonatomic ,strong) UITableView *myTableView; |
|
@property (nonatomic ,assign) NSInteger page; |
|
|
|
@property (nonatomic ,strong) NSMutableArray *temnArray; |
|
|
|
@end |
|
|
|
@implementation RemindMessageViewController |
|
|
|
|
|
- (UITableView *)myTableView |
|
{ |
|
if (!_myTableView) |
|
{ |
|
kWeakSelf(self) |
|
_myTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; |
|
_myTableView.backgroundColor = KKClearColor; |
|
_myTableView.delegate = self; |
|
_myTableView.dataSource = self; |
|
_myTableView.emptyDataSetSource = self; |
|
_myTableView.emptyDataSetDelegate = self; |
|
_myTableView.showsHorizontalScrollIndicator = NO; |
|
_myTableView.showsVerticalScrollIndicator = NO; |
|
_myTableView.estimatedRowHeight = 0; |
|
_myTableView.estimatedSectionHeaderHeight = 0; |
|
_myTableView.estimatedSectionFooterHeight = 0; |
|
if (@available(iOS 15.0, *)) { |
|
_myTableView.sectionHeaderTopPadding = 0; |
|
} |
|
|
|
|
|
//去线 |
|
//_myTableView.separatorStyle = UITableViewCellSelectionStyleNone; |
|
[_myTableView registerNib:[UINib nibWithNibName:@"MessageTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MessageTableViewCellID"]; |
|
[_myTableView bindHeadRefreshHandler:^{ |
|
[UICommon feedbackGenerator]; |
|
[weakself GetRemindList:TableisReload_h]; |
|
} themeColor:KKMainColor refreshStyle:KafkaRefreshStyleReplicatorWoody]; |
|
|
|
[_myTableView bindFootRefreshHandler:^{ |
|
[weakself GetRemindList:TableisReload_f]; |
|
} themeColor:KKMainColor refreshStyle:KafkaRefreshStyleReplicatorWoody]; |
|
|
|
} |
|
return _myTableView; |
|
} |
|
|
|
|
|
- (void)viewDidLoad { |
|
[super viewDidLoad]; |
|
self.emptyTitle = GJText(@"没有提醒消息"); |
|
self.emptyText = GJText(@"点击刷新一下"); |
|
self.ImgType = Xiaoxi; |
|
[self.view addSubview:self.myTableView]; |
|
[self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.edges.equalTo(self.view); |
|
}]; |
|
[self GetRemindList:TableisReload_h]; |
|
|
|
// Do any additional setup after loading the view. |
|
} |
|
|
|
#pragma mark 获取通知提醒 |
|
/// 获取通知提醒 |
|
- (void)GetRemindList:(TableisReload)isReload |
|
{ |
|
kWeakSelf(self) |
|
[UICommon MessageUpload:@"加载中"]; |
|
if (isReload == TableisReload_h) |
|
{ |
|
self.page = 1; |
|
[self.modelListArr removeAllObjects]; |
|
[self.temnArray removeAllObjects]; |
|
} |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[parameters setValue:@(self.page) forKey:@"current"]; |
|
[parameters setValue:@(KSizeNO) forKey:@"pageSize"]; |
|
[[[APIManager sharedManager] APGET:QueryRemind_URL parameters:parameters resultClass:BaseModel.class] subscribeNext:^(BaseModel *model) { |
|
[UICommon HidenLoading]; |
|
NSArray *arr = model.records; |
|
[weakself.myTableView.headRefreshControl endRefreshingWithAlertText:@"已为你加载最新数据~" completion:^{ |
|
|
|
}]; |
|
[weakself.myTableView.footRefreshControl endRefreshing]; |
|
for (NSDictionary *dic in arr) |
|
{ |
|
RemindModel *model = [RemindModel yy_modelWithJSON:dic]; |
|
NSString *dateStr = [UICommon getDateFormatWithStr:@"YYYY-MM-dd" |
|
date:[NSDate dateWithTimeIntervalSince1970:[self getTimeStrWithString:model.createTime]]]; |
|
model.time = dateStr; |
|
[self.temnArray addObject:model]; |
|
} |
|
NSMutableArray *tttttArr = [self.temnArray mutableCopy]; |
|
weakself.page++; |
|
weakself.myTableView.footRefreshControl.hidden = arr.count < KSizeNO ? YES : NO; |
|
|
|
[self.modelListArr removeAllObjects]; |
|
for (int i = 0; i < tttttArr.count; i++) |
|
{ |
|
RemindModel *model = tttttArr[i]; |
|
NSMutableArray *tempArr = [@[] mutableCopy]; |
|
[tempArr addObject:model]; |
|
for (int j = i+1; j < tttttArr.count; j ++) |
|
{ |
|
RemindModel *models = tttttArr[j]; |
|
if([model.time isEqualToString:models.time]) |
|
{ |
|
[tempArr addObject:models]; |
|
[tttttArr removeObjectAtIndex:j]; |
|
j -= 1; |
|
} |
|
} |
|
[self.modelListArr addObject:tempArr]; |
|
} |
|
|
|
[weakself.myTableView reloadData]; |
|
|
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
#pragma mark 删除通知提醒 |
|
/// 删除通知提醒 |
|
- (void)DeleteRemind |
|
{ |
|
[UICommon MessageUpload:@"加载中"]; |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[[[APIManager sharedManager] APPOST:DeleteRemind_URL parameters:parameters isJson:YES resultClass:nil] subscribeNext:^(id _Nullable x) { |
|
[UICommon HidenLoading]; |
|
[UICommon MessageSuccessText:@"删除成功"]; |
|
[self GetRemindList:TableisReload_h]; |
|
[[NSNotificationCenter defaultCenter] postNotificationName:KK_UPDATE_ALL_NEWS_MESSAGE object:nil]; |
|
|
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
|
|
//MARK :刪除方法 |
|
- (void)deletAction |
|
{ |
|
kWeakSelf(self) |
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:GJText(@"注意") message:GJText(@"确认要清空提醒消息?") style:LGAlertViewStyleAlert buttonTitles:@[GJText(@"确定")] cancelButtonTitle:GJText(@"取消") destructiveButtonTitle:nil actionHandler:^(LGAlertView * _Nonnull alertView, NSUInteger index, NSString * _Nullable title) { |
|
[weakself DeleteRemind]; |
|
} cancelHandler:^(LGAlertView * _Nonnull alertView) { |
|
} destructiveHandler:^(LGAlertView * _Nonnull alertView) { |
|
}]; |
|
[alertView showAnimated:YES completionHandler:nil]; |
|
} |
|
|
|
|
|
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView |
|
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath |
|
{ |
|
return UITableViewCellEditingStyleNone; |
|
} |
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section |
|
{ |
|
return [self.modelListArr[section] count]; |
|
} |
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView |
|
{ |
|
return self.modelListArr.count; |
|
} |
|
|
|
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section |
|
{ |
|
RemindModel *dMessage = self.modelListArr[section][0]; |
|
return dMessage.time; |
|
} |
|
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section |
|
{ |
|
return 30; |
|
} |
|
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath |
|
{ |
|
RemindModel *dMessage = self.modelListArr[indexPath.section][indexPath.row]; |
|
|
|
NSString *str = @""; |
|
if ([dMessage.type isEqualToString:@"sos"]) |
|
{ |
|
str = [NSString stringWithFormat:GJText(@"【%@】触发SOS!"),dMessage.name]; |
|
str = [NSString stringWithFormat:GJText(@"%@\n当前位置:%@"),str,dMessage.address]; |
|
} |
|
// else if ([dMessage.type isEqualToString:@"sms"]) { |
|
// str = [NSString stringWithFormat:@"【%@】SIM卡收到短信\n发件人:%@\n内容:%@",dMessage.name,dMessage.phone,dMessage.context]; |
|
// } |
|
else if ([dMessage.type isEqualToString:@"rail"]) { |
|
str = [NSString stringWithFormat:GJText(@"【%@】进入安全区域 %@"),dMessage.name,dMessage.address]; |
|
} |
|
else if ([dMessage.type isEqualToString:@"lowBattery"]) { |
|
str = [NSString stringWithFormat:GJText(@"【%@】设备当前电量%@%%"),dMessage.name,dMessage.battery]; |
|
} |
|
else if ([dMessage.type isEqualToString:@"photograph"]) { |
|
str = [NSString stringWithFormat:GJText(@"【%@】上传图册"),dMessage.name]; |
|
} |
|
else if ([dMessage.type isEqualToString:@"lp"]) { |
|
str = [NSString stringWithFormat:GJText(@"【%@】于%@进行了一次课外活动"),dMessage.name,dMessage.createTime]; |
|
} |
|
if (dMessage.msgContent.length > 0) { |
|
str = dMessage.msgContent; |
|
} |
|
return [self getLineHeight:str withWidth:SCREEN_WIDTH*(280.0/320) withFont:FontADA_(13)]; |
|
} |
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath |
|
{ |
|
RemindModel *dMessage = self.modelListArr[indexPath.section][indexPath.row]; |
|
ContextModel *contextModel = [ContextModel yy_modelWithJSON:dMessage.context]; |
|
MessageTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"MessageTableViewCellID" forIndexPath:indexPath]; |
|
cell.timeLabel.text = [UICommon getDateFormatWithStr:@"HH:mm" date:[UICommon getTimeStrWithString:dMessage.timestamp]]; //时间 |
|
if (dMessage.isSelect){ |
|
cell.selectImageView.image = [UIImage imageNamed:@"选中"]; |
|
}else{ |
|
cell.selectImageView.image = [UIImage imageNamed:@"CellGraySelected"]; |
|
} |
|
//信息 |
|
|
|
NSString * titleStr ; |
|
if ([dMessage.type isEqualToString:@"sos"]) { |
|
titleStr = GJText(@"求救报警"); |
|
NSString *tmp = [NSString stringWithFormat:GJText(@"【%@】触发SOS!"),dMessage.name]; |
|
NSInteger lenght = tmp.length; |
|
tmp = [NSString stringWithFormat:GJText(@"%@\n当前位置:%@"),tmp,contextModel.address]; |
|
|
|
NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:tmp]; |
|
[att addAttribute:NSForegroundColorAttributeName |
|
value:[UIColor redColor] |
|
range:NSMakeRange(0,lenght)]; |
|
cell.messageLabel.attributedText = att; |
|
|
|
} |
|
// else if ([dMessage.type isEqualToString:@"sms"]) { |
|
// titleStr = @"短信通知"; |
|
// cell.messageLabel.text = [NSString stringWithFormat:@"【%@】SIM卡收到短信\n发件人:%@\n内容:%@",dMessage.name,dMessage.phone,dMessage.context]; |
|
// } |
|
else if ([dMessage.type isEqualToString:@"rail"]) |
|
{ |
|
titleStr = @"区域报警"; |
|
NSLog(@"%@",dMessage.context); |
|
NSString *property = contextModel.property == 1 ? @"安全" : @"危险"; |
|
if ([contextModel.action isEqualToString:@"enter"]) |
|
{ |
|
cell.messageLabel.text = [NSString stringWithFormat:@"【%@】进入%@区域 【%@】",dMessage.name,property,contextModel.railName]; |
|
} |
|
else if ([contextModel.action isEqualToString:@"leave"]) |
|
{ |
|
cell.messageLabel.text = [NSString stringWithFormat:@"【%@】离开%@区域 【%@】",dMessage.name,property,contextModel.railName]; |
|
} |
|
} |
|
else if ([dMessage.type isEqualToString:@"lowBattery"]) { |
|
titleStr = GJText(@"低电报警"); |
|
|
|
cell.messageLabel.text = [NSString stringWithFormat:GJText(@"【%@】设备当前电量%@%%"),dMessage.name, contextModel.battery]; |
|
}else if ([dMessage.type isEqualToString:@"photograph"]) { |
|
titleStr = GJText(@"图册上传"); |
|
cell.messageLabel.text = [NSString stringWithFormat:GJText(@"【%@】上传图册"),dMessage.name]; |
|
}else if ([dMessage.type isEqualToString:@"abnormalBodyTemperature"]) { |
|
titleStr = GJText(@"体温异常报警"); |
|
if(dMessage.msgContent.length > 0){ |
|
cell.messageLabel.text = dMessage.msgContent; |
|
}else |
|
cell.messageLabel.text = [NSString stringWithFormat:GJText(@"【%@】设备当前监测体温为%@℃"),dMessage.name, dMessage.data]; |
|
}else if ([dMessage.type isEqualToString:@"abnormalHeartRate"]) { |
|
titleStr = GJText(@"心率异常报警"); |
|
if(dMessage.msgContent.length > 0){ |
|
cell.messageLabel.text = dMessage.msgContent; |
|
}else |
|
cell.messageLabel.text = [NSString stringWithFormat:GJText(@"【%@】设备当前监测心率为%@次/分"),dMessage.name, dMessage.data]; |
|
} |
|
else if ([dMessage.type isEqualToString:@"lp"]) { |
|
titleStr = GJText(@"课外活动"); |
|
cell.messageLabel.text = [NSString stringWithFormat:GJText(@"【%@】于%@进行了一次课外活动"),dMessage.name,dMessage.createTime]; |
|
} |
|
|
|
if(dMessage.msgContent.length > 0){ |
|
cell.messageLabel.text = dMessage.msgContent; |
|
} |
|
|
|
if(dMessage.messageRead && [dMessage.messageRead intValue] == 0) { |
|
cell.readLabel.hidden = NO; |
|
}else{ |
|
cell.readLabel.hidden = YES; |
|
} |
|
|
|
cell.aTitleLabel.text = titleStr; |
|
cell.timeLabel.text = [self dateWithTimeInterval:F(@"%ld",[self getTimeStrWithString:dMessage.createTime])]; |
|
return cell; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath |
|
{ |
|
RemindModel *dMessage = self.modelListArr[indexPath.section][indexPath.row]; |
|
if (dMessage.messageRead && [dMessage.messageRead intValue] == 0) { |
|
[UICommon MessageUpload:@"加载中"]; |
|
[self updateRemind:dMessage]; |
|
} |
|
} |
|
//- (void)viewWillDisappear:(BOOL)animated |
|
//{ |
|
// [super viewWillDisappear:animated]; |
|
// [self xiaoxiyidu]; |
|
//} |
|
|
|
|
|
- (void)xiaoxiyidu |
|
{ |
|
[self.modelListArr enumerateObjectsUsingBlock:^(RemindModel *model, NSUInteger idx, BOOL * _Nonnull stop) { |
|
if (model.messageRead && model.messageRead == 0) |
|
{ |
|
[self updateRemind:model]; |
|
} |
|
}]; |
|
} |
|
|
|
- (void)updateRemind:(RemindModel *)model |
|
{ |
|
kWeakSelf(self) |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[parameters setValue:model.Id forKey:@"id"]; |
|
[parameters setValue:@"1" forKey:@"messageRead"]; |
|
[[[APIManager sharedManager] APPOST:UpdateRemind_URL parameters:parameters isJson:YES resultClass:nil] subscribeNext:^(id _Nullable x) { |
|
[UICommon HidenLoading]; |
|
model.messageRead = @"1"; |
|
[weakself.myTableView reloadData]; |
|
[[NSNotificationCenter defaultCenter] postNotificationName:KK_UPDATE_ALL_NEWS_MESSAGE object:nil]; |
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
|
|
- (CGFloat)getLineHeight:(NSString *)string withWidth:(CGFloat)width withFont:(UIFont *)font |
|
{ |
|
UILabel *label = [[UILabel alloc]init]; |
|
label.numberOfLines = 0; |
|
label.lineBreakMode = NSLineBreakByWordWrapping; |
|
label.textAlignment = NSTextAlignmentLeft; |
|
label.text = string; |
|
label.font = font; |
|
CGSize labelSize = [label sizeThatFits:CGSizeMake(width, MAXFLOAT)]; |
|
CGFloat height = ceil(labelSize.height) + 1 + 34 + 10 +8; |
|
//换行符的 行数 |
|
NSUInteger number = [[string componentsSeparatedByString:@"\n"] count]; |
|
if(number > 1){ |
|
height += (number-1) * 21; |
|
} |
|
|
|
// xLog(@"文本框应该高 Height :%f ", height); |
|
if(height < 66){ |
|
height = 66; |
|
} |
|
return height; |
|
} |
|
|
|
#pragma mark - DZNEmptyDataSetSource,DZNEmptyDataSetDelegate |
|
- (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view |
|
{ |
|
[self GetRemindList:TableisReload_h]; |
|
} |
|
|
|
|
|
#pragma mark 时间戳 转日期 (yyyy-MM-dd HH:mm:ss SS) |
|
// 时间戳转时间,时间戳为13位是精确到毫秒的,10位精确到秒 |
|
- (NSString *)dateWithTimeInterval:(NSString *)timeStr { |
|
|
|
// 传入的时间戳timeStr如果是精确到秒的记得要/1000 |
|
NSTimeInterval timeInterval = [timeStr doubleValue]/1000; |
|
NSDate *detailDate = [NSDate dateWithTimeIntervalSince1970:timeInterval]; |
|
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; |
|
// 实例化一个NSDateFormatter对象,设定时间格式,这里可以设置成自己需要的格式 |
|
[dateFormatter setDateFormat:@"HH:mm"]; |
|
NSString *dateStr = [dateFormatter stringFromDate:detailDate]; |
|
|
|
return dateStr; |
|
} |
|
|
|
// 字符串转时间戳 如:2017-4-10 17:15:10 (精确到毫秒*1000) |
|
- (NSInteger)getTimeStrWithString:(NSString *)str |
|
{ |
|
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];// 创建一个时间格式化对象 |
|
[dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; //设定时间的格式 |
|
NSDate *tempDate = [dateFormatter dateFromString:str];//将字符串转换为时间对象 |
|
NSInteger timeStr = [tempDate timeIntervalSince1970]*1000;//字符串转成时间戳,精确到毫秒*1000 |
|
return timeStr; |
|
} |
|
|
|
- (NSMutableArray *)temnArray |
|
{ |
|
if (!_temnArray) _temnArray = [NSMutableArray new]; |
|
return _temnArray; |
|
} |
|
|
|
@end
|
|
|