-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathDetailViewController.m
More file actions
6229 lines (5744 loc) · 294 KB
/
DetailViewController.m
File metadata and controls
6229 lines (5744 loc) · 294 KB
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
//
// DetailViewController.m
// XBMC Remote
//
// Created by Giovanni Messina on 23/3/12.
// Copyright (c) 2012 joethefox inc. All rights reserved.
//
#import "DetailViewController.h"
#import "mainMenu.h"
#import "DSJSONRPC.h"
#import "GlobalData.h"
#import "ShowInfoViewController.h"
#import "DetailViewController.h"
#import "NowPlaying.h"
#import "SDImageCache.h"
#import "AppDelegate.h"
#import "ViewControllerIPad.h"
#import "StackScrollViewController.h"
#import "PosterCell.h"
#import "PosterLabel.h"
#import "PosterHeaderView.h"
#import "RecentlyAddedCell.h"
#import "NSString+MD5.h"
#import "UIScrollView+SVPullToRefresh.h"
#import "BroadcastProgressView.h"
#import "SettingsValuesViewController.h"
#import "customButton.h"
#import "VersionCheck.h"
#import "SharingActivityItemSource.h"
#import "RemoteController.h"
#import "UIBarButtonItem+Extensions.h"
#import "UIViewController+Extensions.h"
#import "UILabel+Extensions.h"
#import "GeneratedAssetSymbols.h"
@import QuartzCore;
@interface DetailViewController ()
- (void)configureView;
@end
@implementation DetailViewController
@synthesize detailItem = _detailItem;
@synthesize sections;
@synthesize filteredListContent;
@synthesize richResults;
@synthesize sectionArray;
@synthesize sectionArrayOpen;
#define SECTIONS_START_AT 100
#define MAX_NORMAL_BUTTONS 4
#define WARNING_TIMEOUT 30.0
#define GRID_SECTION_HEADER_HEIGHT 24
#define LIST_SECTION_HEADER_HEIGHT 24
#define FIXED_SPACE_WIDTH 120
#define INFO_PADDING 10
#define MONKEY_COUNT 38
#define MONKEY_OFFSET_X 3
#define IPHONE_SEASON_SECTION_HEIGHT 99
#define IPHONE_ALBUM_SECTION_HEIGHT 116
#define IPAD_SEASON_SECTION_HEIGHT 120
#define IPAD_ALBUM_SECTION_HEIGHT 166
#define INDEX_WIDTH 34
#define GENRE_HEIGHT 18
#define EPGCHANNELTIME_WIDTH 40
#define EPGCHANNELTIME_HEIGHT 12
#define EPGCHANNELBAR_HEIGHT 30
#define RECORDING_DOT_SIZE 12
#define TRACKCOUNT_WIDTH 26
#define LABEL_PADDING 8
#define VERTICAL_PADDING 8
#define SMALL_PADDING 4
#define TINY_PADDING 2
#define FLAG_SIZE 16
#define INDICATOR_SIZE 16
#define FLOWLAYOUT_FULLSCREEN_INSET 8
#define FLOWLAYOUT_FULLSCREEN_MIN_SPACE 4
#define FLOWLAYOUT_FULLSCREEN_LABEL (FULLSCREEN_LABEL_HEIGHT + 8)
#define TOGGLE_BUTTON_SIZE 11
#define INFO_BUTTON_SIZE 30
#define FULLSCREEN_BUTTON_SIZE 26
#define LABEL_HEIGHT(font) ceil(font.lineHeight)
#define XIB_JSON_DATA_CELL_TITLE 1
#define XIB_JSON_DATA_CELL_GENRE 2
#define XIB_JSON_DATA_CELL_RUNTIMEYEAR 3
#define XIB_JSON_DATA_CELL_RUNTIME 4
#define XIB_JSON_DATA_CELL_RATING 5
#define XIB_JSON_DATA_CELL_WATCHED_FLAG 9
#define XIB_JSON_DATA_CELL_ACTIVTYINDICATOR SHARED_CELL_ACTIVTYINDICATOR
#define ALBUM_VIEW_CELL_TRACKNUMBER 101
#define SEASON_VIEW_CELL_TOGGLE 99
#define DETAIL_VIEW_INFO_ALBUM 104
#define DETAIL_VIEW_INFO_TVSHOW 105
#define EPG_VIEW_CELL_STARTTIME 102
#define EPG_VIEW_CELL_PROGRESSVIEW 103
#define EPG_VIEW_CELL_RECORDING_ICON SHARED_CELL_RECORDING_ICON
- (id)initWithFrame:(CGRect)frame {
if (self = [super init]) {
self.view.frame = frame;
}
return self;
}
- (id)initWithNibName:(NSString*)nibNameOrNil withItem:(mainMenu*)item withFrame:(CGRect)frame bundle:(NSBundle*)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
self.detailItem = item;
self.view.frame = frame;
}
return self;
}
#pragma mark - Live TV epg memory/disk cache management
- (NSMutableArray*)loadEPGFromMemory:(NSNumber*)channelid {
__block NSMutableArray *epgarray = nil;
dispatch_sync(epglockqueue, ^{
epgarray = epgDict[channelid];
});
return epgarray;
}
- (NSMutableArray*)loadEPGFromDisk:(NSNumber*)channelid parameters:(NSDictionary*)params {
NSString *epgKey = [self getCacheKey:@"EPG" parameters:nil];
NSString *filename = [NSString stringWithFormat:@"%@-%@.epg.dat", epgKey, channelid];
NSMutableArray *epgArray = [Utilities unarchivePath:epgCachePath file:filename];
dispatch_sync(epglockqueue, ^{
if (epgArray != nil && channelid != nil) {
epgDict[channelid] = epgArray;
}
});
return epgArray;
}
- (void)backgroundSaveEPGToDisk:(NSDictionary*)parameters {
NSNumber *channelid = parameters[@"channelid"];
NSMutableArray *epgData = parameters[@"epgArray"];
[self saveEPGToDisk:channelid epgData:epgData];
}
- (void)saveEPGToDisk:(NSNumber*)channelid epgData:(NSMutableArray*)epgArray {
if (epgArray != nil && channelid != nil && epgArray.count > 0) {
NSString *epgKey = [self getCacheKey:@"EPG" parameters:nil];
NSString *filename = [NSString stringWithFormat:@"%@-%@.epg.dat", epgKey, channelid];
[Utilities archivePath:epgCachePath file:filename data:epgArray];
dispatch_sync(epglockqueue, ^{
epgDict[channelid] = epgArray;
[epgDownloadQueue removeObject:channelid];
});
}
}
#pragma mark - Live TV epg management
- (void)getChannelEpgInfo:(NSDictionary*)parameters {
NSNumber *channelid = [Utilities getNumberFromItem:parameters[@"channelid"]];
NSIndexPath *indexPath = parameters[@"indexPath"];
NSMutableDictionary *item = parameters[@"item"];
if ([channelid longValue] > 0) {
NSMutableArray *retrievedEPG = [self loadEPGFromMemory:channelid];
NSMutableDictionary *channelEPG = [self parseEpgData:retrievedEPG];
NSDictionary *epgparams = [NSDictionary dictionaryWithObjectsAndKeys:
channelEPG, @"channelEPG",
indexPath, @"indexPath",
item, @"item",
nil];
[self performSelectorOnMainThread:@selector(updateEpgTableInfo:) withObject:epgparams waitUntilDone:NO];
if ([channelEPG[@"refresh_data"] boolValue]) {
retrievedEPG = [self loadEPGFromDisk:channelid parameters:parameters];
channelEPG = [self parseEpgData:retrievedEPG];
NSDictionary *epgparams = [NSDictionary dictionaryWithObjectsAndKeys:
channelEPG, @"channelEPG",
indexPath, @"indexPath",
item, @"item",
nil];
[self performSelectorOnMainThread:@selector(updateEpgTableInfo:) withObject:epgparams waitUntilDone:NO];
dispatch_sync(epglockqueue, ^{
if ([channelEPG[@"refresh_data"] boolValue] && ![epgDownloadQueue containsObject:channelid]) {
[epgDownloadQueue addObject:channelid];
[self performSelectorOnMainThread:@selector(getJsonEPG:) withObject:parameters waitUntilDone:NO];
}
});
}
}
}
- (NSMutableDictionary*)parseEpgData:(NSMutableArray*)epgData {
NSMutableDictionary *channelEPG = [NSMutableDictionary new];
channelEPG[@"current"] = LOCALIZED_STR(@"Not Available");
channelEPG[@"next"] = LOCALIZED_STR(@"Not Available");
channelEPG[@"current_details"] = @"";
channelEPG[@"refresh_data"] = @YES;
channelEPG[@"starttime"] = @"";
channelEPG[@"endtime"] = @"";
if (epgData != nil) {
NSDictionary *objectToSearch;
NSDate *nowDate = [NSDate date];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"starttime <= %@ AND endtime >= %@", nowDate, nowDate];
NSArray *filteredArray = [epgData filteredArrayUsingPredicate:predicate];
if (filteredArray.count > 0) {
objectToSearch = filteredArray[0];
channelEPG[@"starttime"] = objectToSearch[@"starttime"];
channelEPG[@"endtime"] = objectToSearch[@"endtime"];
channelEPG[@"current"] = [NSString stringWithFormat:@"%@ %@",
[localHourMinuteFormatter stringFromDate:objectToSearch[@"starttime"]],
objectToSearch[@"title"]
];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSUInteger unitFlags = NSCalendarUnitMinute;
NSDateComponents *components = [gregorian components:unitFlags
fromDate:objectToSearch[@"starttime"]
toDate:objectToSearch[@"endtime"] options:0];
NSInteger minutes = [components minute];
NSString *plotoutline = objectToSearch[@"plotoutline"];
if (!plotoutline || [plotoutline isKindOfClass:[NSNull class]] || [objectToSearch[@"plot"] isEqualToString:plotoutline]) {
plotoutline = @"";
}
channelEPG[@"current_details"] = [NSString stringWithFormat:@"\n%@\n%@\n%@\n\n%@ - %@ (%ld %@)",
objectToSearch[@"title"],
plotoutline.length > 0 ? [NSString stringWithFormat:@"%@\n", plotoutline] : @"",
objectToSearch[@"plot"],
[localHourMinuteFormatter stringFromDate:objectToSearch[@"starttime"]],
[localHourMinuteFormatter stringFromDate:objectToSearch[@"endtime"]],
(long)minutes,
(long)minutes > 1 ? LOCALIZED_STR(@"Mins.") : LOCALIZED_STR(@"Min")
];
predicate = [NSPredicate predicateWithFormat:@"starttime >= %@", objectToSearch[@"endtime"]];
NSArray *nextFilteredArray = [epgData filteredArrayUsingPredicate:predicate];
if (nextFilteredArray.count > 0) {
channelEPG[@"next"] = [NSString stringWithFormat:@"%@ %@",
[localHourMinuteFormatter stringFromDate:nextFilteredArray[0][@"starttime"]],
nextFilteredArray[0][@"title"]
];
channelEPG[@"refresh_data"] = @NO;
}
}
}
return channelEPG;
}
- (void)updateEpgTableInfo:(NSDictionary*)parameters {
NSMutableDictionary *channelEPG = parameters[@"channelEPG"];
NSIndexPath *indexPath = parameters[@"indexPath"];
NSMutableDictionary *item = parameters[@"item"];
UITableViewCell *cell = [dataList cellForRowAtIndexPath:indexPath];
UILabel *current = (UILabel*)[cell viewWithTag:XIB_JSON_DATA_CELL_GENRE];
UILabel *next = (UILabel*)[cell viewWithTag:XIB_JSON_DATA_CELL_RUNTIME];
current.text = channelEPG[@"current"];
next.text = channelEPG[@"next"];
if (channelEPG[@"current_details"] != nil) {
item[@"genre"] = channelEPG[@"current_details"];
}
BroadcastProgressView *progressView = (BroadcastProgressView*)[cell viewWithTag:EPG_VIEW_CELL_PROGRESSVIEW];
if (![current.text isEqualToString:LOCALIZED_STR(@"Not Available")] && [channelEPG[@"starttime"] isKindOfClass:[NSDate class]] && [channelEPG[@"endtime"] isKindOfClass:[NSDate class]]) {
float percent_elapsed = [Utilities getPercentElapsed:channelEPG[@"starttime"] EndDate:channelEPG[@"endtime"]];
[progressView setProgress:percent_elapsed / 100.0];
progressView.hidden = NO;
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSUInteger unitFlags = NSCalendarUnitMinute;
NSDateComponents *components = [gregorian components:unitFlags
fromDate:channelEPG[@"starttime"]
toDate:channelEPG[@"endtime"] options:0];
NSInteger minutes = [components minute];
progressView.barLabel.text = [NSString stringWithFormat:@"%ld'", (long)minutes];
}
else {
progressView.hidden = YES;
}
}
- (void)parseBroadcasts:(NSDictionary*)parameters {
NSArray *broadcasts = parameters[@"broadcasts"];
NSNumber *channelid = parameters[@"channelid"];
NSIndexPath *indexPath = parameters[@"indexPath"];
NSMutableDictionary *item = parameters[@"item"];
NSMutableArray *retrievedEPG = [NSMutableArray new];
for (id EPGobject in broadcasts) {
if ([EPGobject isKindOfClass:[NSDictionary class]]) {
NSDate *starttime = [xbmcDateFormatter dateFromString:EPGobject[@"starttime"]];
NSDate *endtime = [xbmcDateFormatter dateFromString:EPGobject[@"endtime"]];
[retrievedEPG addObject:[NSDictionary dictionaryWithObjectsAndKeys:
starttime, @"starttime",
endtime, @"endtime",
EPGobject[@"title"], @"title",
EPGobject[@"label"], @"label",
EPGobject[@"plot"], @"plot",
EPGobject[@"plotoutline"], @"plotoutline",
nil]];
}
}
[self saveEPGToDisk:channelid epgData:retrievedEPG];
NSDictionary *epgparams = [NSDictionary dictionaryWithObjectsAndKeys:
[self parseEpgData:retrievedEPG], @"channelEPG",
indexPath, @"indexPath",
item, @"item",
nil];
[self performSelectorOnMainThread:@selector(updateEpgTableInfo:) withObject:epgparams waitUntilDone:NO];
}
- (void)getJsonEPG:(NSDictionary*)parameters {
NSNumber *channelid = parameters[@"channelid"];
NSIndexPath *indexPath = parameters[@"indexPath"];
NSMutableDictionary *item = parameters[@"item"];
[[Utilities getJsonRPC] callMethod:@"PVR.GetBroadcasts"
withParameters:[NSDictionary dictionaryWithObjectsAndKeys:
channelid, @"channelid",
@[@"title", @"starttime", @"endtime", @"plot", @"plotoutline"], @"properties",
nil]
onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *error) {
if (error == nil && methodError == nil && [methodResult isKindOfClass:[NSDictionary class]]) {
NSArray *broadcasts = methodResult[@"broadcasts"];
if (broadcasts && [broadcasts isKindOfClass:[NSArray class]]) {
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
channelid, @"channelid",
indexPath, @"indexPath",
item, @"item",
broadcasts, @"broadcasts",
nil];
[NSThread detachNewThreadSelector:@selector(parseBroadcasts:) toTarget:self withObject:params];
}
}
}];
}
#pragma mark - Library disk cache management
- (NSString*)getCacheKey:(NSString*)fieldA parameters:(NSMutableDictionary*)fieldB {
// Which server are we connected to?
GlobalData *obj = [GlobalData getInstance];
NSString *serverInfo = [NSString stringWithFormat:@"%@ %@ %@", obj.serverIP, obj.serverPort, obj.serverDescription];
// Which version does the serer have?
NSString *serverVersion = [NSString stringWithFormat:@"%d.%d", serverMajorVersion, serverMinorVersion];
// Which App version are we running?
NSString *appVersion = [Utilities getAppVersionString];
// Which JSON request's results do we cache??
NSString *jsonRequest = [NSString stringWithFormat:@"%@ %@", fieldA, fieldB];
// Get SHA256 hash for the combination given above
NSString *text = [NSString stringWithFormat:@"%@%@%@%@", serverInfo, serverVersion, appVersion, jsonRequest];
return [text SHA256String];
}
- (void)saveData:(NSMutableDictionary*)mutableParameters {
if (!enableDiskCache) {
return;
}
if (mutableParameters != nil) {
mainMenu *menuItem = self.detailItem;
NSDictionary *methods = menuItem.mainMethod[chosenTab];
NSString *viewKey = [self getCacheKey:methods[@"method"] parameters:mutableParameters];
NSString *filename = [NSString stringWithFormat:@"%@.richResults.dat", viewKey];
[Utilities archivePath:libraryCachePath file:filename data:self.richResults];
NSString *path = [libraryCachePath stringByAppendingPathComponent:filename];
[self updateSyncDate:path];
filename = [NSString stringWithFormat:@"%@.extraSectionRichResults.dat", viewKey];
[Utilities archivePath:libraryCachePath file:filename data:self.extraSectionRichResults];
}
}
- (void)loadDataFromDisk:(NSDictionary*)params {
self.richResults = nil;
self.sectionArray = nil;
self.sectionArrayOpen = nil;
self.extraSectionRichResults = nil;
self.sections = [NSMutableDictionary new];
NSString *viewKey = [self getCacheKey:params[@"methodToCall"] parameters:params[@"mutableParameters"]];
NSString *filename = [NSString stringWithFormat:@"%@.richResults.dat", viewKey];
NSMutableArray *tempArray = [Utilities unarchivePath:libraryCachePath file:filename];
self.richResults = tempArray;
filename = [NSString stringWithFormat:@"%@.extraSectionRichResults.dat", viewKey];
tempArray = [Utilities unarchivePath:libraryCachePath file:filename];
self.extraSectionRichResults = tempArray;
storeRichResults = [self.richResults mutableCopy];
[self performSelectorOnMainThread:@selector(indexAndDisplayData) withObject:nil waitUntilDone:YES];
}
- (BOOL)loadedDataFromDisk:(NSString*)methodToCall parameters:(NSMutableDictionary*)mutableParameters refresh:(BOOL)forceRefresh {
if (forceRefresh) {
return NO;
}
if (!enableDiskCache) {
return NO;
}
NSString *viewKey = [self getCacheKey:methodToCall parameters:mutableParameters];
NSString *filename = [NSString stringWithFormat:@"%@.richResults.dat", viewKey];
NSString *path = [libraryCachePath stringByAppendingPathComponent:filename];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:path]) {
NSDictionary *extraParams = [NSDictionary dictionaryWithObjectsAndKeys:
mutableParameters, @"mutableParameters",
methodToCall, @"methodToCall",
nil];
[self updateSyncDate:path];
[NSThread detachNewThreadSelector:@selector(loadDataFromDisk:) toTarget:self withObject:extraParams];
return YES;
}
return NO;
}
- (void)updateSyncDate:(NSString*)filePath {
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:filePath]) {
NSError *attributesRetrievalError = nil;
NSDictionary *attributes = [fileManager attributesOfItemAtPath:filePath error:&attributesRetrievalError];
if (attributes) {
NSDateFormatter *dateFormatter = [NSDateFormatter new];
dateFormatter.dateStyle = NSDateFormatterLongStyle;
dateFormatter.timeStyle = NSDateFormatterShortStyle;
dateFormatter.locale = [NSLocale currentLocale];
NSString *dateString = [dateFormatter stringFromDate:[attributes fileModificationDate]];
NSString *title = [NSString stringWithFormat:@"%@: %@", LOCALIZED_STR(@"Last sync"), dateString];
[dataList.pullToRefreshView setSubtitle:title forState:SVPullToRefreshStateStopped];
[dataList.pullToRefreshView setSubtitle:title forState:SVPullToRefreshStateTriggered];
[collectionView.pullToRefreshView setSubtitle:title forState:SVPullToRefreshStateStopped];
[collectionView.pullToRefreshView setSubtitle:title forState:SVPullToRefreshStateTriggered];
}
}
}
#pragma mark - Utility
- (BOOL)isTimerActiveForItem:(id)item {
return [item[@"hastimer"] boolValue] || [item[@"isrecording"] boolValue];
}
- (void)enterSubmenuForItem:(id)item params:(NSDictionary*)parameters {
mainMenu *menuItem = [self getMainMenu:item];
int activeTab = [self getActiveTab:item];
menuItem.subItem.mainLabel = item[@"label"];
mainMenu *newMenuItem = [menuItem.subItem copy];
newMenuItem.mainParameters[activeTab] = parameters;
newMenuItem.chooseTab = activeTab;
if (IS_IPHONE) {
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
detailViewController.detailItem = newMenuItem;
[self.navigationController pushViewController:detailViewController animated:YES];
}
else {
if (stackscrollFullscreen) {
[self toggleFullscreen];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.6f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
DetailViewController *iPadDetailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" withItem:newMenuItem withFrame:CGRectMake(0, 0, STACKSCROLL_WIDTH, self.view.frame.size.height) bundle:nil];
[AppDelegate.instance.windowController.stackScrollViewController addViewInSlider:iPadDetailViewController invokeByController:self isStackStartView:NO];
});
}
else {
DetailViewController *iPadDetailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" withItem:newMenuItem withFrame:CGRectMake(0, 0, STACKSCROLL_WIDTH, self.view.frame.size.height) bundle:nil];
[AppDelegate.instance.windowController.stackScrollViewController addViewInSlider:iPadDetailViewController invokeByController:self isStackStartView:NO];
}
}
}
- (void)addFileProperties:(NSMutableDictionary*)dict {
if (dict[@"file_properties"] != nil) {
dict[@"properties"] = [dict[@"file_properties"] mutableCopy];
[dict removeObjectForKey:@"file_properties"];
// Kodi 11 does not support art for file properties
if (AppDelegate.instance.serverVersion <= 11) {
[dict[@"properties"] removeObject:@"art"];
}
}
}
- (void)addExtraProperties:(NSMutableArray*)mutableProperties newParams:(NSMutableDictionary*)mutableParameters params:(NSDictionary*)parameters {
if ([parameters[@"FrodoExtraArt"] boolValue] && AppDelegate.instance.serverVersion > 11) {
[mutableProperties addObject:@"art"];
}
if (parameters[@"kodiExtrasPropertiesMinimumVersion"] != nil) {
for (id key in parameters[@"kodiExtrasPropertiesMinimumVersion"]) {
if (AppDelegate.instance.serverVersion >= [key integerValue]) {
id arrayProperties = parameters[@"kodiExtrasPropertiesMinimumVersion"][key];
for (id value in arrayProperties) {
[mutableProperties addObject:value];
}
}
}
}
if (mutableProperties != nil) {
mutableParameters[@"properties"] = mutableProperties;
}
}
- (void)setFilternameLabel:(NSString*)labelText {
labelText = [Utilities stripBBandHTML:labelText];
self.navigationItem.title = labelText;
if (IS_IPHONE || stackscrollFullscreen) {
return;
}
[UIView animateWithDuration:0.1
animations:^{
// fade out
topNavigationLabel.alpha = 0;
}
completion:^(BOOL finished) {
// update label
topNavigationLabel.text = labelText;
// fade in
[UIView animateWithDuration:0.1
animations:^{
topNavigationLabel.alpha = 1;
}
completion:nil];
}];
}
- (NSDictionary*)getNewDictionaryFromExtraInfoItem:(NSDictionary*)item mainFields:(NSDictionary*)mainFields serverURL:(NSString*)serverURL sec2min:(int)sec2min useBanner:(BOOL)useBanner useIcon:(BOOL)useIcon {
NSString *label = [NSString stringWithFormat:@"%@", item[mainFields[@"row1"]]];
NSString *genre = [Utilities getStringFromItem:item[mainFields[@"row2"]]];
NSString *year = [Utilities getYearFromItem:item[mainFields[@"row3"]]];
NSString *runtime = [Utilities getTimeFromItem:item[mainFields[@"row4"]] sec2min:sec2min];
NSString *rating = [Utilities getRatingFromItem:item[mainFields[@"row5"]]];
NSString *thumbnailPath = [Utilities getThumbnailFromDictionary:item useBanner:useBanner useIcon:useIcon];
NSDictionary *art = item[@"art"];
NSString *clearlogo = [Utilities getClearArtFromDictionary:art type:@"clearlogo"];
NSString *clearart = [Utilities getClearArtFromDictionary:art type:@"clearart"];
NSString *stringURL = [Utilities formatStringURL:thumbnailPath serverURL:serverURL];
NSString *fanartURL = [Utilities formatStringURL:item[@"fanart"] serverURL:serverURL];
if (!stringURL.length) {
stringURL = [Utilities getItemIconFromDictionary:item];
}
id row11 = item[mainFields[@"row11"]] ?: @0;
NSString *row11key = mainFields[@"row11"] ?: @"";
id row7 = item[mainFields[@"row7"]] ?: @0;
NSString *row7key = mainFields[@"row7"] ?: @"";
NSDictionary *newItem = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@(albumView), @"fromAlbumView",
@(episodesView), @"fromEpisodesView",
clearlogo, @"clearlogo",
clearart, @"clearart",
label, @"label",
genre, @"genre",
stringURL, @"thumbnail",
fanartURL, @"fanart",
runtime, @"runtime",
row7, row7key,
item[mainFields[@"row6"]], mainFields[@"row6"],
item[mainFields[@"row8"]], mainFields[@"row8"],
year, @"year",
rating, @"rating",
mainFields[@"playlistid"], @"playlistid",
mainFields[@"row8"], @"family",
[Utilities getNumberFromItem:item[mainFields[@"row9"]]], mainFields[@"row9"],
item[mainFields[@"row10"]], mainFields[@"row10"],
row11, row11key,
item[mainFields[@"row12"]], mainFields[@"row12"],
item[mainFields[@"row13"]], mainFields[@"row13"],
item[mainFields[@"row14"]], mainFields[@"row14"],
item[mainFields[@"row15"]], mainFields[@"row15"],
item[mainFields[@"row16"]], mainFields[@"row16"],
item[mainFields[@"row17"]], mainFields[@"row17"],
item[mainFields[@"row18"]], mainFields[@"row18"],
item[mainFields[@"row19"]], mainFields[@"row19"],
item[mainFields[@"row20"]], mainFields[@"row20"],
nil];
return newItem;
}
- (NSMutableDictionary*)getNewDictionaryFromItem:(NSDictionary*)item mainFields:(NSDictionary*)mainFields serverURL:(NSString*)serverURL sec2min:(int)sec2min useBanner:(BOOL)useBanner useIcon:(BOOL)useIcon {
NSString *label = [NSString stringWithFormat:@"%@", item[mainFields[@"row1"]]];
NSString *genre = [Utilities getStringFromItem:item[mainFields[@"row2"]]];
NSString *year = [Utilities getYearFromItem:item[mainFields[@"row3"]]];
NSString *runtime = [Utilities getTimeFromItem:item[mainFields[@"row4"]] sec2min:sec2min];
NSString *rating = [Utilities getRatingFromItem:item[mainFields[@"row5"]]];
NSString *thumbnailPath = [Utilities getThumbnailFromDictionary:item useBanner:NO useIcon:recordingListView];
NSString *bannerPath = [Utilities getThumbnailFromDictionary:item useBanner:YES useIcon:recordingListView];
NSString *stringURL = [Utilities formatStringURL:thumbnailPath serverURL:serverURL];
NSString *bannerURL = [Utilities formatStringURL:bannerPath serverURL:serverURL];
NSString *fanartURL = [Utilities formatStringURL:item[@"fanart"] serverURL:serverURL];
if (!stringURL.length) {
stringURL = [Utilities getItemIconFromDictionary:item];
}
NSString *row7key = mainFields[@"row7"] ?: @"none";
NSString *row7obj = mainFields[@"row7"] ? [NSString stringWithFormat:@"%@", item[mainFields[@"row7"]]] : @"";
NSString *seasonNumber = [NSString stringWithFormat:@"%@", item[mainFields[@"row10"]]];
NSString *family = [NSString stringWithFormat:@"%@", mainFields[@"row8"]];
NSString *row19key = mainFields[@"row19"] ?: @"episode";
id row19obj = @"";
if ([item[mainFields[@"row19"]] isKindOfClass:[NSDictionary class]]) {
row19obj = [item[mainFields[@"row19"]] mutableCopy];
}
else if ([row19key isEqualToString:@"tag"]) {
row19obj = [Utilities getStringFromItem:item[@"label"]];
}
else {
row19obj = [NSString stringWithFormat:@"%@", item[mainFields[@"row19"]]];
}
id row13key = mainFields[@"row13"];
id row13obj = [row13key isEqualToString:@"options"] ? (item[row13key] ?: @"") : item[row13key];
id row14key = mainFields[@"row14"];
id row14obj = [row14key isEqualToString:@"allowempty"] ? (item[row14key] ?: @"") : item[row14key];
id row15key = mainFields[@"row15"];
id row15obj = [row15key isEqualToString:@"addontype"] ? (item[row15key] ?: @"") : item[row15key];
NSMutableDictionary *newDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
label, @"label",
genre, @"genre",
stringURL, @"thumbnail",
fanartURL, @"fanart",
bannerURL, @"banner",
runtime, @"runtime",
seasonNumber, @"season",
row19obj, row19key,
family, @"family",
item[mainFields[@"row6"]], mainFields[@"row6"],
item[mainFields[@"row8"]], mainFields[@"row8"],
year, @"year",
rating, @"rating",
mainFields[@"playlistid"], @"playlistid",
row7obj, row7key,
item[mainFields[@"row9"]], mainFields[@"row9"],
item[mainFields[@"row10"]], mainFields[@"row10"],
item[mainFields[@"row11"]], mainFields[@"row11"],
item[mainFields[@"row12"]], mainFields[@"row12"],
row13obj, row13key,
row14obj, row14key,
row15obj, row15key,
item[mainFields[@"row16"]], mainFields[@"row16"],
item[mainFields[@"row17"]], mainFields[@"row17"],
item[mainFields[@"row18"]], mainFields[@"row18"],
item[mainFields[@"row20"]], mainFields[@"row20"],
nil];
return newDict;
}
- (CGPoint)getGlobalSearchThumbsize:(NSDictionary*)item {
CGPoint thumbSize = CGPointMake(DEFAULT_THUMB_WIDTH, DEFAULT_ROW_HEIGHT);
if ([item[@"family"] isEqualToString:@"movieid"] ||
[item[@"family"] isEqualToString:@"setid"] ||
[item[@"family"] isEqualToString:@"musicvideoid"] ||
[item[@"family"] isEqualToString:@"tvshowid"]) {
thumbSize.x = DEFAULT_THUMB_WIDTH;
thumbSize.y = PORTRAIT_ROW_HEIGHT;
}
return thumbSize;
}
- (NSUInteger)getGlobalSearchLookupIndexForItemId:(NSString*)itemid {
return [AppDelegate.instance.globalSearchLookup getLookupIndexForItemId:itemid];
}
- (NSString*)getGlobalSearchThumb:(NSDictionary*)item {
return [AppDelegate.instance.globalSearchLookup getThumbForItem:item];
}
- (mainMenu*)getMainMenu:(id)item {
mainMenu *menuItem = self.detailItem;
if (globalSearchView) {
mainMenu *menuFromLookup = [AppDelegate.instance.globalSearchLookup getMenuForItem:item];
menuItem = menuFromLookup ?: menuItem;
}
return menuItem;
}
- (int)getActiveTab:(id)item {
int activeTab = chosenTab;
if (globalSearchView) {
NSInteger tab = [AppDelegate.instance.globalSearchLookup getTabForItem:item];
activeTab = tab != NSNotFound ? (int)tab : activeTab;
}
return activeTab;
}
- (void)setIndexViewVisibility {
// Only show the collection view index, if there are valid index titles to show
self.indexView.hidden = self.indexView.indexTitles.count <= 1;
}
- (NSDictionary*)getItemFromIndexPath:(NSIndexPath*)indexPath {
NSDictionary *item;
if ([self doesShowSearchResults] && !useSectionInSearchResults) {
if (indexPath.row < self.filteredListContent.count) {
item = self.filteredListContent[indexPath.row];
}
}
else {
if (indexPath.section < self.sectionArray.count) {
if (indexPath.row < [self.sections[self.sectionArray[indexPath.section]] count]) {
item = self.sections[self.sectionArray[indexPath.section]][indexPath.row];
}
}
}
return item;
}
- (BOOL)wasSeasonPlayed:(NSInteger)section {
BOOL seasonWasPlayed = YES;
if (section < self.sectionArray.count) {
for (NSDictionary *episode in self.sections[sectionArray[section]]) {
if ([episode[@"playcount"] intValue] == 0) {
seasonWasPlayed = NO;
break;
}
}
}
return seasonWasPlayed;
}
- (void)updatePlaycount {
if (tvshowsView) {
// In tvshowsview we need to sync the TV Shows to retrieve playcount and to update the watched overlays.
[self startRetrieveDataWithRefresh:YES];
}
else if (episodesView) {
// In episodesView we do only want to reloadData to keep the section closed/opened in their current state.
[dataList reloadData];
}
}
- (NSString*)getAmountOfSearchResultsString {
NSString *results = @"";
NSUInteger numResult = self.filteredListContent.count;
if (numResult > 0) {
if (numResult > 1) {
// Keep cast to (int) as "%d" is used for many translated languages
results = LOCALIZED_STR_ARGS(@"%d results", (int)numResult);
}
else {
results = LOCALIZED_STR(@"1 result");
}
}
return results;
}
- (void)setSearchBar:(UISearchBar*)searchBar toColor:(UIColor*)sectionColor tintColor:(UIColor*)tintColor {
UITextField *searchTextField = [self getSearchTextField:searchBar];
if (searchTextField != nil) {
UIImageView *iconView = (id)searchTextField.leftView;
iconView.image = [iconView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
iconView.tintColor = tintColor;
searchTextField.textColor = tintColor;
searchTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.searchController.searchBar.placeholder attributes:@{NSForegroundColorAttributeName: tintColor}];
}
searchBar.backgroundColor = sectionColor;
searchBar.tintColor = tintColor;
searchBar.barTintColor = tintColor;
}
- (void)setViewColor:(UIView*)view image:(UIImage*)image isTopMost:(BOOL)isTopMost label1:(UILabel*)label1 label2:(UILabel*)label2 label3:(UILabel*)label3 label4:(UILabel*)label4 gradient:(CAGradientLayer*)gradient infoButton:(UIButton*)infoButton {
// Gather average cover color and limit saturation
UIColor *mainColor = [Utilities getUIColorFromImage:image];
// Create gradient based on average color
UIColor *gradientTop = [Utilities sectionGradientTopColor:mainColor];
UIColor *gradientBottom = [Utilities sectionGradientBottomColor:mainColor];
gradient.colors = @[
(id)gradientTop.CGColor,
(id)gradientBottom.CGColor,
];
[view.layer insertSublayer:gradient atIndex:0];
// Set text colors
UIColor *label12Color = [Utilities contrastColor:gradientTop
lightColor:[Utilities getGrayColor:255 alpha:1.0]
darkColor:[Utilities getGrayColor:0 alpha:1.0]];
UIColor *label34Color = [label12Color colorWithAlphaComponent:0.95];
// Set colors for the different labels
label1.textColor = label2.textColor = label12Color;
label3.textColor = label4.textColor = label34Color;
// Set color of info button
UIImage *buttonImage = [Utilities colorizeImage:[UIImage imageNamed:@"table_arrow_right"] withColor:label34Color];
[infoButton setImage:buttonImage forState:UIControlStateNormal];
// Only the top most item shall define albumcolor, searchbar tint and navigationbar tint
if (isTopMost) {
albumColor = mainColor;
UIColor *searchbarTintColor = [label12Color colorWithAlphaComponent:0.8];
[self setSearchBar:self.searchController.searchBar toColor:gradientTop tintColor:searchbarTintColor];
[self setSearchBar:(UISearchBar*)dataList.tableHeaderView toColor:gradientTop tintColor:searchbarTintColor];
[self setNavigationBarTint:[Utilities textTintColor:albumColor]];
}
}
- (BOOL)doesShowSearchResults {
BOOL result = NO;
if (@available(iOS 13.0, *)) {
result = self.searchController.showsSearchResultsController;
}
else {
// Fallback on earlier versions
result = (self.filteredListContent.count > 0);
}
return result;
}
- (UITextField*)getSearchTextField {
return [self getSearchTextField:self.searchController.searchBar];
}
- (UITextField*)getSearchTextField:(UISearchBar*)searchBar {
UITextField *textfield = nil;
if (@available(iOS 13.0, *)) {
textfield = searchBar.searchTextField;
}
else {
textfield = [searchBar valueForKey:@"searchField"];
}
return textfield;
}
- (void)setGridListButtonImage:(BOOL)isGridView {
NSString *imgName = isGridView ? @"st_view_grid" : @"st_view_list";
UIImage *image = [Utilities colorizeImage:[UIImage imageNamed:imgName] withColor:ICON_TINT_COLOR];
[button6 setBackgroundImage:image forState:UIControlStateNormal];
}
- (void)setSortButtonImage:(NSString*)sortOrder {
NSString *imgName = [sortOrder isEqualToString:@"descending"] ? @"st_sort_desc" : @"st_sort_asc";
UIImage *image = [Utilities colorizeImage:[UIImage imageNamed:imgName] withColor:ICON_TINT_COLOR];
[button7 setBackgroundImage:image forState:UIControlStateNormal];
}
- (void)setButtonViewContent:(int)activeTab {
mainMenu *menuItem = self.detailItem;
NSDictionary *methods = menuItem.mainMethod[chosenTab];
NSDictionary *parameters = menuItem.mainParameters[chosenTab];
// Build basic button list
[self buildButtons:activeTab];
// Show grid/list button when grid view is possible
button6.hidden = [self collectionViewCanBeEnabled] ? NO : YES;
// Set up sorting
sortMethodIndex = -1;
sortMethodName = nil;
sortAscDesc = nil;
[self setUpSort:methods parameters:parameters];
// Show sort button when sorting is possible
button7.hidden = parameters[@"available_sort_methods"] ? NO : YES;
[self hideButtonListWhenEmpty];
}
- (void)setViewInset:(UIScrollView*)scrollView bottom:(CGFloat)bottomInset {
UIEdgeInsets viewInsets = scrollView.contentInset;
viewInsets.bottom = bottomInset;
scrollView.contentInset = viewInsets;
scrollView.scrollIndicatorInsets = viewInsets;
}
- (void)hideButtonList:(BOOL)hide {
if (hide) {
buttonsView.hidden = YES;
[self setViewInset:dataList bottom:0];
[self setViewInset:collectionView bottom:0];
}
else {
buttonsView.hidden = NO;
CGFloat bottomInset = buttonsViewBgToolbar.frame.size.height;
[self setViewInset:dataList bottom:bottomInset];
[self setViewInset:collectionView bottom:bottomInset];
}
}
- (void)hideButtonListWhenEmpty {
// Hide the toolbar when no button is shown at all
BOOL hide = button1.hidden && button2.hidden && button3.hidden && button4.hidden &&
button5.hidden && button6.hidden && button7.hidden;
[self hideButtonList:hide];
}
- (void)toggleOpen:(UITapGestureRecognizer*)sender {
[self.searchController.searchBar resignFirstResponder];
[self.searchController setActive:NO];
NSInteger section = [sender.view tag];
// Toggle the section's state (open/close)
BOOL expandSection = ![self.sectionArrayOpen[section] boolValue];
self.sectionArrayOpen[section] = @(expandSection);
// Build the section content
NSInteger countEpisodes = [self.sections[self.sectionArray[section]] count];
NSMutableArray *indexPaths = [NSMutableArray new];
for (NSInteger i = 0; i < countEpisodes; i++) {
[indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:section]];
}
// Add/remove the section content
UIButton *toggleButton = (UIButton*)[sender.view viewWithTag:SEASON_VIEW_CELL_TOGGLE];
if (expandSection) {
[dataList performBatchUpdates:^{
[dataList insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop];
} completion:nil];
}
else {
[dataList performBatchUpdates:^{
[dataList deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop];
} completion:nil];
}
toggleButton.selected = expandSection;
// Refresh layout (moves section header to top when expanding any season or when toggling the first season)
int visibleRows = 0;
for (int i = 0; i < section; i++) {
visibleRows += [dataList numberOfRowsInSection:i];
}
int insetToMoveSectionToTop = iOSYDelta + section * albumViewHeight + visibleRows * cellHeight;
if (expandSection || section == 0) {
// Moves inset to show current section on top
[dataList setContentOffset:CGPointMake(0, insetToMoveSectionToTop) animated:YES];
}
}
- (void)goBack:(id)sender {
if (IS_IPHONE) {
[self.navigationController popViewControllerAnimated:YES];
}
else {
[[NSNotificationCenter defaultCenter] postNotificationName:@"UIApplicationEnableStackPan" object:nil];
}
}
- (void)layoutTVShowCell:(UIView*)cell useDefaultThumb:(BOOL)useFallback {
// Exception handling for TVShow banner view
if (tvshowsView) {
// First tab shows the banner
if (chosenTab == 0) {
// When not in grid and not in fullscreen view
if (!enableCollectionView && !stackscrollFullscreen) {
// If loaded, we use a dark background
if (!useFallback) {
cell.backgroundColor = SYSTEMGRAY6_DARKMODE;
}
// If not loaded, use default background color and poster dimensions for default thumb
else {
cell.backgroundColor = [Utilities getSystemGray6];
}
}
// When in grid or fullscreen view
else {
cell.backgroundColor = SYSTEMGRAY6_DARKMODE;
}
}
// Other tabs (e.g. list of episodes) use default layout
else {
if (enableCollectionView) {
cell.backgroundColor = SYSTEMGRAY6_DARKMODE;
}
else {
cell.backgroundColor = [Utilities getSystemGray6];
}
}
if ([cell isKindOfClass:[UITableViewCell class]]) {
[(UITableViewCell*)cell contentView].backgroundColor = cell.backgroundColor;
}
}
}
- (void)setCellImageView:(UIImageView*)imgView cell:(UIView*)cell dictItem:(NSDictionary*)item url:(NSString*)stringURL size:(CGSize)viewSize defaultImg:(NSString*)displayThumb {
if (viewSize.width == 0 || viewSize.height == 0) {
[self layoutTVShowCell:cell useDefaultThumb:NO];
return;
}
if ([item[@"family"] isEqualToString:@"channelid"] ||
[item[@"family"] isEqualToString:@"recordingid"] ||
[item[@"family"] isEqualToString:@"type"]) {
imgView.contentMode = UIViewContentModeScaleAspectFit;
}
BOOL isOnPVR = [item[@"path"] hasPrefix:@"pvr:"];
[Utilities applyRoundedEdgesView:imgView];
// In few cases stringURL does not hold an URL path but a loadable icon name. In this case
// ensure sd_setImageWithURL falls back to this icon.
if (stringURL.length) {
if ([UIImage imageNamed:stringURL]) {
displayThumb = stringURL;
stringURL = @"";
}
}
if (stringURL.length) {
__auto_type __weak weakImageView = imgView;
[imgView sd_setImageWithURL:[NSURL URLWithString:stringURL]
placeholderImage:[UIImage imageNamed:displayThumb]
options:SDWebImageScaleToNativeSize
progress:nil
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *url) {