JLChen
2021-05-18 a869383e163a18cdedcf587383c1eca043129754
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
//
//  LocalRecordViewController.m
//  lechangeDemo
//
//  Created by mac318340418 on 16/7/11.
//  Copyright © 2016年 dh-Test. All rights reserved.
//
 
#import "LCOpenSDK_Prefix.h"
#import "DownloadPicture.h"
#import "RecordPlayViewController.h"
#import "RecordViewController.h"
#import "RestApiService.h"
#import "LocalPlayViewController.h"
 
#import "PHAsset+Lechange.h"
 
#define RECORD_NUM_MAX 10
 
@interface RecordViewController () {
    LCOpenSDK_Utils* m_util;
    LCOpenSDK_Download* m_download;
    NSString* m_downloadPath;
    int64_t m_totalDataSize[RECORD_NUM_MAX];
    int64_t m_receiveDataSize[RECORD_NUM_MAX];
    BOOL m_isCloudDownload[RECORD_NUM_MAX];
    NSInteger m_index; /**Ch:正在下载的index,用于限制下载数目为1 En:The index being downloaded, used to limit the number of downloads to 1.*/
 
    CGFloat m_cellWidth;
    CGFloat m_cellHeight;
    CGFloat m_separatorHeight;
    NSMutableArray* m_recInfo;
    DownloadPicture* m_downloadPicture[RECORD_NUM_MAX];
    NSString* m_dateSelected;
    NSLock* m_listViewLock;
    UITableView* m_listView;
    BOOL m_isStarting;
 
    NSLock* m_recInfoLock;
    NSLock* m_downStatusLock;
    BOOL m_looping;
    NSInteger m_iPos;
    NSInteger m_downloadingPos;
 
    NSURL* m_httpUrl;
    NSMutableURLRequest* m_req;
    NSURLConnection* m_conn;
 
    NSInteger m_interval;
    NSTimer* m_timer;
    NSMutableSet* m_downloadSet;
 
    UIButton* m_right;
}
 
@end
 
@implementation RecordViewController
 
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self initWindow];
    [self initDatePicker];
 
    UINavigationItem* item;
    if (m_recordType == DeviceRecord) {
        item = [[UINavigationItem alloc] initWithTitle:NSLocalizedString(LOCAL_RECORD_TITLE_TXT, nil)];
    }
    else if (m_recordType == CloudRecord) {
        item = [[UINavigationItem alloc] initWithTitle:NSLocalizedString(NET_RECORD_TITLE_TXT, nil)];
    }
 
    UIButton* left = [UIButton buttonWithType:UIButtonTypeCustom];
    [left setFrame:CGRectMake(0, 0, 50, 30)];
 
    [left setBackgroundImage:[UIImage leChangeImageNamed:Back_Btn_Png] forState:UIControlStateNormal];
    [left addTarget:self action:@selector(onBack) forControlEvents:UIControlEventTouchUpInside];
 
    UIBarButtonItem* leftBtn = [[UIBarButtonItem alloc] initWithCustomView:left];
    [item setLeftBarButtonItem:leftBtn animated:NO];
 
    m_right = [UIButton buttonWithType:UIButtonTypeCustom];
    [m_right setFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 5 - 40, 0, 50, 30)];
 
    [m_right setBackgroundImage:[UIImage leChangeImageNamed:Search_Icon_Png] forState:UIControlStateNormal];
    [m_right addTarget:self action:@selector(onSearch) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* rightBtn = [[UIBarButtonItem alloc] initWithCustomView:m_right];
    [item setRightBarButtonItem:rightBtn animated:NO];
 
    [super.m_navigationBar pushNavigationItem:item animated:NO];
 
    [self.view addSubview:super.m_navigationBar];
    
    [self.m_dateCancelBtn setTitle:NSLocalizedString(DATE_CANCEL_TXT, nil) forState:UIControlStateNormal];
    [self.m_dateSelectBtn setTitle:NSLocalizedString(DATE_QUERY_TXT, nil) forState:UIControlStateNormal];
    [self.m_dateLab setText:NSLocalizedString(DATE_TIP_TXT, nil)];
  
    m_listView = [[UITableView alloc] initWithFrame:CGRectMake(0, super.m_yOffset, self.view.frame.size.width,
                                                        self.view.frame.size.height - super.m_yOffset)];
    m_listView.delegate = (id<UITableViewDelegate>)self;
    m_listView.dataSource = (id<UITableViewDataSource>)self;
    m_listView.backgroundColor = [UIColor clearColor];
    m_listView.separatorColor = [UIColor clearColor];
    m_listView.allowsSelection = YES;
    [self.view addSubview:m_listView];
 
    m_progressInd = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    m_progressInd.transform = CGAffineTransformMakeScale(2.0, 2.0);
    m_progressInd.center = CGPointMake(self.view.center.x, self.view.center.y);
    [self.view addSubview:m_progressInd];
 
    m_toastLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
    m_toastLab.center = self.view.center;
    m_toastLab.backgroundColor = [UIColor whiteColor];
    m_toastLab.textAlignment = NSTextAlignmentCenter;
    m_toastLab.hidden = YES;
    [self.view addSubview:m_toastLab];
 
    m_recInfo = [[NSMutableArray alloc] init];
    m_util = [[LCOpenSDK_Utils alloc] init];
 
    [self.view bringSubviewToFront:self.m_viewDateBar];
    [self.view bringSubviewToFront:m_toastLab];
    [self.view bringSubviewToFront:m_progressInd];
 
    [self.m_ImgRecordNull setImage:[UIImage leChangeImageNamed:Video_None_Png]];
    for (int i = 0; i < RECORD_NUM_MAX; i++) {
        m_downloadPicture[i] = [[DownloadPicture alloc] init];
    }
    m_index = -1;
    m_iPos = 0;
    m_downloadingPos = -1;
 
    m_listViewLock = [[NSLock alloc] init];
    m_downStatusLock = [[NSLock alloc] init];
    m_recInfoLock = [[NSLock alloc] init];
    m_looping = YES;
    m_conn = nil;
    m_downloadSet = [[NSMutableSet alloc] init];
    m_timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(onSmsTimer:) userInfo:nil repeats:YES];
 
    m_download = [LCOpenSDK_Download shareMyInstance];
    [m_download setListener:(id<LCOpenSDK_DownloadListener>)self];
 
    [self getRecords];
 
    dispatch_queue_t downQueue = dispatch_queue_create("cloudThumbnailDown", nil);
    dispatch_async(downQueue, ^{
        [self downloadThread];
    });
}
 
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}
 
- (void)setInfo:(NSString*)token playToken:(NSString *)playToken Dev:(NSString*)deviceId Key:(NSString*)key Chn:(NSInteger)chn Type:(RecordType)type  accessType:(NSString*)accessType;
{
    m_accessToken = [token mutableCopy];
    m_strDevSelected = [deviceId mutableCopy];
    m_encryptKey = [key mutableCopy];
    m_devChnSelected = chn;
    m_recordType = type;
    m_playToken = [playToken copy];
    m_accessType = [accessType copy];
}
 
- (NSString*)timeTransformFormatter:(NSString*)time
{
    NSString* regex = @"[1-9]\\d{3}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}";
    NSPredicate* pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    if (![pred evaluateWithObject:time]) {
        NSLog(@"Time format error:%@", time);
        return nil;
    }
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate* date = [formatter dateFromString:time];
    [formatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
    NSString* retTime = [formatter stringFromDate:date];
    return [retTime substringFromIndex:2];
}
 
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView
{
    return 1;
}
 
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
    self.m_ImgRecordNull.hidden = (0 == m_recInfo.count && m_isStarting) ? NO : YES;
 
    NSInteger iCount = 0;
    [m_recInfoLock lock];
    iCount = m_recInfo.count;
    [m_recInfoLock unlock];
    return iCount;
}
 
- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
    return m_cellHeight;
}
 
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
    static NSString* cellIdentifier = @"Cell";
 
    UITableViewCell* cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    [m_recInfoLock lock];
    if ([indexPath row] >= m_recInfo.count) {
        NSLog(@"RecordViewController cellForRowAtIndexPath not valid,row[%ld],count[%lu]", (long)[indexPath row], (unsigned long)m_recInfo.count);
        [m_recInfoLock unlock];
        return cell;
    }
    NSString* beginTime = ((RecordInfo*)[m_recInfo objectAtIndex:[indexPath row]])->beginTime;
    NSString* endTime = ((RecordInfo*)[m_recInfo objectAtIndex:[indexPath row]])->endTime;
    [m_recInfoLock unlock];
 
    UIImage* imgPic = nil;
 
    if (nil != m_downloadPicture[[indexPath row]].picData) {
        imgPic = [UIImage imageWithData:m_downloadPicture[[indexPath row]].picData];
        NSLog(@"cell[%ld] decrypt imgPic %@", (long)[indexPath row], (imgPic ? @"successfully" : @"failed"));
        if (!imgPic) {
             imgPic = [UIImage leChangeImageNamed:DefaultCover_Png];
        }
    }
    else {
        imgPic = [UIImage leChangeImageNamed:DefaultCover_Png];
        NSLog(@"cell[%ld] default imgPic", (long)[indexPath row]);
    }
    UIImageView* imgPicView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, (m_cellHeight)*16.0 / 9, m_cellHeight)];
    [imgPicView setImage:imgPic];
    [cell addSubview:imgPicView];
 
    UIImageView* mImgBar = [[UIImageView alloc] initWithImage:
                            [UIImage leChangeImageNamed:Toast_Png]];
    mImgBar.frame = CGRectMake(-50, m_cellHeight - m_separatorHeight - 30, m_cellWidth + 100, 30);
    [mImgBar setContentMode:UIViewContentModeScaleAspectFill];
    mImgBar.clipsToBounds = YES;
    [cell addSubview:mImgBar];
    UILabel* dateLab = [[UILabel alloc] initWithFrame:CGRectMake(10, m_cellHeight - m_separatorHeight - 30, m_cellWidth - 10 - 2 * 30, 30)];
    dateLab.text = [NSString stringWithFormat:@"%@—%@", [self timeTransformFormatter:beginTime], [self timeTransformFormatter:endTime]];
    dateLab.backgroundColor = [UIColor clearColor];
    dateLab.textColor = [UIColor whiteColor];
    [dateLab setFont:[UIFont systemFontOfSize:13.0f]];
    [cell addSubview:dateLab];
 
    UIView* additionalSeparator = [[UIView alloc] initWithFrame:CGRectMake(0, m_cellHeight - m_separatorHeight, m_cellWidth, m_separatorHeight)];
    additionalSeparator.backgroundColor = [UIColor whiteColor];
    [cell addSubview:additionalSeparator];
    if (m_totalDataSize[[indexPath row]] != 0) {
        double rate = 1.0 * m_receiveDataSize[[indexPath row]] / m_totalDataSize[[indexPath row]];
        rate = rate > 1.0 ? 1.0 : rate;
        UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(m_cellWidth - 60, m_cellHeight - m_separatorHeight - 30 + 2.5, rate * 2 * (30 - 5), 30 - 5)];
        label.backgroundColor = [UIColor greenColor];
        [cell addSubview:label];
    }
    UIButton* downloadBtn = [[UIButton alloc] initWithFrame:CGRectMake(m_cellWidth - 60, m_cellHeight - m_separatorHeight - 30 + 2.5, 2 * (30 - 5), 30 - 5)];
    if (m_isCloudDownload[[indexPath row]]) {
        [downloadBtn setBackgroundImage:[UIImage leChangeImageNamed:Video_Download_Cancel_Png] forState:UIControlStateNormal];
    }
    else {
        [downloadBtn setBackgroundImage:[UIImage leChangeImageNamed:Video_Download_Png] forState:UIControlStateNormal];
    }
    downloadBtn.tag = [indexPath row];
    [downloadBtn addTarget:self action:@selector(onDownload:) forControlEvents:UIControlEventTouchUpInside];
    [cell addSubview:downloadBtn];
    [cell bringSubviewToFront:downloadBtn];
    return cell;
}
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
    [m_recInfoLock lock];
    if ([indexPath row] >= m_recInfo.count) {
        NSLog(@"tableView indexPath[%ld],m_recInfo[%lu]", (long)[indexPath row], (unsigned long)m_recInfo.count);
        [m_recInfoLock unlock];
        return;
    }
    if (m_recordType == DeviceRecord)
 
    {
        m_strRecSelected = ((RecordInfo*)[m_recInfo objectAtIndex:[indexPath row]])->name;
    }
    else if (m_recordType == CloudRecord) {
        /**
         Ch:处于下载状态,不允许播放云录像
         En:It is in the downloading state, and cloud recording is not allowed.
         */
        if (-1 != m_index) {
            [m_recInfoLock unlock];
            [self showDownloadToast:DOWNLOADING];
            return;
        }
        m_strRecSelected = ((RecordInfo*)[m_recInfo objectAtIndex:[indexPath row]])->recId;
    }
    m_strRecRegSelected = ((RecordInfo*)[m_recInfo objectAtIndex:[indexPath row]])->recRegId;
    m_beginTimeSelected = ((RecordInfo*)[m_recInfo objectAtIndex:[indexPath row]])->beginTime;
    m_endTimeSelected = ((RecordInfo*)[m_recInfo objectAtIndex:[indexPath row]])->endTime;
    m_imgPicSelected = [UIImage imageWithData:m_downloadPicture[[indexPath row]].picData];
 
    [m_recInfoLock unlock];
    UIStoryboard* currentBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    RecordPlayViewController* recordPlayView = [currentBoard instantiateViewControllerWithIdentifier:@"RecordPlay"];
    [recordPlayView setInfo:m_accessToken PlayToken:m_playToken Dev:m_strDevSelected Key:m_encryptKey Chn:m_devChnSelected Type:m_recordType accessType:m_accessType];
    [recordPlayView setRecInfo:m_strRecSelected RecReg:m_strRecRegSelected Begin:m_beginTimeSelected End:m_endTimeSelected Img:m_imgPicSelected];
    [self.navigationController pushViewController:recordPlayView animated:NO];
}
 
- (void)initWindow
{
    m_separatorHeight = 5;
    m_cellWidth = [UIScreen mainScreen].bounds.size.width;
    m_cellHeight = m_cellWidth * 9 / 16 + m_separatorHeight;
    self.m_viewDateBar.hidden = YES;
    m_isStarting = NO;
}
 
- (void)initDatePicker
{
    
    self.m_datePicker.locale = [NSLocale localeWithLocaleIdentifier:NSLocalizedString(LANGUAGE_TXT, nil)];
    self.m_datePicker.datePickerMode = UIDatePickerModeDate;
    [self.m_datePicker addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventValueChanged];
}
 
- (void)valueChange:(UIDatePicker*)datePicker
{
    NSDateFormatter* fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"yyyy-MM-dd";
    NSString* dateStr = [fmt stringFromDate:datePicker.date];
    m_dateSelected = dateStr;
}
 
- (void)cancelBtn:(id)sender
{
    self.m_viewDateBar.hidden = YES;
}
 
- (void)inquireBtn:(id)sender
{
    for (NSString* obj in m_downloadSet) {
        NSInteger index = [obj intValue];
        [m_download stopDownload:index];
        m_isCloudDownload[index] = NO;
        m_receiveDataSize[index] = 0;
        [m_downloadSet removeObject:[NSString stringWithFormat:@"%ld", (long)index]];
        m_index = -1;
    }
    [m_downStatusLock lock];
    for (int i = 0; i < RECORD_NUM_MAX; i++) {
        [m_downloadPicture[i] clearData];
    }
    m_iPos = 0;
    m_downloadingPos = -1;
    m_conn = nil;
    [m_downStatusLock unlock];
 
    self.m_viewDateBar.hidden = YES;
    [m_listViewLock lock];
    m_listView.hidden = YES;
    self.m_ImgRecordNull.hidden = YES;
    [m_listViewLock unlock];
 
    [self getRecords];
}
 
- (void)onSearch
{
    self.m_viewDateBar.hidden = NO;
}
 
- (void)onDownload:(UIButton*)sender
{
    NSLog(@"RecordPlayViewController onDownload");
    /**
     *  管理标志符(En:Management identifier)
     *  m_index == -1, 下载任务未开始(En:Download task did not start)
     *  m_index != -1, 下载任务已开启,不再开启下载任务(En:Download task has been opened, download task is no longer open)
     */
    if (m_index != -1 && m_index != sender.tag) {
        [self showDownloadToast:DOWNLOADING];
        return;
    }
    m_index = sender.tag;
    if (m_index < 0) {
        NSLog(@"RecordPlayViewController onDownload[%ld] Wrong!", (long)m_index);
        m_index = -1;
        return;
    }
    /**
     Ch:取消下载任务
     En:Cancel download task
     */
    if (m_isCloudDownload[m_index]) {
        [m_download stopDownload:m_index];
        m_isCloudDownload[m_index] = NO;
        m_receiveDataSize[m_index] = 0;
        [m_listViewLock lock];
        [self reloadCell:m_listView Section:0 Row:m_index];
        [m_listViewLock unlock];
        [m_downloadSet removeObject:[NSString stringWithFormat:@"%ld", (long)m_index]];
        [self showDownloadToast:NONE];
        m_index = -1;
        return;
    }
 
    /**
    Ch:开始下载任务
    En:Start download task
    */
    m_isCloudDownload[m_index] = YES;
    [m_downloadSet addObject:[NSString stringWithFormat:@"%ld", (long)m_index]];
    NSString *recId = nil;
    NSString *recordRegionId = nil;
    NSString *recName = nil;
    if (m_recordType == CloudRecord) {
        recId = ((RecordInfo*)[m_recInfo objectAtIndex:m_index])->recId;
        recordRegionId = ((RecordInfo*)[m_recInfo objectAtIndex:m_index])->recRegId;
    } else {
        recName = ((RecordInfo*)[m_recInfo objectAtIndex:m_index])->name;
    }
    
    NSString* beginTime = ((RecordInfo*)[m_recInfo objectAtIndex:m_index])->beginTime;
    NSString* time;
 
    NSString* regex = @"[1-9]\\d{3}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}"; //正常字符范围
    NSPredicate* pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex]; //比较处理
 
    if ([pred evaluateWithObject:beginTime]) {
        NSArray* array = [beginTime componentsSeparatedByString:@" "];
        NSArray* arrayDate = [array[0] componentsSeparatedByString:@"-"];
        NSArray* arrayTime = [array[1] componentsSeparatedByString:@":"];
        time = [arrayDate[0] stringByAppendingFormat:@"%@%@%@%@%@", arrayDate[1], arrayDate[2], arrayTime[0], arrayTime[1], arrayTime[2]];
    }
 
    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString* libraryDirectory = [paths objectAtIndex:0];
 
    NSString* myDirectory = [libraryDirectory stringByAppendingPathComponent:@"lechange"];
    NSString* downloadDirectory = [myDirectory stringByAppendingPathComponent:@"download"];
 
    NSString* infoPath = [downloadDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_download_%@", time, (m_recordType == CloudRecord) ? @"cloud_record" : @"device_record"]];
    
    m_downloadPath = [infoPath stringByAppendingString:@".mp4"];
    NSFileManager* fileManage = [NSFileManager defaultManager];
    NSError* pErr;
    BOOL isDir;
    if (NO == [fileManage fileExistsAtPath:myDirectory isDirectory:&isDir]) {
        [fileManage createDirectoryAtPath:myDirectory withIntermediateDirectories:YES attributes:nil error:&pErr];
    }
    if (NO == [fileManage fileExistsAtPath:downloadDirectory isDirectory:&isDir]) {
        [fileManage createDirectoryAtPath:downloadDirectory withIntermediateDirectories:YES attributes:nil error:&pErr];
    }
    NSLog(@"RecordPlayViewController[m_downloadPath] = %@", m_downloadPath);
    [m_listViewLock lock];
    [self reloadCell:m_listView Section:0 Row:m_index];
    [m_listViewLock unlock];
    if (m_recordType == CloudRecord) {
        [m_download startDownload:m_index filepath:m_downloadPath token:m_accessToken devID:m_strDevSelected channelID:m_devChnSelected psk:m_encryptKey recordRegionId:recordRegionId Type:1000 Timeout:10];
    }
    else {
        [m_download startDownload:m_index filepath:m_downloadPath token:m_accessToken devID:m_strDevSelected decryptKey:m_encryptKey fileID:recName speed:16];
    }
}
 
- (void)onDownloadReceiveData:(NSInteger)index datalen:(NSInteger)datalen
{
    dispatch_async(dispatch_get_main_queue(), ^{
        if (index < 0 || index >= RECORD_NUM_MAX) {
            NSLog(@"RecordViewController, index Wrong!");
            return;
        }
        m_receiveDataSize[index] = m_receiveDataSize[index] + datalen;
    });
}
 
- (void)onDownloadState:(NSInteger)index code:(NSString*)code type:(NSInteger)type
{
    NSLog(@"RecordPlayViewController onDownloadState[index, code, type] = [%ld, %@, %ld]", (long)index, code, (long)type);
    if (99 == type) {
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"openapi network interaction timeout");
            m_isCloudDownload[index] = NO;
            [m_listViewLock lock];
            [self reloadCell:m_listView Section:0 Row:index];
            [m_listViewLock unlock];
            [m_downloadSet removeObject:[NSString stringWithFormat:@"%ld", (long)index]];
            [self showDownloadToast:DOWNLOAD_FAILED];
            m_index = -1;
        });
    }
    else if (1 == type) {
        if ([HLS_Result_String(HLS_DOWNLOAD_FAILD) isEqualToString:code]) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"HLS_DOWNLOAD_FAILD");
                m_isCloudDownload[index] = NO;
                m_receiveDataSize[index] = 0;
                [m_listViewLock lock];
                [self reloadCell:m_listView Section:0 Row:index];
                [m_listViewLock unlock];
                [m_downloadSet removeObject:[NSString stringWithFormat:@"%ld", (long)index]];
                [self showDownloadToast:DOWNLOAD_FAILED];
                m_index = -1;
            });
        }
        else if ([HLS_Result_String(HLS_DOWNLOAD_BEGIN) isEqualToString:code]) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"HLS_DOWNLOAD_BEGIN");
            });
        }
        else if ([HLS_Result_String(HLS_DOWNLOAD_END) isEqualToString:code]) {
            dispatch_async(dispatch_get_main_queue(), ^{
                m_isCloudDownload[index] = NO;
                m_receiveDataSize[index] = 0;
                [m_listViewLock lock];
                [self reloadCell:m_listView Section:0 Row:index];
                [m_listViewLock unlock];
                [m_downloadSet removeObject:[NSString stringWithFormat:@"%ld", (long)index]];
                m_index = -1;
            });
            NSURL *dowmloadRUL = [NSURL fileURLWithPath:m_downloadPath];
            [PHAsset deleteFormCameraRoll:dowmloadRUL success:^{
            } failure:^(NSError *error) {
                NSLog(@"Failed to delete:%@", error.description);
            }];
            [PHAsset saveVideoAtURL:dowmloadRUL success:^(void) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    NSLog(@"Saved successfully");
                    [self alertToPlayLocalFile:m_downloadPath];
                });
            } failure:^(NSError *error) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    NSLog(@"Save failed:%@", error.description);
                    [self showDownloadToast:SAVE_FAILED];
                });
            }];
        }
        else if ([HLS_Result_String(HLS_SEEK_SUCCESS) isEqualToString:code]) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"HLS_SEEK_SUCCESS");
            });
        }
        else if ([HLS_Result_String(HLS_SEEK_FAILD) isEqualToString:code]) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"HLS_SEEK_FAILD");
            });
        }
        else if ([HLS_Result_String(HLS_ABORT_DONE) isEqualToString:code]) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"HLS_ABORT_DONE");
                m_isCloudDownload[index] = NO;
                m_receiveDataSize[index] = 0;
                [m_listViewLock lock];
                [self reloadCell:m_listView Section:0 Row:index];
                [m_listViewLock unlock];
                [m_downloadSet removeObject:[NSString stringWithFormat:@"%ld", (long)index]];
                [self showDownloadToast:DOWNLOAD_FAILED];
                m_index = -1;
            });
        }
        else if ([HLS_Result_String(HLS_DOWNLOAD_TIMEOUT) isEqualToString:code]) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"HLS_DOWNLOAS_TIMEOUT");
                m_isCloudDownload[index] = NO;
                m_receiveDataSize[index] = 0;
                [m_listViewLock lock];
                [self reloadCell:m_listView Section:0 Row:index];
                [m_listViewLock unlock];
                [m_downloadSet removeObject:[NSString stringWithFormat:@"%ld", (long)index]];
                [self showDownloadToast:DOWNLOAD_FAILED];
                m_index = -1;
            });
        }
        else if([HLS_Result_String(HLS_KEY_ERROR) isEqualToString:code]) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"HLS_KEY_ERROR");
                m_isCloudDownload[index] = NO;
                m_receiveDataSize[index] = 0;
                [m_listViewLock lock];
                [self reloadCell:m_listView Section:0 Row:index];
                [m_listViewLock unlock];
                [m_downloadSet removeObject:[NSString stringWithFormat:@"%ld", (long)index]];
                [self showDownloadToast:DOWNLOAD_FAILED];
                m_index = -1;
            });
        }
    }
    else if (0 == type)
    {
        if ([code isEqualToString:@"1"]) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"RTSP_DOWNLOAD_FAILD");
                [m_download stopDownload:m_index];
                m_isCloudDownload[index] = NO;
                m_receiveDataSize[index] = 0;
                [m_listViewLock lock];
                [self reloadCell:m_listView Section:0 Row:index];
                [m_listViewLock unlock];
                [m_downloadSet removeObject:[NSString stringWithFormat:@"%ld", (long)index]];
                [self showDownloadToast:DOWNLOAD_FAILED];
                m_index = -1;
            });
        }
        else if ([code isEqualToString:@"4"]) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"RTSP_DOWNLOAD_BEGIN");
            });
        }
        else if ([code isEqualToString:@"5"]) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [m_download stopDownload:m_index];
                m_isCloudDownload[index] = NO;
                m_receiveDataSize[index] = 0;
                [m_listViewLock lock];
               [self reloadCell:m_listView Section:0 Row:index];
               [m_listViewLock unlock];
               [m_downloadSet removeObject:[NSString stringWithFormat:@"%ld", (long)index]];
               m_index = -1;
            });
            
           NSURL *dowmloadRUL = [NSURL fileURLWithPath:m_downloadPath];
           [PHAsset deleteFormCameraRoll:dowmloadRUL success:^{
           } failure:^(NSError *error) {
               NSLog(@"Failed to delete:%@", error.description);
           }];
           [PHAsset saveVideoAtURL:dowmloadRUL success:^(void) {
               dispatch_async(dispatch_get_main_queue(), ^{
                   NSLog(@"Saved successfully");
                    [self alertToPlayLocalFile:m_downloadPath];
               });
           } failure:^(NSError *error) {
               dispatch_async(dispatch_get_main_queue(), ^{
                   NSLog(@"Save failed:%@", error.description);
                   [self showDownloadToast:SAVE_FAILED];
               });
           }];
        }
        else if ([code isEqualToString:@"7"]) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"RTSP_KEY_ERROR");
                [m_download stopDownload:m_index];
                m_isCloudDownload[index] = NO;
                m_receiveDataSize[index] = 0;
                [m_listViewLock lock];
                [self reloadCell:m_listView Section:0 Row:index];
                [m_listViewLock unlock];
                [m_downloadSet removeObject:[NSString stringWithFormat:@"%ld", (long)index]];
                [self showDownloadToast:DOWNLOAD_FAILED];
                m_index = -1;
            });
        }
    }
}
 
- (void)onSmsTimer:(NSInteger)index
{
    for (NSString* obj in m_downloadSet) {
        [m_listViewLock lock];
        [self reloadCell:m_listView Section:0 Row:[obj intValue]];
        [m_listViewLock unlock];
    }
}
 
- (void)onBack
{
    for (NSString* obj in m_downloadSet) {
        [m_download stopDownload:[obj intValue]];
    }
    [m_timer invalidate];
    [self destroyThread];
    [self dismissViewControllerAnimated:YES completion:nil];
    [self.navigationController popViewControllerAnimated:YES];
}
 
- (void)getRecords
{
    m_right.enabled = NO;
    switch (m_recordType) {
    case DeviceRecord:
        [self getLocalRecords];
        break;
    case CloudRecord:
        [self getCloudRecords];
    default:
        break;
    }
}
 
- (void)getLocalRecords
{
    [self showLoading];
    m_toastLab.hidden = YES;
    dispatch_queue_t get_local_records = dispatch_queue_create("get_local_records", nil);
    dispatch_async(get_local_records, ^{
        NSInteger year, month, day;
        NSInteger hour, minute, second;
        NSString* sBeginTime;
        NSString* sEndTime;
        year = month = day = hour = minute = second = 0;
 
        if (m_dateSelected == nil) {
            [self getCurrentDate:&year month:&month day:&day hour:&hour minute:&minute second:&second];
        }
        else {
            NSString* regex = @"[1-9]\\d{3}-\\d{2}-\\d{2}";
            NSPredicate* pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
            if ([pred evaluateWithObject:m_dateSelected]) {
                year = [[m_dateSelected substringWithRange:(NSRange){ 0, 4 }] intValue];
                month = [[m_dateSelected substringWithRange:(NSRange){ 5, 2 }] intValue];
                day = [[m_dateSelected substringWithRange:(NSRange){ 8, 2 }] intValue];
            }
        }
        sBeginTime = [NSString stringWithFormat:@"%04ld-%02ld-%02ld 00:00:00", (long)year, (long)month, (long)day];
        sEndTime = [NSString stringWithFormat:@"%04ld-%02ld-%02ld 23:59:59", (long)year, (long)month, (long)day];
 
        if (YES == m_isStarting) {
            [m_recInfoLock lock];
        }
        [self freeRecInfo];
        //end.
        NSString* errMsg;
        NSInteger iNum;
        RestApiService* restApiService = [RestApiService shareMyInstance];
        [restApiService getRecordNum:m_strDevSelected Chnl:m_devChnSelected Begin:sBeginTime End:sEndTime Num:&iNum Msg:&errMsg];
        if (![errMsg isEqualToString:[MSG_SUCCESS mutableCopy]]) {
            if (YES == m_isStarting) {
                [m_recInfoLock unlock];
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                [self hideLoading];
                m_toastLab.text = errMsg;
                m_toastLab.hidden = NO;
                m_right.enabled = YES;
            });
            return;
        }
        if (iNum > 0) {
            NSInteger beginIndex = iNum > 10 ? (iNum - 9) : 1;
            NSString* errMsg;
            [restApiService getRecords:m_strDevSelected Chnl:m_devChnSelected Begin:sBeginTime End:sEndTime IndexBegin:beginIndex IndexEnd:iNum InfoOut:m_recInfo Msg:&errMsg];
            if (![errMsg isEqualToString:[MSG_SUCCESS mutableCopy]]) {
                if (YES == m_isStarting) {
                    [m_recInfoLock unlock];
                }
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self hideLoading];
                    m_toastLab.text = errMsg;
                    m_toastLab.hidden = NO;
                    m_right.enabled = YES;
                });
                return;
            }
            NSInteger count = m_recInfo.count;
            for (NSInteger i = 0; i <= count / 2 - 1; i++) {
                RecordInfo* t_record = [m_recInfo objectAtIndex:i];
                m_recInfo[i] = m_recInfo[count - 1 - i];
                m_recInfo[count - 1 - i] = t_record;
            }
        }
        for (NSInteger i = 0; i < m_recInfo.count; i++) {
            m_totalDataSize[i] = ((RecordInfo*)[m_recInfo objectAtIndex:i])->size;
            m_receiveDataSize[i] = 0;
            m_isCloudDownload[i] = NO;
        }
        if (YES == m_isStarting) {
            [m_recInfoLock unlock];
        }
 
        m_isStarting = YES;
        dispatch_async(dispatch_get_main_queue(), ^{
            [m_listViewLock lock];
            m_listView.hidden = NO;
            [m_listView reloadData];
            [m_listViewLock unlock];
            [self hideLoading];
            m_right.enabled = YES;
        });
    });
}
 
- (void)getCloudRecords
{
    [self showLoading];
    m_toastLab.hidden = YES;
    dispatch_queue_t get_cloud_records = dispatch_queue_create("get_cloud_records", nil);
    dispatch_async(get_cloud_records, ^{
        NSInteger year, month, day;
        NSInteger hour, minute, second;
        NSString* sBeginTime;
        NSString* sEndTime;
        year = month = day = hour = minute = second = 0;
        // TODO
        if (m_dateSelected == nil) {
            [self getCurrentDate:&year month:&month day:&day hour:&hour minute:&minute second:&second];
        }
        else {
            NSString* regex = @"[1-9]\\d{3}-\\d{2}-\\d{2}";
            NSPredicate* pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
            if ([pred evaluateWithObject:m_dateSelected]) {
                year = [[m_dateSelected substringWithRange:(NSRange){ 0, 4 }] intValue];
                month = [[m_dateSelected substringWithRange:(NSRange){ 5, 2 }] intValue];
                day = [[m_dateSelected substringWithRange:(NSRange){ 8, 2 }] intValue];
            }
        }
        sBeginTime = [NSString stringWithFormat:@"%04ld-%02ld-%02ld 00:00:00", (long)year, (long)month, (long)day];
        sEndTime = [NSString stringWithFormat:@"%04ld-%02ld-%02ld 23:59:59", (long)year, (long)month, (long)day];
 
        if (YES == m_isStarting) {
            [m_recInfoLock lock];
        }
        [self freeRecInfo];
 
        NSString* errMsg;
        NSInteger iNum;
        RestApiService* restApiService = [RestApiService shareMyInstance];
        [restApiService getCloudRecordNum:m_strDevSelected Chnl:m_devChnSelected Bengin:sBeginTime End:sEndTime Num:&iNum Msg:&errMsg];
        if (![errMsg isEqualToString:[MSG_SUCCESS mutableCopy]]) {
            if (YES == m_isStarting) {
                [m_recInfoLock unlock];
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                [self hideLoading];
                m_toastLab.text = errMsg;
                m_toastLab.hidden = NO;
                m_right.enabled = YES;
            });
            return;
        }
        if (iNum > 0) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                m_toastLab.hidden = YES;
            });
            
            NSString* errMsg;
            NSInteger beginIndex = iNum > 10 ? (iNum - 9) : 1;
            [restApiService getCloudRecords:m_strDevSelected Chnl:m_devChnSelected Begin:sBeginTime End:sEndTime IndexBegin:beginIndex IndexEnd:iNum InfoOut:m_recInfo Msg:&errMsg];
            if (![errMsg isEqualToString:[MSG_SUCCESS mutableCopy]]){
                if (YES == m_isStarting) {
                    [m_recInfoLock unlock];
                }
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self hideLoading];
                    m_toastLab.text = errMsg;
                    m_toastLab.hidden = NO;
                    m_right.enabled = YES;
                });
                return;
            }
 
            NSInteger count = m_recInfo.count;
            for (NSInteger i = 0; i <= count / 2 - 1; i++) {
                RecordInfo* t_record = [m_recInfo objectAtIndex:i];
                m_recInfo[i] = m_recInfo[count - 1 - i];
                m_recInfo[count - 1 - i] = t_record;
            }
        }
        for (NSInteger i = 0; i < m_recInfo.count; i++) {
            m_totalDataSize[i] = ((RecordInfo*)[m_recInfo objectAtIndex:i])->size;
            m_receiveDataSize[i] = 0;
            m_isCloudDownload[i] = NO;
        }
        if (YES == m_isStarting) {
            [m_recInfoLock unlock];
        }
        m_isStarting = YES;
        dispatch_async(dispatch_get_main_queue(), ^{
            [self hideLoading];
            [m_listViewLock lock];
            m_listView.hidden = NO;
            [m_listView reloadData];
            [m_listViewLock unlock];
            m_right.enabled = YES;
        });
    });
}
 
- (void)getCurrentDate:(NSInteger*)year month:(NSInteger*)month day:(NSInteger*)day hour:(NSInteger*)hour minute:(NSInteger*)minute second:(NSInteger*)second
{
    NSDate* now = [NSDate date];
    NSCalendar* calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
 
    NSDateComponents* dateComponent = [calendar components:unitFlags fromDate:now];
    *year = [dateComponent year];
    *month = [dateComponent month];
    *day = [dateComponent day];
    *hour = [dateComponent hour];
    *minute = [dateComponent minute];
    *second = [dateComponent second];
}
 
- (void)freeRecInfo
{
    [m_recInfo removeAllObjects];
}
 
- (void)reloadCell:(UITableView*)tableView Section:(NSInteger)section Row:(NSInteger)row
{
    NSIndexPath* indexPath = [NSIndexPath indexPathForRow:row inSection:section];
 
    if ([tableView numberOfRowsInSection:section] > row) {
        
       [UIView performWithoutAnimation:^{
            CGPoint loc = tableView.contentOffset;
            [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
            tableView.contentOffset = loc;
        }];
    }
}
 
- (void)downloadThread
{
    m_iPos = 0;
    m_downloadingPos = -1;
    int j;
    while (m_looping) {
        usleep(20 * 1000);
        BOOL bNeedDown = YES;
        NSString* picUrl;
 
        [m_recInfoLock lock];
        [m_downStatusLock lock];
        do {
            picUrl = nil;
 
            if (m_iPos < 0 || m_iPos >= m_recInfo.count) {
                bNeedDown = NO;
                m_iPos = (m_iPos + 1) % (RECORD_NUM_MAX);
                break;
            }
 
            for (j = 0; j < RECORD_NUM_MAX; j++) {
                if (DOWNLOADING == m_downloadPicture[j].downStatus) {
                    break;
                }
            }
            if (j < RECORD_NUM_MAX) {
                bNeedDown = NO;
                break;
            }
            if (NONE != m_downloadPicture[m_iPos].downStatus) {
                bNeedDown = NO;
                m_iPos = (m_iPos + 1) % (RECORD_NUM_MAX);
                break;
            }
            picUrl = [((RecordInfo*)[m_recInfo objectAtIndex:m_iPos])->thumbUrl mutableCopy];
        } while (0);
 
        [m_recInfoLock unlock];
 
        if (!bNeedDown || !picUrl || 0 == picUrl.length) {
            [m_downStatusLock unlock];
            continue;
        }
        //download
        m_httpUrl = [NSURL URLWithString:picUrl];
        m_downloadPicture[m_iPos].downStatus = DOWNLOADING;
        m_downloadingPos = m_iPos;
        m_iPos = (m_iPos + 1) % (RECORD_NUM_MAX);
 
        NSURLRequest* request = [NSMutableURLRequest requestWithURL:m_httpUrl cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0];
        NSHTTPURLResponse* response = nil;
        NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:NULL];
        if (m_downloadingPos < 0) {
            NSLog(@"connectionDidFinishLoading m_downloadingPos[%ld]", (long)m_downloadingPos);
            return;
        }
        if (response == nil) {
            NSLog(@"download failed");
            m_downloadPicture[m_downloadingPos].downStatus = DOWNLOAD_FAILED;
        }
        else {
            NSLog(@"connectionDidFinishLoading m_downloadingPos[%ld]", (long)m_downloadingPos);
            m_downloadPicture[m_downloadingPos].picData = data;
            NSData* dataOut = [[NSData alloc] init];
            NSInteger iret = [m_util decryptPic:m_downloadPicture[m_downloadingPos].picData deviceID:m_strDevSelected key:m_encryptKey token:m_accessToken bufOut:&dataOut];
 
            NSLog(@"decrypt iret[%ld]", (long)iret);
            if (0 == iret) {
                [m_downloadPicture[m_downloadingPos] setData:[NSData dataWithBytes:[dataOut bytes] length:[dataOut length]] status:DOWNLOAD_FINISHED];
                dispatch_async(dispatch_get_main_queue(), ^{
                    [m_listViewLock lock];
                    [m_listView reloadData];
                    [m_listViewLock unlock];
                });
            }
            else {
                [m_downloadPicture[m_downloadingPos] setData:nil status:DOWNLOAD_FAILED];
            }
        }
        [m_downStatusLock unlock];
    }
}
- (void)destroyThread
{
    m_looping = NO;
}
 
- (void)showDownloadToast:(DownStatus)status
{
    switch (status) {
        case DOWNLOAD_SUCCESS:
            m_toastLab.text = NSLocalizedString(DOWNLOAD_SUCCESS_TXT, nil);
            m_toastLab.hidden = NO;
            [self performSelector:@selector(downloadToastDelay) withObject:nil afterDelay:2.0f];
            break;
        case DOWNLOAD_FAILED:
            m_toastLab.text = NSLocalizedString(DOWNLOAD_FAILED_TXT, nil);
            m_toastLab.hidden = NO;
            [self performSelector:@selector(downloadToastDelay) withObject:nil afterDelay:2.0f];
            break;
        case DOWNLOADING:
            m_toastLab.text = NSLocalizedString(DOWNLOADING_TXT, nil);
            m_toastLab.hidden = NO;
            [self performSelector:@selector(downloadToastDelay) withObject:nil afterDelay:2.0f];
            break;
        case NONE:
            m_toastLab.text = NSLocalizedString(CANCEL_DOWNLOAD_TXT, nil);
            m_toastLab.hidden = NO;
            [self performSelector:@selector(downloadToastDelay) withObject:nil afterDelay:2.0f];
            break;
        case SAVE_FAILED:
            m_toastLab.text = NSLocalizedString(RECORD_SAVE_FAILED, nil);
            m_toastLab.hidden = NO;
            [self performSelector:@selector(downloadToastDelay) withObject:nil afterDelay:2.0f];
            break;
        default:
            break;
    }
}
 
- (void)alertToPlayLocalFile:(NSString *)filePath {
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(PLAY_LOCAL_FILE, nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction* confirmAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction* _Nonnull action){
        LocalPlayViewController *localPlayViewController = [LocalPlayViewController new];
        localPlayViewController.filepath = filePath;
        [self.navigationController pushViewController:localPlayViewController animated:NO];
    }];
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleDefault handler:nil];
    [alert addAction:confirmAction];
    [alert addAction:cancelAction];
    [self presentViewController:alert animated:YES completion:nil];
}
 
- (void)downloadToastDelay
{
    m_toastLab.hidden = YES;
}
 
 
- (void)showLoading
{
    [m_progressInd startAnimating];
}
 
- (void)hideLoading
{
    if ([m_progressInd isAnimating]) {
        [m_progressInd stopAnimating];
    }
}
 
- (void)dealloc
{
    NSLog(@"RecordViewController, dealloc");
}
@end