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.
422 lines
15 KiB
422 lines
15 KiB
![]()
2 years ago
|
//
|
||
|
// HomeViewController.m
|
||
|
// LekangGuard
|
||
|
//
|
||
|
// Created by ecell on 2022/9/27.
|
||
|
//
|
||
|
|
||
|
#import "HomeViewController.h"
|
||
|
#import "ScanCodeViewController.h"
|
||
|
#import "HomeTableViewCell.h"
|
||
|
#import "HomeHeaderView.h"
|
||
|
#import "HAndTViewController.h"
|
||
|
#import "JCManager.h"
|
||
|
#import "BRManager.h"
|
||
|
#import "TihuManager.h"
|
||
|
#import <JCSDKOC/JCSDKOC.h>
|
||
|
|
||
|
@interface HomeViewController ()<YBPopupMenuDelegate,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>
|
||
|
|
||
|
@property (nonatomic ,strong) NSMutableArray *menuTitles;
|
||
|
@property (nonatomic ,strong) NSMutableArray *menuIcons;
|
||
|
|
||
|
|
||
|
@property (nonatomic ,strong) CommonTableView *homeTable;
|
||
|
@property (nonatomic ,strong) HomeHeaderView *headerView;
|
||
|
|
||
|
/// 设备列表Arr
|
||
|
@property (nonatomic ,strong) NSMutableArray *deviceListArr;
|
||
|
|
||
|
@property (nonatomic ,strong) NSMutableArray *cellMenuArr;
|
||
|
|
||
|
|
||
|
@property (nonatomic ,strong) LatestLocationModel *laloModel;
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation HomeViewController
|
||
|
|
||
|
- (void)viewDidLoad {
|
||
|
[super viewDidLoad];
|
||
|
// Do any additional setup after loading the view.
|
||
|
UIImageView *bgImg = [UICommon ui_imageView:self.view.frame fileName:@"home_bg"];
|
||
|
self.ImgType = HomeNoWhat;
|
||
|
self.emptyTitle = GJText(@"您还没有绑定设备");
|
||
|
self.emptyText = GJText(@"赶快去绑定一个设备体验一下吧!");
|
||
|
self.buttonTitle = GJText(@"添加设备");
|
||
|
|
||
|
self.buttonImg = ImageName_(@"home_addBtn");
|
||
|
[self.view addSubview:bgImg];
|
||
|
self.zx_navTitle = GJText(@"首页");
|
||
|
self.zx_navRightBtn.zx_fixImageSize = ImageName_(@"home_icon_add").size;
|
||
|
self.zx_navRightBtn.zx_fixWidth = 40;
|
||
|
self.zx_navRightBtn.zx_fixHeight = 40;
|
||
|
[self zx_setRightBtnWithImg:ImageName_(@"home_icon_add") clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
|
||
|
[self isShowMenu];
|
||
|
}];
|
||
|
[self setTotal];
|
||
|
[self QueryMsg];
|
||
|
[self GetDeviceList];
|
||
|
[self GetBannerList];
|
||
|
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:UPDATA_DeviceList object:nil] subscribeNext:^(NSNotification *x) {
|
||
|
[self GetDeviceList];
|
||
|
}];
|
||
|
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:@"updateBatteryAndLocation" object:nil] subscribeNext:^(NSNotification *x)
|
||
|
{
|
||
|
[self GetLatest:APIManager.sharedManager.deviceModel.imei];
|
||
|
}];
|
||
|
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:@"deviceNowLocation" object:nil] subscribeNext:^(NSNotification *x)
|
||
|
{
|
||
|
[self GetLatest:APIManager.sharedManager.deviceModel.imei];
|
||
|
}];
|
||
|
|
||
|
[self.view addSubview:self.homeTable];
|
||
|
[self.homeTable mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.top.equalTo(self.view).offset(iPhoneX_NavHeight);
|
||
|
make.left.right.equalTo(self.view);
|
||
|
make.bottom.equalTo(self.view.mas_bottom);
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
/// 收到推送聊天信息
|
||
|
- (void)pusChatMessage:(NSDictionary *)chatModel
|
||
|
{
|
||
|
[self.headerView GetUnreadTotal];
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
- (CommonTableView *)homeTable
|
||
|
{
|
||
|
if (!_homeTable)
|
||
|
{
|
||
|
kWeakSelf(self)
|
||
|
_homeTable = [[CommonTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain cellHeight:100 cellRow:0 isAdaptive:NO isLine:NO commonCell:HomeTableViewCell.class createCell:^(ZZTableViewCell * _Nonnull cells, NSIndexPath * _Nonnull indexPath) {
|
||
|
|
||
|
HomeTableViewCell *cell = (HomeTableViewCell *)cells;
|
||
|
if (indexPath.row < weakself.cellMenuArr.count)
|
||
|
{
|
||
|
cell.titleStr = weakself.cellMenuArr[indexPath.row];
|
||
|
cell.laLoModel = self.laloModel;
|
||
|
}
|
||
|
|
||
|
} selectedCell:^(UITableView * _Nonnull tableView, NSIndexPath * _Nonnull indexPath) {
|
||
|
NSString *title = self.cellMenuArr[indexPath.row];
|
||
|
HAndTViewController *vc = [HAndTViewController new];
|
||
|
vc.type = [title isEqualToString:GJText(@"心率")] ? 1 : 2;
|
||
|
[self.navigationController pushViewController:vc animated:YES];
|
||
|
|
||
|
} DidscrollView:^(UIScrollView * _Nonnull scrollView) {
|
||
|
|
||
|
}];
|
||
|
_homeTable.tableHeaderView = self.headerView;
|
||
|
_homeTable.tableHeaderView.height = Adapted(320)+35;
|
||
|
_homeTable.backgroundColor = KKClearColor;
|
||
|
[_homeTable bindHeadRefreshHandler:^{
|
||
|
[self GetDeviceList];
|
||
|
[self GetBannerList];
|
||
|
} themeColor:KKMainColor refreshStyle:KafkaRefreshStyleReplicatorWoody];
|
||
|
}
|
||
|
return _homeTable;
|
||
|
}
|
||
|
|
||
|
- (HomeHeaderView *)headerView
|
||
|
{
|
||
|
if (!_headerView)
|
||
|
{
|
||
|
_headerView = [HomeHeaderView new];
|
||
|
_headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, Adapted(320)+35);
|
||
|
}
|
||
|
return _headerView;
|
||
|
}
|
||
|
|
||
|
|
||
|
- (void)isShowMenu
|
||
|
{
|
||
|
CGPoint p = CGPointMake(SCREEN_WIDTH - 30, iPhoneX_NavHeight - 10);
|
||
|
[YBPopupMenu showAtPoint:p titles:self.menuTitles icons:self.menuIcons menuWidth:120*(SCREEN_WIDTH/320) otherSettings:^(YBPopupMenu *popupMenu) {
|
||
|
popupMenu.textColor = KKWhiteColorColor;
|
||
|
popupMenu.fontSize = 15;
|
||
|
popupMenu.cornerRadius = 4.0f;
|
||
|
popupMenu.dismissOnSelected = NO;
|
||
|
popupMenu.delegate = self;
|
||
|
popupMenu.offset = 5;
|
||
|
popupMenu.type = YBPopupMenuTypeDark;
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
#pragma mark - YBPopupMenuDelegate 代理方法
|
||
|
- (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu
|
||
|
{
|
||
|
[ybPopupMenu dismiss];
|
||
|
if(index == 0)
|
||
|
{
|
||
|
ScanCodeViewController *vc = [ScanCodeViewController new];
|
||
|
[self.navigationController pushViewController:vc animated:YES];
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
DeviceModel *model = self.deviceListArr[index-1];
|
||
|
[self GetDeviceMenu:model];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#pragma mark 获取设备列表
|
||
|
/// 获取设备列表
|
||
|
- (void)GetDeviceList
|
||
|
{
|
||
|
kWeakSelf(self)
|
||
|
self.menuTitles = [NSMutableArray new];
|
||
|
self.menuIcons = [NSMutableArray new];
|
||
|
|
||
|
[self.menuTitles insertObject:GJText(@"添加手表") atIndex:0];
|
||
|
[self.menuIcons insertObject:@"home_icon_add_watch" atIndex:0];
|
||
|
[UICommon MessageUpload:@"加载中"];
|
||
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
|
||
|
[[[APIManager sharedManager] APGET:BindDevice_URL parameters:parameters resultClass:nil] subscribeNext:^(NSArray *arr) {
|
||
|
[UICommon HidenLoading];
|
||
|
[self.homeTable.headRefreshControl endRefreshing];
|
||
|
[self.deviceListArr removeAllObjects];
|
||
|
for (NSDictionary *dic in arr)
|
||
|
{
|
||
|
DeviceModel *model = [DeviceModel yy_modelWithJSON:dic];
|
||
|
if (model.image.length <= 0)
|
||
|
[self.menuIcons addObject:model.sex == 2 ? @"icon_girl_head_portrait" : @"icon_boy_head_portrait"];
|
||
|
else
|
||
|
[self.menuIcons addObject:model.image];
|
||
|
[self.menuTitles addObject:model.name];
|
||
|
[self.deviceListArr addObject:model];
|
||
|
}
|
||
|
|
||
|
if (arr.count > 0)
|
||
|
{
|
||
|
|
||
|
weakself.homeTable.emptyDataSetSource = nil;
|
||
|
weakself.homeTable.emptyDataSetDelegate = nil;
|
||
|
if (STRINGHASVALUE(APIManager.sharedManager.deviceModel.imei))
|
||
|
{
|
||
|
[self.deviceListArr enumerateObjectsUsingBlock:^(DeviceModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||
|
if ([obj.imei isEqualToString:APIManager.sharedManager.deviceModel.imei])
|
||
|
[self GetDeviceMenu:obj];
|
||
|
}];
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
DeviceModel *model = [DeviceModel yy_modelWithJSON:arr[0]];
|
||
|
[self GetDeviceMenu:model];
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
[self GetDeviceMenu:[DeviceModel new]];
|
||
|
weakself.homeTable.emptyDataSetSource = self;
|
||
|
weakself.homeTable.emptyDataSetDelegate = self;
|
||
|
}
|
||
|
self.homeTable.tableHeaderView.height = arr.count == 0 ? Adapted(190) : Adapted(320)+35;
|
||
|
self.headerView.isDev = arr.count == 0 ? YES : NO;
|
||
|
} error:^(NSError * _Nullable error) {
|
||
|
NSDictionary *dic = error.userInfo;
|
||
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
|
||
|
[self.homeTable.headRefreshControl endRefreshing];
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
#pragma mark 动态显示设备功能列
|
||
|
/// 动态显示设备功能列
|
||
|
- (void)GetDeviceMenu:(DeviceModel *)model
|
||
|
{
|
||
|
APIManager.sharedManager.deviceModel = model;
|
||
|
[APIManager.sharedManager.cache setObject:model forKey:sDeviceKey];
|
||
|
|
||
|
self.headerView.devicemodel = model;
|
||
|
[self GetLatest:model.imei];
|
||
|
[self GetLatestInstructions:model.imei];
|
||
|
|
||
|
[self.cellMenuArr removeAllObjects];
|
||
|
if (model.heartRate)
|
||
|
[self.cellMenuArr addObject:GJText(@"心率")];
|
||
|
if (model.temperature)
|
||
|
[self.cellMenuArr addObject:GJText(@"体温")];
|
||
|
self.homeTable.cellRow = self.cellMenuArr.count;
|
||
|
[self.homeTable reloadData];
|
||
|
/// 视频类型名称(0.不支持,1.菊风,2.声网,3.佰锐,4.鹈鹕)
|
||
|
if (model.videoModelName == 1)
|
||
|
{
|
||
|
// 拥有菊风的设备,需要登录 账号 (调试时期暂时停止)
|
||
|
if(![JCManager shared].client)
|
||
|
{
|
||
|
// if([[JCManager shared] initializeWithAPPKey:model.appKey])
|
||
|
// {
|
||
|
// JCClientLoginParam* loginParam = [[JCClientLoginParam alloc] init];
|
||
|
// //loginParam.directConnectEnable = YES;
|
||
|
// [[JCManager shared].client setServerAddress:@"http:cn.router.justalkcloud.com:8080"];
|
||
|
// [[JCManager shared].client login:APIManager.sharedManager.loginModel.openid password:@"test" loginParam:nil];
|
||
|
// [JCManager shared].gMianVC = self;
|
||
|
// NSLog(@"菊风账号是:%@", APIManager.sharedManager.loginModel.openid);
|
||
|
// }
|
||
|
}
|
||
|
}
|
||
|
else if (model.videoModelName == 3)
|
||
|
{
|
||
|
// 拥有佰锐的设备,需要登录 账号
|
||
|
if (![[BRManager shared] isUserLogin]) {
|
||
|
[[BRManager shared] initialize];
|
||
|
[BRManager shared].gMianVC = self;
|
||
|
[[BRManager shared] login:model.baiRuiId nick:model.name];
|
||
|
} else {
|
||
|
NSLog(@"====================>佰锐视频账号已经登录");
|
||
|
}
|
||
|
}
|
||
|
else if (model.videoModelName == 2)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
else if (model.videoModelName == 4)
|
||
|
{
|
||
|
// 拥有鹈鹕的设备,需要登录账号
|
||
|
if (![[TihuManager shared] isUserLogin]) {
|
||
|
[[TihuManager shared] initialize];
|
||
|
[TihuManager shared].gMianVC = self;
|
||
|
[[TihuManager shared] login:APIManager.sharedManager.loginModel.openid pwd:@"123456"];
|
||
|
|
||
|
NSLog(@"鹈鹕账号是:%@", APIManager.sharedManager.loginModel.openid);
|
||
|
} else {
|
||
|
NSLog(@"====>鹈鹕视频账号已经登录");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#pragma mark 获取banner图
|
||
|
/// 获取banner图
|
||
|
- (void)GetBannerList
|
||
|
{
|
||
|
[UICommon MessageUpload:GJText(@"加载中")];
|
||
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
|
||
|
[[[APIManager sharedManager] APPOST:Home_banner_URL parameters:parameters isJson:YES resultClass:nil] subscribeNext:^(NSArray *x) {
|
||
|
[UICommon HidenLoading];
|
||
|
if (ARRAYHASVALUE(x))
|
||
|
{
|
||
|
NSMutableArray *bannerArr = [NSMutableArray new];
|
||
|
for (NSDictionary *dic in x)
|
||
|
{
|
||
|
BannerModel *model = [BannerModel yy_modelWithJSON:dic];
|
||
|
[bannerArr addObject:model.banner];
|
||
|
}
|
||
|
self.headerView.bannerArr = bannerArr;
|
||
|
}
|
||
|
|
||
|
} error:^(NSError * _Nullable error) {
|
||
|
NSDictionary *dic = error.userInfo;
|
||
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
#pragma mark 获取设备最新位置信息
|
||
|
/// 获取设备最新位置信息
|
||
|
- (void)GetLatest:(NSString *)imei
|
||
|
{
|
||
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
|
||
|
[[[APIManager sharedManager] APGET:F(@"%@/%@", Latest_location_app_URL,imei) parameters:parameters resultClass:LatestLocationModel.class] subscribeNext:^(LatestLocationModel *model) {
|
||
|
[UICommon HidenLoading];
|
||
|
self.laloModel = model;
|
||
|
self.headerView.laLoModel = model;
|
||
|
[self.homeTable reloadData];
|
||
|
NSLog(@"-->%@",model);
|
||
|
} error:^(NSError * _Nullable error) {
|
||
|
NSDictionary *dic = error.userInfo;
|
||
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
|
||
|
#pragma mark 主动请求位置下发
|
||
|
/// 主动请求位置下发
|
||
|
- (void)GetLatestInstructions:(NSString *)imei
|
||
|
{
|
||
|
[UICommon MessageUpload:@"加载中"];
|
||
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
|
||
|
[[[APIManager sharedManager] APGET:F(@"%@/%@", Latest_location_app_instructions_URL,imei) parameters:parameters resultClass:nil] subscribeNext:^(id _Nullable x) {
|
||
|
[UICommon HidenLoading];
|
||
|
NSLog(@"-->%@",x);
|
||
|
} error:^(NSError * _Nullable error) {
|
||
|
NSDictionary *dic = error.userInfo;
|
||
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
#pragma mark 查看个人资料
|
||
|
/// 查看个人资料
|
||
|
- (void)QueryMsg
|
||
|
{
|
||
|
[UICommon MessageUpload:@"加载中"];
|
||
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
|
||
|
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"];
|
||
|
[[[APIManager sharedManager] APGET:QueryMsg_URL parameters:parameters resultClass:MyUserMsgModel.class] subscribeNext:^(MyUserMsgModel *model) {
|
||
|
[UICommon HidenLoading];
|
||
|
|
||
|
} error:^(NSError * _Nullable error) {
|
||
|
NSDictionary *dic = error.userInfo;
|
||
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
#pragma mark 用户活跃度统计上传
|
||
|
/// 用户活跃度统计上传
|
||
|
- (void)setTotal
|
||
|
{
|
||
|
// NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
|
||
|
// NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
|
||
|
// [parameters setValue:@"lekangshouhu" forKey:@"channelName"];
|
||
|
// [parameters setValue:version forKey:@"version"];
|
||
|
// [[[APIManager sharedManager] APGET:Total_URL parameters:parameters resultClass:MyUserMsgModel.class] subscribeNext:^(MyUserMsgModel *model) {
|
||
|
// [UICommon HidenLoading];
|
||
|
//
|
||
|
// } error:^(NSError * _Nullable error) {
|
||
|
// NSDictionary *dic = error.userInfo;
|
||
|
// [UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
|
||
|
// }];
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
- (NSMutableArray *)deviceListArr
|
||
|
{
|
||
|
if (!_deviceListArr) _deviceListArr = [NSMutableArray new];
|
||
|
return _deviceListArr;
|
||
|
}
|
||
|
|
||
|
- (NSMutableArray *)cellMenuArr
|
||
|
{
|
||
|
if (!_cellMenuArr) _cellMenuArr = [NSMutableArray new];
|
||
|
return _cellMenuArr;
|
||
|
}
|
||
|
|
||
|
- (void)updateAllMessage
|
||
|
{
|
||
|
[self GetDeviceList];
|
||
|
}
|
||
|
|
||
|
- (void)emptyDataSet:(UIScrollView *)scrollView didTapButton:(UIButton *)button
|
||
|
{
|
||
|
ScanCodeViewController *vc = [ScanCodeViewController new];
|
||
|
[self.navigationController pushViewController:vc animated:YES];
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
#pragma mark - Navigation
|
||
|
|
||
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
||
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
||
|
// Get the new view controller using [segue destinationViewController].
|
||
|
// Pass the selected object to the new view controller.
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
@end
|