//
|
// HDLEZDeviceMsgListView.m
|
// EZSDK
|
//
|
// Created by 陈启扬 on 2023/3/16.
|
//
|
|
#import "HDLEZDeviceMsgListView.h"
|
#import "HDLEZDeviceMsgCell.h"
|
#import "HDLEZVideoDoorMsgCell.h"
|
|
@interface HDLEZDeviceMsgListView ()
|
|
@property (copy, nonatomic) void(^previewPic)(NSString *pictureUrl);
|
|
@end
|
|
@implementation HDLEZDeviceMsgListView{
|
CGFloat cellHeight;
|
}
|
|
-(instancetype)init{
|
self = [super init];
|
if (self) {
|
self.backgroundColor = HDLEZ_COLOR_VIEW_BACKGROUND;
|
// self.backgroundColor = [UIColor greenColor];
|
|
self.separatorStyle = NO;
|
self.showsVerticalScrollIndicator=NO;
|
self.delegate = self;
|
self.dataSource = self;
|
cellHeight=80;
|
self.rowHeight = UITableViewAutomaticDimension;
|
self.estimatedRowHeight = 80;
|
[self registerClass:[HDLEZVideoDoorMsgCell class] forCellReuseIdentifier:@"HDLEZVideoDoorMsgCell"];
|
[self setSeparatorInset:UIEdgeInsetsZero];
|
// [self setLayoutMargins:UIEdgeInsetsZero];
|
}
|
|
return self;
|
}
|
|
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
return 1;
|
}
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
return _msgList.count;
|
}
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
return UITableViewAutomaticDimension;
|
}
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
HDLEZLog(@"初始化cell");
|
HDLEZVideoDoorMsgCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HDLEZVideoDoorMsgCell" forIndexPath:indexPath];
|
if(cell == nil){
|
cell=[[HDLEZVideoDoorMsgCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"HDLEZVideoDoorMsgCell"];
|
}
|
[self configCell:cell indexPath:indexPath];
|
// HDLEZDeviceMsgCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HDLEZDeviceMsgCell"];
|
// if(cell == nil){
|
// cell=[[HDLEZDeviceMsgCell alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, cellHeight)];
|
// }
|
// HDLEZDeviceMsgInfoModel *model=self.msgList[indexPath.row];
|
// cell.msgInfo=model;
|
// HDLEZLog(@"初始化cell ID:%@",model.extVisitorId);
|
|
return cell;
|
|
}
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
if (self.msgList.count <= indexPath.row) return;
|
HDLEZDeviceMsgInfoModel *messageModel = self.msgList[indexPath.row];
|
if (self.previewPic && messageModel.imageUrl && messageModel.imageUrl.length > 0) {
|
self.previewPic(messageModel.imageUrl);
|
}
|
}
|
|
#pragma mark - PublishMethod
|
- (void)previewPicture:(void(^)(NSString *pictureUrl))previewPic {
|
self.previewPic = previewPic;
|
}
|
|
#pragma mark - PrivateMethod
|
- (void)configCell:(HDLEZVideoDoorMsgCell *)cell indexPath:(NSIndexPath *)indexPath {
|
if (self.msgList.count <= indexPath.row) return;
|
|
HDLEZDeviceMsgInfoModel *messageModel = self.msgList[indexPath.row];
|
|
#warning mock
|
NSString *stataus = @"";
|
if (indexPath.row == 0) {
|
stataus = @"未接";
|
messageModel.createTime = @"";
|
} else if (indexPath.row == 1) {
|
stataus = @"已接";
|
}
|
if (messageModel.createTime && messageModel.createTime.length == 13) {
|
messageModel.createTime = [messageModel.createTime substringToIndex:10];
|
}
|
NSString *messageTime = [self turnDate:messageModel.createTime];
|
[cell configMessageInfoWithTitle:messageModel.content deviceStatus:stataus messageTime:messageTime messageImage:indexPath.row != 0 ? messageModel.imageUrl : @""];
|
[cell showSpearator:(self.msgList.count != indexPath.row + 1)];
|
}
|
|
/*时间戳转时间
|
*/
|
-(NSString *)turnDate:(NSString*)dateStr{
|
return [HDLEZConstants timeStrWithFormate:@"yyyy.MM.dd HH:mm" data:[NSDate dateWithTimeIntervalSince1970:[dateStr integerValue]]];;
|
}
|
|
/*设置消息列表值
|
*/
|
-(void)setMsgList:(NSArray<HDLEZDeviceMsgInfoModel *> *)msgList{
|
_msgList=msgList;
|
[self reloadData];
|
}
|
@end
|