JLChen
2021-02-03 4715e99a9be1c50d8ec31f594af9ebde18647c94
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
//  EZRecordCell.m
//  EZOpenSDKDemo
//
//  Created by DeJohn Dong on 15/11/3.
//  Copyright © 2015年 Ezviz. All rights reserved.
//
 
#import "EZRecordCell.h"
#import "EZDeviceRecordFile.h"
#import "EZCloudRecordFile.h"
#import "UIImageView+AFNetworking.h"
#import "DDKit.h"
 
@implementation EZRecordCell {
    
    EZDeviceRecordFile *deviceFile;
    EZCloudRecordFile *cloudFile;
}
 
- (void)setCloudRecord:(EZCloudRecordFile *)cloudFile selected:(BOOL)selected
{
    if (![cloudFile isKindOfClass:[EZCloudRecordFile class]])
    {
        return;
    }
    self.imageView.backgroundColor = [UIColor clearColor];
    //https://cloud.ys7.com:8089/api/cloud?method=download&fid=bf883130-8e13-11e5-8000-a4b5707128a7&session=hik%24shipin7%231%23USK%23at.05idkxni22jmnf4x4f3o380e0oum07ve-7sjmcfm1m8-18q74ue-zhxrqgkur
    NSURL *url = [NSURL URLWithString:cloudFile.coverPic];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"POST";
    NSString *file = [cloudFile.coverPic dd_getSubStringBeginKey:@"fid=" endKey:@"&session"];
    NSString *password = @"";
    //判断是否加密
    if(![cloudFile.encryption isEqualToString:@""])
    {
        //注意该密码是一定要正确的,或者会得不到图片数据
        password = [[GlobalKit shareKit].deviceVerifyCodeBySerial valueForKey:self.deviceSerial];
    }
    NSString *body = [NSString stringWithFormat:@"fid=%@&x=%d&decodekey=%@", file, 200, password];
    request.HTTPBody = [body dataUsingEncoding:NSUTF8StringEncoding];
    [self.imageView setImageWithURLRequest:request
                          placeholderImage:[UIImage imageNamed:@"message_callhelp"]
                                   success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, UIImage * _Nonnull image) {
                                       self.imageView.image = image;
                                   }
                                   failure:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, NSError * _Nonnull error) {
                                       NSLog(@"error = %@",error);
                                   }];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"HH:mm";
    self.timeLabel.text = [formatter stringFromDate:cloudFile.startTime];
    
    UIColor *tintColor = [UIColor grayColor];
    if(selected)
        tintColor = [UIColor dd_hexStringToColor:@"0x1b9ee2"];
    self.imageView.layer.borderColor = tintColor.CGColor;
    self.imageView.layer.borderWidth = 1.0f;
    self.timeLabel.textColor = tintColor;
    
    self->cloudFile = cloudFile;
}
 
- (void)setDeviceRecord:(EZDeviceRecordFile *)deviceFile selected:(BOOL)selected
{
    self.imageView.image = nil;
    self.imageView.backgroundColor = [UIColor grayColor];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"HH:mm";
    self.timeLabel.text = [formatter stringFromDate:deviceFile.startTime];
    self.imageView.image = [UIImage imageNamed:@"message_callhelp"];
    
    UIColor *tintColor = [UIColor grayColor];
    if(selected)
        tintColor = [UIColor dd_hexStringToColor:@"0x1b9ee2"];
    self.imageView.layer.borderColor = tintColor.CGColor;
    self.imageView.layer.borderWidth = 1.0f;
    self.timeLabel.textColor = tintColor;
    
    self->deviceFile = deviceFile;
}
 
- (IBAction)clickDownloadBtn:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(didClickDownlodBtn:)]) {
        [self.delegate didClickDownlodBtn:_isSelectedDevice ? deviceFile : cloudFile];
    }
}
 
@end