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.
 
 
 
 

344 lines
13 KiB

//
// TrackViewController.m
// watch
//
// Created by xTT on 2017/7/13.
// Copyright © 2017年 xTT. All rights reserved.
//
#import "TrackViewController.h"
#import "NewTrackMsgCell.h"
//高德
#import <MAMapKit/MAMapKit.h>
#import <AMapLocationKit/AMapLocationKit.h>
#import <AMapSearchKit/AMapSearchKit.h>
@interface TrackViewController ()<AMapSearchDelegate>
/**
这个是逆地理位置编码的请求的列表 和 Locate 的 Model 对应
*/
@property (nonatomic, strong) NSMutableArray *AMapSearchList;
//逆地理编码
@property (nonatomic, strong) AMapReGeocodeSearchRequest *regeo;
//逆地理编码使用的
@property (nonatomic, strong) AMapSearchAPI *search;
/**
需要上传的 解析完的 坐标点的 参数
*/
@property (nonatomic, strong) NSMutableArray *shouldUpdateLocateAddressList;
/**
需要上传的定位点的ID 集合列表
*/
@property (nonatomic, strong) NSMutableArray *shouldUpdateIDList;
@end
@implementation TrackViewController
-(NSMutableArray *)shouldUpdateIDList{
if(!_shouldUpdateIDList){
_shouldUpdateIDList = [NSMutableArray array];
}
return _shouldUpdateIDList;
}
-(NSMutableArray *)shouldUpdateLocateAddressList{
if(!_shouldUpdateLocateAddressList){
_shouldUpdateLocateAddressList = [NSMutableArray array];
}
return _shouldUpdateLocateAddressList;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.zx_hideBaseNavBar = YES;
// //检查隐私合规
// [MAMapView updatePrivacyShow:AMapPrivacyShowStatusDidShow privacyInfo:AMapPrivacyInfoStatusDidContain];
// [MAMapView updatePrivacyAgree:AMapPrivacyAgreeStatusDidAgree];
// [AMapSearchAPI updatePrivacyShow:(AMapPrivacyShowStatusDidShow) privacyInfo:(AMapPrivacyInfoStatusDidContain)];
[self.myTableView registerNib:[UINib nibWithNibName:@"NewTrackMsgCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"NewTrackMsgCellID"];
//去线
self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.myTableView.mj_footer beginRefreshing];
self.view.backgroundColor = self.myTableView.backgroundColor;
self.isSetTranslucent = NO;
[self setUI];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
//重新设置 🈚数据的 图
[self.noDataSourceImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.centerY.equalTo(self.view).mas_offset(-getRectNavAndStatusHight);
}];
[self.noReachableImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.centerY.equalTo(self.view).mas_offset(-getRectNavAndStatusHight);
}];
}
-(void)setUI{
Device * mainDevice = cUser.cDevice;
UIImage * defaImage ;
if([mainDevice.sex isEqualToString:@"girl"]){
//女
defaImage = [myHelper getImageWithName: @"icon_girl_head_portrait_1"];
}else{
//男
defaImage = [myHelper getImageWithName: @"icon_boy_head_portrait_1"];
}
[self.deviceImageView sd_setImageWithURL:[NSURL URLWithString:mainDevice.avator]
placeholderImage:defaImage];
self.deviceImageView.layer.cornerRadius = self.deviceImageView.height/2;
self.deviceImageView.layer.masksToBounds = YES;
self.allCountTrackLabel.text = @"";
[self.delectBtn addTarget:self action:@selector(delectAction:) forControlEvents:UIControlEventTouchUpInside];
//默认隐藏
self.headCollectionView.hidden = YES;
//默认显示 无数据
[self showNoDataSourceView];
}
- (void)delectAction:(UIButton*)sender{
WEAKSELF
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"确定删除轨迹?" message:@"" style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:@"取消" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) {
[Track delectTrackWithDailyIds:@[self.infoTrack.id] success:^(id responseObject) {
[weakSelf.myDataSource removeAllObjects];
[weakSelf.myTableView reloadData];
weakSelf.headCollectionView.hidden = YES;
weakSelf.infoTrack = nil;
//显示 无数据
[weakSelf showNoDataSourceView];
if(weakSelf.delectBlockCall){
weakSelf.delectBlockCall();
}
xLog(@"删除轨迹点成功");
} failure:^{
xLog(@"删除轨迹点失败");
} ];
} cancelHandler:nil destructiveHandler:nil];
[alertView showAnimated:YES completionHandler:nil];
}
- (void)loadWithInfoTrack:(Track*)track Back:(BlockCall)blockCall{
// [self.view getViewController]
if(!track){
self.headCollectionView.hidden = YES;
[self.myDataSource removeAllObjects];
[self.myTableView reloadData];
[self showNoDataSourceView];
if(blockCall){
blockCall();
}
return;
}else{
self.headCollectionView.hidden = NO;
[self hiddenNoReachableView];
}
self.infoTrack = track;
NSString *tmp = [NSString stringWithFormat:@"%ld条轨迹",(long)track.amount.integerValue];
NSInteger lenght = tmp.length;
NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:tmp];
[att addAttribute:NSForegroundColorAttributeName
value:mainColor
range:NSMakeRange(0,lenght-3)];
self.allCountTrackLabel.attributedText = att;
if(self.AMapSearchList){
[self.AMapSearchList removeAllObjects];
self.AMapSearchList = nil;
}
self.AMapSearchList = [NSMutableArray array];
WEAKSELF
[track getTrackInfoSuccess:^(NSMutableArray *arr) {
NSArray *tempArr = [arr copy];
[weakSelf.shouldUpdateIDList removeAllObjects];
for (int i=0; i<tempArr.count; i++) {
Locate * model = tempArr[i];
AMapReGeocodeSearchRequest *regeo = [[AMapReGeocodeSearchRequest alloc]init];
regeo.requireExtension = YES;
regeo.location = [AMapGeoPoint locationWithLatitude:model.lat.doubleValue longitude:model.lon.doubleValue];
[weakSelf.AMapSearchList addObject:regeo];
if ((model.address && model.address.length == 0 )|| model.address == nil){
[weakSelf.shouldUpdateIDList addObject:model.id];
}
}
[weakSelf.myDataSource removeAllObjects];
[weakSelf.myDataSource addObjectsFromArray:@[tempArr]];
[weakSelf.myTableView reloadData];
[weakSelf showNoDataSourceView];
if(blockCall){
blockCall();
}
} failure:^(NSError *error){
if (!error) {
[weakSelf showNoReachableView];
}
if(blockCall){
blockCall();
}
}];
}
- (AMapReGeocodeSearchRequest *)regeo {
if (!_regeo) {
_regeo = [[AMapReGeocodeSearchRequest alloc]init];
_regeo.requireExtension = YES;
}
return _regeo;
}
- (AMapSearchAPI *)search {
if (!_search) {
_search = [[AMapSearchAPI alloc]init];
_search.delegate = self;
}
return _search;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
Locate *locate = self.myDataSource[indexPath.section][indexPath.row];
if (self.AMapSearchList.count > 0) {
self.regeo = self.AMapSearchList[indexPath.row];
if( (locate.address && locate.address.length == 0 )|| locate.address == nil){
[self.search AMapReGoecodeSearch:self.regeo];
}
}
NSString *dateStr = [myHelper getDateFormatWithStr:@"HH:mm"
date:[NSDate dateWithTimeIntervalSince1970:[locate.timestamp doubleValue]]];
// MARK: 增加停留时间 add by lsz 2021-06-24
long seconds = [locate.endtime integerValue] - [locate.timestamp integerValue];
NSString *stayTime = [self secondToTime:seconds];
NewTrackMsgCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NewTrackMsgCellID" forIndexPath:indexPath];
if([self.myDataSource[indexPath.section] count] == 1){
//起,不绘制虚线
[cell setIconType:0 WithAddress:locate.address WithTime:dateStr CanShapeToView:NO StayTime:stayTime];
return cell;
}
if(indexPath.section == 0){
if (indexPath.row == 0) {
[cell setIconType:2 WithAddress:locate.address WithTime:dateStr CanShapeToView:YES StayTime:stayTime];
}else if([self.myDataSource[indexPath.section] count] -1 == indexPath.row){
[cell setIconType:0 WithAddress:locate.address WithTime:dateStr CanShapeToView:NO StayTime:stayTime];
}else{
[cell setIconType:1 WithAddress:locate.address WithTime:dateStr CanShapeToView:YES StayTime:stayTime];
}
}
return cell;
}
- (NSString *)secondToTime:(long)seconds {
long days = seconds/86400;
seconds = seconds%86400;
long hours = seconds/3600;
seconds = seconds%3600;
long minutes = ceil(seconds/60.0);
seconds = seconds%60;
if (days > 0) {
return [NSString stringWithFormat:@"停留%zd天%zd小时%zd分",days,hours,minutes];
} else if (hours > 0) {
return [NSString stringWithFormat:@"停留%zd小时%zd分",hours,minutes];
} else if(minutes > 0) {
return [NSString stringWithFormat:@"停留%zd分",minutes];
} else {
return @"0";
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 60;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark ====高德地图位置解析回调====
- (void)AMapSearchRequest:(id)request didFailWithError:(NSError *)error
{
NSLog(@"%@",error);
}
-(void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response{
if (response.regeocode != nil)
{
NSString *name = response.regeocode.formattedAddress;
//解析response获取地址描述,具体解析见 Demo
// //获取市
// NSString *city = response.regeocode.addressComponent.city;
// NSString *province = response.regeocode.addressComponent.province;
// if(city && city.length>0){
// name = [name componentsSeparatedByString:city].lastObject;
// if([city isEqualToString:province]){
// //直辖市
// name = [NSString stringWithFormat:@"%@ %@",name,city];
// }else{
// //普通市
// name = [NSString stringWithFormat:@"%@ %@ %@",name,city,province];
// }
// }
if(self.AMapSearchList.count > 0){
NSInteger index = [self.AMapSearchList indexOfObject:request];
if(index != NSNotFound &&
self.myDataSource.count > 0 &&
index < [self.myDataSource[0] count]){
Locate * indexModel = self.myDataSource[0][index];
if([self.shouldUpdateIDList containsObject:indexModel.id]){
indexModel.address = name;
NSMutableDictionary *param = [NSMutableDictionary dictionary];
[param setValue:indexModel.id forKey:@"locationId"];
[param setValue:name forKey:@"address"];
[self.shouldUpdateLocateAddressList addObject:param];
[self.myTableView reloadData];
}
if (self.shouldUpdateLocateAddressList.count == self.shouldUpdateIDList.count){
//上传某天定位点 的 解析位置数据
WEAKSELF
[self.infoTrack postLocationsAddress:self.shouldUpdateLocateAddressList success:^(id responseObject) {
xLog(@"APP解析的 位置上传成功");
[weakSelf.shouldUpdateLocateAddressList removeAllObjects];
[weakSelf.shouldUpdateIDList removeAllObjects];
} failure:^{
[weakSelf.shouldUpdateLocateAddressList removeAllObjects];
[weakSelf.shouldUpdateIDList removeAllObjects];
xLog(@"APP解析的 位置上传失败");
}];
}
}
}
}
}
@end