Skip to content

Commit

Permalink
Merge pull request #209 from wutschel/desaturate_season
Browse files Browse the repository at this point in the history
Better colors for season background, searchbar color follows topmost cover
  • Loading branch information
kambala-decapitator authored Apr 2, 2021
2 parents 971e4e6 + e6db9d1 commit 72b5cc4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
39 changes: 25 additions & 14 deletions XBMC Remote/DetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,22 @@ -(void)updateSyncDate:(NSString *)filePath{

#pragma mark - Utility

-(void)setSearchBarColor:(UIColor*)albumColor {
UITextField *searchTextField = [self getSearchTextField];
UIColor *lightAlbumColor = [utils lighterColorForColor:albumColor];
if (searchTextField != nil) {
UIImageView *iconView = (id)searchTextField.leftView;
iconView.image = [iconView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
iconView.tintColor = lightAlbumColor;
searchTextField.textColor = lightAlbumColor;
searchTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.searchController.searchBar.placeholder attributes: @{NSForegroundColorAttributeName: lightAlbumColor}];
}
self.searchController.searchBar.backgroundColor = albumColor;
self.searchController.searchBar.tintColor = lightAlbumColor;
self.searchController.searchBar.barTintColor = lightAlbumColor;
self.searchController.searchBar.barStyle = UIBarStyleBlack;
}

-(void)setLabelColor:(UIColor*)text fontshadow:(UIColor*)shadow label1:(UILabel*)label1 label2:(UILabel*)label2 label3:(UILabel*)label3 label4:(UILabel*)label4{
[label1 setShadowColor:shadow];
[label1 setTextColor:text];
Expand Down Expand Up @@ -2506,11 +2522,9 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger
albumColor = [utils averageColor:image inverse:NO];
UIColor *lightAlbumColor = [utils lighterColorForColor:albumColor];
self.navigationController.navigationBar.tintColor = lightAlbumColor;
self.searchController.searchBar.tintColor = lightAlbumColor;
if ([[[self.searchController.searchBar subviews] objectAtIndex:0] isKindOfClass:[UIImageView class]]){
[[[self.searchController.searchBar subviews] objectAtIndex:0] removeFromSuperview];
}
[self.searchController.searchBar setBackgroundColor:albumColor];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = albumDetailView.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[albumColor CGColor], (id)[[utils lighterColorForColor:albumColor] CGColor], nil];
Expand All @@ -2519,16 +2533,7 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger
albumFontShadowColor = [utils updateColor:albumColor lightColor:[Utilities getGrayColor:0 alpha:0.3] darkColor:[Utilities getGrayColor:255 alpha:0.3]];
albumDetailsColor = [utils updateColor:albumColor lightColor:[Utilities getGrayColor:255 alpha:0.7] darkColor:[Utilities getGrayColor:0 alpha:0.6]];
[self setLabelColor:albumFontColor fontshadow:albumFontShadowColor label1:artist label2:albumLabel label3:trackCountLabel label4:releasedLabel];
UITextField *searchTextField = [self getSearchTextField];
if (searchTextField != nil) {
if ([searchTextField respondsToSelector:@selector(setAttributedPlaceholder:)]) {
UIImageView *iconView = (id)searchTextField.leftView;
iconView.image = [iconView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
iconView.tintColor = lightAlbumColor;
searchTextField.textColor = lightAlbumColor;
searchTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.searchController.searchBar.placeholder attributes: @{NSForegroundColorAttributeName: lightAlbumColor}];
}
}
[self setSearchBarColor:albumColor];
}
}];
}
Expand Down Expand Up @@ -2651,7 +2656,6 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger
gradient.frame = albumDetailView.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[Utilities getSystemGray5] CGColor], (id)[[Utilities getSystemGray1] CGColor], nil];
[albumDetailView.layer insertSublayer:gradient atIndex:0];
[self.searchController.searchBar setBackgroundColor:[Utilities getSystemGray5]];
if (section>0){
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, -1, viewWidth, 1)];
[lineView setBackgroundColor:[Utilities getGrayColor:242 alpha:1]];
Expand Down Expand Up @@ -2686,6 +2690,10 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger
UIImageView *thumbImageView = [[UIImageView alloc] initWithFrame:CGRectMake(albumViewPadding + toggleIconSpace, albumViewPadding, seasonThumbWidth, albumViewHeight - (albumViewPadding * 2))];
NSString *stringURL = [[self.extraSectionRichResults objectAtIndex:seasonIdx] objectForKey:@"thumbnail"];
NSString *displayThumb=@"coverbox_back_section.png";
if (seasonIdx == 0) {
self.searchController.searchBar.backgroundColor = [Utilities getSystemGray6];
self.searchController.searchBar.tintColor = tableViewSearchBarColor;
}
if ([[item objectForKey:@"filetype"] length]!=0){
displayThumb=stringURL;
}
Expand All @@ -2694,11 +2702,14 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = albumDetailView.bounds;
albumColor = [utils averageColor:image inverse:NO];
albumColor = [utils limitSaturation:albumColor satmax:0.33];
gradient.colors = [NSArray arrayWithObjects:(id)[albumColor CGColor], (id)[[utils lighterColorForColor:albumColor] CGColor], nil];
seasonFontShadowColor = [utils updateColor:albumColor lightColor:[Utilities getGrayColor:0 alpha:0.3] darkColor:[Utilities getGrayColor:255 alpha:0.3]];
seasonFontColor = [utils updateColor:albumColor lightColor:[Utilities getGrayColor:255 alpha:0.7] darkColor:[Utilities getGrayColor:0 alpha:0.6]];
[albumDetailView.layer insertSublayer:gradient atIndex:1];
[self.searchController.searchBar setBackgroundColor:albumColor];
if (seasonIdx == 0) {
[self setSearchBarColor:albumColor];
}
[self setLabelColor:seasonFontColor fontshadow:seasonFontShadowColor label1:artist label2:albumLabel label3:trackCountLabel label4:releasedLabel];
}];
}
Expand Down
1 change: 1 addition & 0 deletions XBMC Remote/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ typedef enum {
@interface Utilities : NSObject

- (UIColor *)averageColor:(UIImage *)image inverse:(BOOL)inverse;
- (UIColor *)limitSaturation:(UIColor *)c satmax:(CGFloat)satmax;
- (UIColor *)slightLighterColorForColor:(UIColor *)c;
- (UIColor *)lighterColorForColor:(UIColor *)c;
- (UIColor *)darkerColorForColor:(UIColor *)c;
Expand Down
11 changes: 11 additions & 0 deletions XBMC Remote/Utilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ - (UIColor *)averageColor:(UIImage *)image inverse:(BOOL)inverse{
return [UIColor colorWithRed:f * red green:f * green blue:f * blue alpha:1];
}

- (UIColor *)limitSaturation:(UIColor *)color_in satmax:(CGFloat)satmax {
CGFloat hue, sat, bright, alpha;
UIColor *color_out = nil;
if ([color_in getHue:&hue saturation:&sat brightness:&bright alpha:&alpha]) {
// limit saturation
sat = MIN(MAX(sat, 0), satmax);
color_out = [UIColor colorWithHue:hue saturation:sat brightness:bright alpha:alpha];
}
return color_out;
}

+ (UIColor *)tailorColor:(UIColor *)color_in satscale:(CGFloat)satscale brightscale:(CGFloat)brightscale brightmin:(CGFloat)brightmin brightmax:(CGFloat)brightmax{
CGFloat hue, sat, bright, alpha;
UIColor *color_out = nil;
Expand Down

0 comments on commit 72b5cc4

Please sign in to comment.