Skip to content

Commit

Permalink
修改将服务器获取日期转换为控件时间格式适用;和安卓对齐时间段拼接方案
Browse files Browse the repository at this point in the history
Tapd: http://tapd.oa.com/NEW_IOT/prong/stories/view/102039319286441266
Change-Id: I07c06cc1b2c83a96cbf3dcbf9456084cd0348ab5
  • Loading branch information
ccharlesren committed May 18, 2021
1 parent a542984 commit 6e7284a
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 8 deletions.
95 changes: 91 additions & 4 deletions Source/LinkSDKDemo/Home/Controllers/Device/TIoTCloudStorageVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ @interface TIoTCloudStorageVC ()<UIScrollViewDelegate>
@property (nonatomic, strong) UILabel *timeLabel;
@property (atomic, retain) IJKFFMoviePlayerController *player;
@property (nonatomic, strong) NSString *videoUrl;
@property (nonatomic, strong) NSArray *timeList; //原始时间
@property (nonatomic, strong) NSMutableArray *modelArray; //重组后存放时间数组

@property (nonatomic, assign) CGFloat kTopPadding; //距离日历间距
@property (nonatomic, assign) CGFloat kLeftPadding; //左边距
Expand Down Expand Up @@ -91,10 +93,7 @@ - (void)setupUIViews {

//自定义slider
TIoTCustomTimeSlider *customTimeSlider = [[TIoTCustomTimeSlider alloc]initWithFrame:CGRectMake(0, 0, self.kScrollContentWidth - self.kLeftPadding*2, self.kSliderHeight)];
TIoTTimeModel *timeModel = [[TIoTTimeModel alloc]init];
timeModel.startTime = 0;
timeModel.endTime = 0;
customTimeSlider.timeSegmentArray = @[timeModel];
customTimeSlider.timeSegmentArray = self.modelArray;
[self.sliderBottomView addSubview:customTimeSlider];
[customTimeSlider addObserver:self forKeyPath:@"currentValue" options:NSKeyValueObservingOptionNew context:nil];

Expand Down Expand Up @@ -141,6 +140,13 @@ - (void)requestCloudStorageDayDate {
paramDic[@"Version"] = @"2020-12-15";

[[TIoTCoreDeviceSet shared] requestVideoOrExploreDataWithParam:paramDic action:DescribeCloudStorageTime vidowOrExploreHost:TIotApiHostVideo success:^(id _Nonnull responseObject) {
TIoTCloudStorageDayTimeListModel *data = [TIoTCloudStorageDayTimeListModel yy_modelWithJSON:responseObject[@"Response"][@"Data"]];

//data.VideoURL 需要拼接

self.timeList = [NSArray arrayWithArray:data.TimeList?:@[]];

[self recombineTimeSegmentWithTimeArray:self.timeList];

} failure:^(NSString * _Nullable reason, NSError * _Nullable error, NSDictionary * _Nullable dic) {

Expand Down Expand Up @@ -194,6 +200,79 @@ - (NSString *)getStampDateStringWithSecond:(NSInteger )secondTime {
return stampDate;
}

- (void)recombineTimeSegmentWithTimeArray:(NSArray *)timeArray {

if (self.modelArray.count != 0) {
[self.modelArray removeAllObjects];
}

[timeArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
TIoTCloudStorageTimeDataModel *model = obj;

if (idx == 0) {
TIoTTimeModel *timeModel = [[TIoTTimeModel alloc]init];
timeModel.startTime = model.StartTime.doubleValue;
timeModel.endTime = model.EndTime.doubleValue;

[self.modelArray addObject:timeModel];

}else {
TIoTTimeModel *timeModel = [[TIoTTimeModel alloc]init];
timeModel.startTime = model.StartTime.doubleValue;
timeModel.endTime = model.EndTime.doubleValue;

NSMutableArray *tempModelArray = [[NSMutableArray alloc]initWithArray:self.modelArray];
TIoTTimeModel *lastModel = tempModelArray.lastObject;
if (timeModel.startTime - lastModel.endTime <= 60) {

lastModel.endTime = timeModel.endTime;

[self.modelArray replaceObjectAtIndex:(tempModelArray.count - 1) withObject:lastModel];
}else {
[self.modelArray addObject:timeModel];
}

}
}];

[self convertTimeArrayItemParam];
}

- (void)convertTimeArrayItemParam{
if (self.modelArray.count != 0) {
[self.modelArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
TIoTTimeModel *itemModel = obj;

TIoTTimeModel *timeModel = [[TIoTTimeModel alloc]init];
timeModel.startTime = [self captureTimestampWithOutDaySecound:itemModel.startTime];
timeModel.endTime = [self captureTimestampWithOutDaySecound:itemModel.endTime];

[self.modelArray replaceObjectAtIndex:idx withObject:timeModel];
}];
}
}

- (NSInteger )captureTimestampWithOutDaySecound:(CGFloat)stamp {

CGFloat timeStamp = stamp;
NSString *dateString = [NSString convertTimestampToTime:@(timeStamp) byDateFormat:@"YYYY-MM-dd HH:mm:ss"]?:@"";

NSArray *dateTempArray = [dateString componentsSeparatedByString:@" "];
NSString *dayTime = dateTempArray.lastObject;
NSArray *dayTempTime = [dayTime componentsSeparatedByString:@":"];
NSString *hourString = dayTempTime.firstObject;
NSString *mitString = dayTempTime[1];
NSString *secString = dayTempTime.lastObject;

NSInteger hour = hourString.intValue;
NSInteger minute = mitString.intValue;
NSInteger second = secString.intValue;

NSInteger totalSecond = second + minute*60 + hour*3600;

return totalSecond;
}

- (void)dealloc
{
[self stopPlayMovie];
Expand Down Expand Up @@ -246,6 +325,14 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
self.sliderBottomView.frame = CGRectMake(-scrollView.contentOffset.x + self.kLeftPadding, CGRectGetMaxY(self.calendarBtn.frame)+self.kTopPadding, self.kScrollContentWidth - self.kLeftPadding*2, self.kSliderHeight);
}

#pragma mark - lazy loading
- (NSMutableArray *)modelArray {
if (!_modelArray) {
_modelArray = [[NSMutableArray alloc]init];
}
return _modelArray;
}

/*
#pragma mark - Navigation
Expand Down
8 changes: 4 additions & 4 deletions TIoTLinkKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
6D06B07C25619FE6006361B5 /* TIoTAutoAddManualIntelliListVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D06B07B25619FE6006361B5 /* TIoTAutoAddManualIntelliListVC.m */; };
6D06B0802561A1DB006361B5 /* TIoTAutoAddManualIntellListCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D06B07F2561A1DB006361B5 /* TIoTAutoAddManualIntellListCell.m */; };
6D18DF2925E50BA4009CF65E /* TIoTWeatherVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D18DF2825E50BA4009CF65E /* TIoTWeatherVC.swift */; };
6D20480E26528199007F6F27 /* TIoTCloudStorageDateModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D20480D26528199007F6F27 /* TIoTCloudStorageDateModel.m */; };
6D20483E26528A71007F6F27 /* TIoTCloudStorageDayTimeListModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D20483D26528A71007F6F27 /* TIoTCloudStorageDayTimeListModel.m */; };
6D2049EB2653C189007F6F27 /* TIoTCloudStorageDayTimeListModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D20483D26528A71007F6F27 /* TIoTCloudStorageDayTimeListModel.m */; };
6D2049EE2653C18D007F6F27 /* TIoTCloudStorageDateModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D20480D26528199007F6F27 /* TIoTCloudStorageDateModel.m */; };
6D257FFD25DFC330005208C2 /* TIoTTabBarCenterCustomView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D257FFC25DFC330005208C2 /* TIoTTabBarCenterCustomView.m */; };
6D42390C261F5F8500C3A5A7 /* TIoTGateWayBindDeviceModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D42390B261F5F8500C3A5A7 /* TIoTGateWayBindDeviceModel.m */; };
6D423910261F5FCD00C3A5A7 /* TIoTSecureAddDeviceModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D42390F261F5FCD00C3A5A7 /* TIoTSecureAddDeviceModel.m */; };
Expand Down Expand Up @@ -3192,7 +3192,6 @@
D20621BB23559E5600142DAC /* TYCyclePagerView.m in Sources */,
ED729062238E669600175739 /* TIoTUploadObj.m in Sources */,
D2038BBA23321EA80036F6B9 /* TIoTAddTimeView.m in Sources */,
6D20483E26528A71007F6F27 /* TIoTCloudStorageDayTimeListModel.m in Sources */,
6D6489B1257D37C7000B340F /* TIoTSingleCustomButton.m in Sources */,
EDF93D9923B367A000D477C7 /* TIoTRequestObject.m in Sources */,
ED93D98D23CBFDD000E3FD7D /* TIoTLoginVC.m in Sources */,
Expand Down Expand Up @@ -3238,7 +3237,6 @@
EDF126FE23BDBE8D00FB1638 /* TIoTWaterFlowLayout.m in Sources */,
D23104D52330678F0003069D /* NSObject+SwizzlingMethod.m in Sources */,
ED6BA5C323C5DF8500BE9EC9 /* TIoTAlertView.m in Sources */,
6D20480E26528199007F6F27 /* TIoTCloudStorageDateModel.m in Sources */,
A43FCE69247E63E900A7CEF3 /* TIoTProductCell.m in Sources */,
D210C7DA2341D7EB00A53B08 /* XWCountryCodeController.m in Sources */,
D210C7D22340A25800A53B08 /* UIImageView+TIoTWebImageView.m in Sources */,
Expand Down Expand Up @@ -3313,9 +3311,11 @@
F4F3D7A924938EBE005D3396 /* TIoTCoreTimerCell.m in Sources */,
F4F3D7C524938EBE005D3396 /* FeedbackVC.m in Sources */,
6D98FE1625C2E6AA00518AC7 /* TIoTCustomCalendarScrollView.m in Sources */,
6D2049EB2653C189007F6F27 /* TIoTCloudStorageDayTimeListModel.m in Sources */,
F4F3D7B924938EBE005D3396 /* TIoTCoreRoomInfoVC.m in Sources */,
6D98FE8125C2EA1A00518AC7 /* TIoTCloudStorageVC.m in Sources */,
F4F3D7CD24938EBE005D3396 /* ChangeWifiVC.m in Sources */,
6D2049EE2653C18D007F6F27 /* TIoTCloudStorageDateModel.m in Sources */,
F4F325E325919A1200A4CAAB /* AppUtils.swift in Sources */,
6D98FE1925C2E6AF00518AC7 /* TIoTCustomCalendarMonth.m in Sources */,
F44D679F25B6D96D001B413C /* TIoTPlayMovieVC.m in Sources */,
Expand Down

0 comments on commit 6e7284a

Please sign in to comment.