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.
407 lines
14 KiB
407 lines
14 KiB
// |
|
// HomeHeaderView.m |
|
// LekangGuard |
|
// |
|
// Created by ecell on 2022/10/14. |
|
// |
|
|
|
#import "HomeHeaderView.h" |
|
#import <WebKit/WebKit.h> |
|
|
|
#import "KJBannerView.h" |
|
#import "MoreServiceViewController.h" |
|
#import "ContactsViewController.h" |
|
#import "EditDeviceViewController.h" |
|
#import "ChatViewController.h" |
|
#import "VideoChatViewController.h" |
|
|
|
|
|
@interface HomeHeaderView () |
|
|
|
@property (nonatomic ,weak) KJBannerView *bannerView; |
|
|
|
/// 手表信息View |
|
@property (nonatomic ,weak) UIView *msgView; |
|
|
|
/// 按钮菜单View |
|
@property (nonatomic ,weak) UIView *btnView; |
|
|
|
/// 头像 |
|
@property (nonatomic ,weak) UIButton *iconBtn; |
|
|
|
/// 名称 |
|
@property (nonatomic ,weak) UILabel *nameLabel; |
|
|
|
/// 电量图片 |
|
@property (nonatomic ,weak) UIImageView *electricityImg; |
|
|
|
/// 电量Label |
|
@property (nonatomic ,weak) UILabel *electricityLabel; |
|
|
|
/// 定位时间Label |
|
@property (nonatomic ,weak) UILabel *timeLabel; |
|
|
|
/// 位置未知提示 |
|
@property (nonatomic ,weak) UILabel *addLabel; |
|
|
|
/// 定位图片 |
|
@property (nonatomic ,weak) UIImageView *mapImg; |
|
|
|
|
|
@property (nonatomic ,strong) NSMutableArray *btnArr; |
|
|
|
@end |
|
|
|
@implementation HomeHeaderView |
|
|
|
- (instancetype)initWithFrame:(CGRect)frame |
|
{ |
|
self = [super initWithFrame:frame]; |
|
if (self) |
|
{ |
|
self.backgroundColor = KKClearColor; |
|
[self subHeaderView]; |
|
} |
|
return self; |
|
} |
|
- (void)setDevicemodel:(DeviceModel *)devicemodel |
|
{ |
|
_devicemodel = devicemodel; |
|
self.nameLabel.text = devicemodel.name; |
|
if (devicemodel.image.length <= 0) |
|
[self.iconBtn setBackgroundImage:ImageName_(devicemodel.sex == 2 ? @"icon_head_girl" : @"icon_head_boy") forState:0]; |
|
else |
|
[self.iconBtn sd_setBackgroundImageWithURL:[NSURL URLWithString:devicemodel.image] forState:0 placeholderImage:ImageName_(@"icon_head_boy")]; |
|
[self subBtnView]; |
|
|
|
} |
|
|
|
|
|
|
|
- (void)setBannerArr:(NSArray *)bannerArr |
|
{ |
|
_bannerArr = bannerArr; |
|
self.bannerView.imageDatas = bannerArr; |
|
} |
|
|
|
- (void)setLaLoModel:(LatestLocationModel *)laLoModel |
|
{ |
|
_laLoModel = laLoModel; |
|
self.electricityLabel.text = F(@"%ld%%", laLoModel.battery); |
|
self.electricityImg.image = [UICommon GetElectricityImg:laLoModel.battery]; |
|
|
|
|
|
if (STRINGHASVALUE(laLoModel.updateTime)) |
|
{ |
|
self.timeLabel.text = laLoModel.updateTime; |
|
CGSize titlesize = [laLoModel.updateTime sizeWithFont:FontADA_(9) constrainedToSize:CGSizeMake(MAXFLOAT, 15)]; |
|
[self.timeLabel mas_remakeConstraints:^(MASConstraintMaker *make) { |
|
make.right.equalTo(self.electricityImg.mas_left).inset(10); |
|
make.centerY.equalTo(self.electricityImg); |
|
make.size.mas_equalTo(CGSizeMake(Adapted(titlesize.width), 15)); |
|
}]; |
|
} |
|
|
|
if (STRINGHASVALUE(laLoModel.addr)) |
|
self.addLabel.text = laLoModel.addr; |
|
|
|
/// 定位类型 LBS GPS,WIFI |
|
if ([laLoModel.locationType isEqualToString:@"LBS"]) |
|
self.mapImg.image = ImageName_(@"icon_home_base_station"); |
|
else if ([laLoModel.locationType isEqualToString:@"GPS"]) |
|
self.mapImg.image = ImageName_(@"icon_histroy_g"); |
|
else if ([laLoModel.locationType isEqualToString:@"WIFI"]) |
|
self.mapImg.image = ImageName_(@"icon_home_wifi"); |
|
|
|
[self.mapImg mas_remakeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(self.iconBtn.mas_right).offset(10); |
|
make.bottom.equalTo(self.iconBtn.mas_bottom).inset(6); |
|
make.size.mas_equalTo(self.mapImg.image.size); |
|
}]; |
|
} |
|
|
|
- (void)setIsDev:(BOOL)isDev |
|
{ |
|
_isDev = isDev; |
|
self.msgView.hidden = isDev; |
|
self.btnView.hidden = isDev; |
|
} |
|
|
|
- (void)subHeaderView |
|
{ |
|
KJBannerView *bannerView = [[KJBannerView alloc]initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH-20, Adapted(160))]; |
|
//bannerView.imgCornerRadius = 5; |
|
bannerView.autoScrollTimeInterval = 8; |
|
//bannerView.isZoom = YES; |
|
//bannerView.itemWidth = SCREEN_WIDTH-50; |
|
bannerView.imageType = KJBannerViewImageTypeNetIamge; |
|
bannerView.bannerImageViewContentMode = UIViewContentModeScaleToFill; |
|
bannerView.pageControl.selectColor = KKMainColor; |
|
bannerView.imageDatas = @[@"home_banner"]; |
|
self.bannerView = bannerView; |
|
[self addSubview:bannerView]; |
|
|
|
UIView *msgView = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:5 borderWidth:0 borderColor:KKWhiteColorColor]; |
|
msgView.hidden = YES; |
|
self.msgView = msgView; |
|
[self addSubview:msgView]; |
|
[msgView mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(self).inset(10); |
|
make.top.equalTo(bannerView.mas_bottom).offset(10); |
|
make.height.mas_equalTo(Adapted(80)); |
|
}]; |
|
|
|
/// 头像 |
|
UIButton *iconBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(0) normalColor:KKClearColor normalText:@"" click:^(id x) { |
|
EditDeviceViewController *vc = [EditDeviceViewController new]; |
|
[[UICommon currentVC].navigationController pushViewController:vc animated:YES]; |
|
}]; |
|
//[iconBtn setBackgroundImage:ImageName_(@"icon_head_girl") forState:0]; |
|
iconBtn.layer.cornerRadius = Adapted(25); |
|
iconBtn.layer.masksToBounds = YES; |
|
self.iconBtn = iconBtn; |
|
[msgView addSubview:iconBtn]; |
|
[iconBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(msgView).offset(10); |
|
make.centerY.equalTo(msgView); |
|
make.size.mas_equalTo(CGSizeMake(Adapted(50), Adapted(50))); |
|
}]; |
|
|
|
/// 修改图片 |
|
UIImageView *img = [UICommon ui_imageView:CGRectZero fileName:@"home_editor_icon"]; |
|
[msgView addSubview:img]; |
|
[img mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.right.equalTo(iconBtn.mas_right); |
|
make.bottom.equalTo(iconBtn.mas_bottom); |
|
make.size.mas_equalTo(img.image.size); |
|
}]; |
|
|
|
/// 名称 |
|
UILabel *nameLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontADA_(14) textColor:KKTextBlackColor text:@"--" Radius:0]; |
|
self.nameLabel = nameLabel; |
|
[msgView addSubview:nameLabel]; |
|
[nameLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(iconBtn.mas_right).offset(10); |
|
make.top.equalTo(iconBtn); |
|
}]; |
|
|
|
/// 电量Label |
|
UILabel *electricityLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontADA_(11) textColor:KKGrey102 text:@"" Radius:0]; |
|
self.electricityLabel = electricityLabel; |
|
[msgView addSubview:electricityLabel]; |
|
[electricityLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.right.equalTo(msgView.mas_right).inset(10); |
|
make.centerY.equalTo(nameLabel); |
|
}]; |
|
|
|
/// 电池图片 |
|
UIImage *imgs = ImageName_(@"icon_home_electricity_100"); |
|
UIImageView *electricityImg = [UICommon ui_imageView:CGRectZero fileName:@""]; |
|
self.electricityImg = electricityImg; |
|
[msgView addSubview:electricityImg]; |
|
[electricityImg mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.right.equalTo(electricityLabel.mas_left).inset(2); |
|
make.centerY.equalTo(electricityLabel); |
|
make.size.mas_equalTo(imgs.size); |
|
}]; |
|
|
|
/// 定位时间Label |
|
UILabel *timeLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontADA_(9) textColor:KKMainColor text:@"" Radius:3]; |
|
timeLabel.backgroundColor = RGBA(88, 157, 245, .2); |
|
self.timeLabel = timeLabel; |
|
[msgView addSubview:timeLabel]; |
|
[timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.right.equalTo(electricityImg.mas_left).inset(10); |
|
make.centerY.equalTo(electricityImg); |
|
}]; |
|
|
|
/// 定位图片 |
|
UIImageView *mapImg = [UICommon ui_imageView:CGRectZero fileName:@"home_gps_icon"]; |
|
self.mapImg = mapImg; |
|
[msgView addSubview:mapImg]; |
|
[mapImg mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(iconBtn.mas_right).offset(10); |
|
make.bottom.equalTo(iconBtn.mas_bottom).inset(6); |
|
make.size.mas_equalTo(mapImg.image.size); |
|
}]; |
|
|
|
/// 定位图片后面分割线 |
|
UILabel *line = [UILabel new]; |
|
line.backgroundColor = KKGrey143; |
|
[msgView addSubview:line]; |
|
[line mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(mapImg.mas_right).offset(5); |
|
make.centerY.equalTo(mapImg); |
|
make.size.mas_equalTo(CGSizeMake(0.5, 15)); |
|
}]; |
|
|
|
/// 位置未知提示 |
|
UILabel *addLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontADA_(12) textColor:KKTextBlackColor text:GJText(@"当前位置未知,点击进行定位") Radius:0]; |
|
self.addLabel = addLabel; |
|
[msgView addSubview:addLabel]; |
|
[addLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(line.mas_left).offset(5); |
|
make.right.equalTo(msgView.mas_right).inset(10); |
|
make.centerY.equalTo(line); |
|
}]; |
|
|
|
|
|
UIButton *locationBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(0) normalColor:KKWhiteColorColor normalText:@"" click:^(id x) { |
|
[UICommon currentVC].tabBarController.selectedIndex = 1; |
|
}]; |
|
[msgView addSubview:locationBtn]; |
|
[locationBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(nameLabel.mas_left); |
|
make.right.equalTo(msgView.mas_right); |
|
make.top.equalTo(msgView); |
|
make.bottom.equalTo(msgView.mas_bottom); |
|
}]; |
|
|
|
UIView *bgView = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:5 borderWidth:0 borderColor:KKWhiteColorColor]; |
|
bgView.hidden = YES; |
|
self.btnView = bgView; |
|
[self addSubview:bgView]; |
|
[bgView mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(self).inset(10); |
|
make.top.equalTo(msgView.mas_bottom).offset(10); |
|
make.bottom.equalTo(self.mas_bottom).inset(15); |
|
}]; |
|
} |
|
|
|
- (void)subBtnView |
|
{ |
|
for (UIButton *views in self.btnView.subviews) |
|
{ |
|
[views removeFromSuperview]; |
|
} |
|
self.btnArr = [NSMutableArray new]; |
|
|
|
NSMutableArray *titleArray = [NSMutableArray new]; |
|
NSMutableArray *imageArray = [NSMutableArray new]; |
|
if (self.devicemodel.videoModelName > 0) |
|
{ |
|
[titleArray addObject:GJText(@"视频")]; |
|
[imageArray addObject:@"home_icon_more_video_call"]; |
|
} |
|
else |
|
{ |
|
[titleArray addObject:GJText(@"电话本")]; |
|
[imageArray addObject:@"home_phone_book_icon"]; |
|
} |
|
if (self.devicemodel.chatFun) |
|
{ |
|
[titleArray addObject:GJText(@"微聊")]; |
|
[imageArray addObject:@"home_small_talk_icon"]; |
|
} |
|
if (self.devicemodel.phoneCall) |
|
{ |
|
[titleArray addObject:GJText(@"打电话")]; |
|
[imageArray addObject:@"home_call_up_icon"]; |
|
} |
|
[titleArray addObject:GJText(@"更多")]; |
|
[imageArray addObject:@"home_more_icon"]; |
|
|
|
|
|
CGFloat masx = (SCREEN_WIDTH-44)/titleArray.count; |
|
for (int i = 0; i < titleArray.count; i++) |
|
{ |
|
NSString *title = [titleArray objectAtIndex:i]; |
|
NSString *image = [imageArray objectAtIndex:i]; |
|
ZZBadgeButton *button = [self createButtonWithTitle:title image:image]; |
|
[button addTarget:self action:@selector(buttonClickAction:) forControlEvents:UIControlEventTouchUpInside]; |
|
button.tag = i; |
|
button.frame = CGRectMake(i*masx+12, Adapted(15), masx, masx); |
|
[self.btnView addSubview:button]; |
|
[self.btnArr addObject:button]; |
|
} |
|
} |
|
|
|
- (void)setUnreadTotal:(NSInteger)unreadTotal |
|
{ |
|
for (ZZBadgeButton *button in self.btnArr) |
|
{ |
|
if([button.currentTitle isEqualToString:GJText(@"微聊")]) |
|
{ |
|
button.badge = unreadTotal; |
|
return; |
|
} |
|
} |
|
} |
|
|
|
- (void)buttonClickAction:(UIButton *)btn |
|
{ |
|
if ([btn.currentTitle isEqualToString:GJText(@"电话本")]) |
|
{ |
|
ContactsViewController *vc = [ContactsViewController new]; |
|
[[UICommon currentVC].navigationController pushViewController:vc animated:YES]; |
|
} |
|
else if ([btn.currentTitle isEqualToString:GJText(@"视频")]) |
|
{ |
|
VideoChatViewController *vc = [VideoChatViewController new]; |
|
[[UICommon currentVC].navigationController pushViewController:vc animated:YES]; |
|
} |
|
else if ([btn.currentTitle isEqualToString:GJText(@"微聊")]) |
|
{ |
|
ChatViewController *vc = [ChatViewController new]; |
|
vc.messageCoutnUpdata = ^{ |
|
[self GetUnreadTotal]; |
|
}; |
|
[[UICommon currentVC].navigationController pushViewController:vc animated:YES]; |
|
} |
|
else if ([btn.currentTitle isEqualToString:GJText(@"打电话")]) |
|
{ |
|
if(self.devicemodel.phone.length == 0) |
|
{ |
|
|
|
} |
|
else |
|
{ |
|
NSString * string = [[NSMutableString alloc] initWithFormat:@"tel:%@",self.devicemodel.phone]; |
|
if(self.devicemodel.phone.length == 11) |
|
string = [NSString stringWithFormat:@"tel:+86-%@", self.devicemodel.phone]; |
|
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:string] options:@{} completionHandler:nil]; |
|
} |
|
} |
|
else if ([btn.currentTitle isEqualToString:GJText(@"更多")]) |
|
{ |
|
MoreServiceViewController *vc = [MoreServiceViewController new]; |
|
[[UICommon currentVC].navigationController pushViewController:vc animated:YES]; |
|
} |
|
} |
|
|
|
|
|
- (ZZBadgeButton *)createButtonWithTitle:(NSString *)title image:(NSString *)image |
|
{ |
|
ZZBadgeButton *customButton = [[ZZBadgeButton alloc] init]; |
|
customButton.titleLabel.font = FontADA_(12); |
|
[customButton setTitle:title forState:UIControlStateNormal]; |
|
[customButton setTitleColor:RGB(153, 153, 153) forState:UIControlStateNormal]; |
|
[customButton setImage:[UIImage imageNamed:image] forState:UIControlStateNormal]; |
|
return customButton; |
|
} |
|
|
|
#pragma mark 查询当前设备用户微聊未读消息数 |
|
/// 查询当前设备用户微聊未读消息数 |
|
- (void)GetUnreadTotal |
|
{ |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[parameters setValue:APIManager.sharedManager.deviceModel.groupid forKey:@"groupId"]; |
|
[[[APIManager sharedManager] APGET:UnreadTotal_URL parameters:parameters resultClass:nil] subscribeNext:^(NSString *x) { |
|
[UICommon HidenLoading]; |
|
NSInteger coutn = x.integerValue; |
|
[self setUnreadTotal:coutn]; |
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
/* |
|
// Only override drawRect: if you perform custom drawing. |
|
// An empty implementation adversely affects performance during animation. |
|
- (void)drawRect:(CGRect)rect { |
|
// Drawing code |
|
} |
|
*/ |
|
|
|
@end
|
|
|