Skip to content

Commit

Permalink
Refactor setting cell's imageView
Browse files Browse the repository at this point in the history
Move duplicated code into helper function.
  • Loading branch information
wutschel committed Sep 18, 2021
1 parent e8df809 commit 207d3d9
Showing 1 changed file with 26 additions and 37 deletions.
63 changes: 26 additions & 37 deletions XBMC Remote/DetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,29 @@ - (void)goBack:(id)sender {
}
}

- (void)setCellImageView:(UIImageView*)imgView dictItem:(NSDictionary*)item url:(NSString*)stringURL size:(CGSize)viewSize defaultImg:(NSString*)displayThumb {
if ([item[@"family"] isEqualToString:@"channelid"] || [item[@"family"] isEqualToString:@"type"]) {
[imgView setContentMode:UIViewContentModeScaleAspectFit];
}
BOOL showBorder = !([item[@"family"] isEqualToString:@"channelid"] ||
[item[@"family"] isEqualToString:@"recordingid"] ||
[item[@"family"] isEqualToString:@"type"] ||
[item[@"family"] isEqualToString:@"file"]);
BOOL isOnPVR = [item[@"path"] hasPrefix:@"pvr:"];
[Utilities applyRoundedEdgesView:imgView drawBorder:showBorder];
if (![stringURL isEqualToString:@""]) {
__auto_type __weak weakImageView = imgView;
[imgView setImageWithURL:[NSURL URLWithString:stringURL] placeholderImage:[UIImage imageNamed:displayThumb] options:0 andResize:viewSize withBorder:showBorder progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
if (channelListView || channelGuideView || recordingListView || isOnPVR) {
[Utilities setLogoBackgroundColor:weakImageView mode:logoBackgroundMode];
}
}];
}
else {
[imgView setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:displayThumb]];
}
}

#pragma mark - Tabbar management

- (IBAction)showMore:(id)sender {
Expand Down Expand Up @@ -1343,25 +1366,9 @@ - (UICollectionViewCell*)collectionView:(UICollectionView*)cView cellForItemAtIn
else if (channelListView) {
[cell setIsRecording:[item[@"isrecording"] boolValue]];
}
if ([item[@"family"] isEqualToString:@"channelid"]) {
[cell.posterThumbnail setContentMode:UIViewContentModeScaleAspectFit];
}
BOOL showBorder = !([item[@"family"] isEqualToString:@"channelid"] ||
[item[@"family"] isEqualToString:@"recordingid"] ||
[item[@"family"] isEqualToString:@"type"] ||
[item[@"family"] isEqualToString:@"file"]);
BOOL isOnPVR = [item[@"path"] hasPrefix:@"pvr:"];
cell.posterThumbnail.frame = cell.bounds;
[Utilities applyRoundedEdgesView:cell.posterThumbnail drawBorder:showBorder];
if (![stringURL isEqualToString:@""]) {
[cell.posterThumbnail setImageWithURL:[NSURL URLWithString:stringURL] placeholderImage:[UIImage imageNamed:displayThumb] options:0 andResize:CGSizeMake(cellthumbWidth, cellthumbHeight) withBorder:showBorder progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
if (channelListView || channelGuideView || recordingListView || isOnPVR) {
[Utilities setLogoBackgroundColor:cell.posterThumbnail mode:logoBackgroundMode];
}
}];
}
else {
[cell.posterThumbnail setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:displayThumb]];
[self setCellImageView:cell.posterThumbnail dictItem:item url:stringURL size:CGSizeMake(cellthumbWidth, cellthumbHeight) defaultImg:displayThumb];
if ([stringURL isEqualToString:@""]) {
[cell.posterThumbnail setBackgroundColor:[Utilities getGrayColor:28 alpha:1.0]];
}
// Set label visibility based on setting and current view
Expand Down Expand Up @@ -2287,25 +2294,7 @@ - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSI
genre.hidden = NO;
runtimeyear.hidden = NO;
}
if ([item[@"family"] isEqualToString:@"channelid"] || [item[@"family"] isEqualToString:@"type"]) {
[cell.urlImageView setContentMode:UIViewContentModeScaleAspectFit];
}
BOOL showBorder = !([item[@"family"] isEqualToString:@"channelid"] ||
[item[@"family"] isEqualToString:@"recordingid"] ||
[item[@"family"] isEqualToString:@"type"] ||
[item[@"family"] isEqualToString:@"file"]);
BOOL isOnPVR = [item[@"path"] hasPrefix:@"pvr:"];
[Utilities applyRoundedEdgesView:cell.urlImageView drawBorder:showBorder];
if (![stringURL isEqualToString:@""]) {
[cell.urlImageView setImageWithURL:[NSURL URLWithString:stringURL] placeholderImage:[UIImage imageNamed:displayThumb] options:0 andResize:CGSizeMake(thumbWidth, cellHeight) withBorder:showBorder progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
if (channelListView || channelGuideView || recordingListView || isOnPVR) {
[Utilities setLogoBackgroundColor:cell.urlImageView mode:logoBackgroundMode];
}
}];
}
else {
[cell.urlImageView setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:displayThumb]];
}
[self setCellImageView:cell.urlImageView dictItem:item url:stringURL size:CGSizeMake(thumbWidth, cellHeight) defaultImg:displayThumb];
}
else if (albumView) {
UILabel *trackNumber = (UILabel*)[cell viewWithTag:101];
Expand Down

0 comments on commit 207d3d9

Please sign in to comment.