//
//  UniversalViewController.m
//  Allzic
//
//  Created by Alia Bourouis on 13/03/14.
//  Copyright (c) 2014 Alia Bourouis. All rights reserved.
//

#import "UniversalViewController.h"
#import "AppDelegate.h"

@interface UniversalViewController ()

@end

@implementation UniversalViewController

@synthesize appDelegate,dataTable,dataArray,searchTextField,navigationView,navTitleImage,loadingTableView,noResultTableLabel;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        [self.view setBackgroundColor:[UIColor whiteColor]];
        
        navigationView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, appDelegate.screenBounds.size.width, 64.0f)];
        if (appDelegate.systemVersion < 7.0) {
            [navigationView setFrame:CGRectMake(0.0f, 0.0f, appDelegate.screenBounds.size.width, 44.0f)];
        }
        navigationView.backgroundColor = [UIColor colorWithRed:46.0f/255.0f green:48.0f/255.0f blue:46.0f/255.0f alpha:1.0f];
        [self.view addSubview:navigationView];
        
        navigationTitle = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, navigationView.frame.size.height - 44.0f, appDelegate.screenBounds.size.width, 44.0f)];
        navigationTitle.backgroundColor = [UIColor clearColor];
        navigationTitle.textColor = [UIColor whiteColor];
        navigationTitle.textAlignment = NSTextAlignmentCenter;
        navigationTitle.font = [UIFont boldSystemFontOfSize:16];
        [navigationView addSubview:navigationTitle];
        
        navTitleImage = [[UIImageView alloc] initWithFrame:CGRectMake((appDelegate.screenBounds.size.width - 145.0f)/2, navigationView.frame.size.height - 37.0f, 145.0f, 30.0f)];
        [navTitleImage setImage:[UIImage imageNamed:@"logo_navbar"]];
        [navTitleImage setContentMode:UIViewContentModeScaleAspectFit];
        [navTitleImage setClipsToBounds:YES];
        
        backView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, navigationView.frame.size.height, navigationView.frame.size.height)];
        [backView setBackgroundColor:[UIColor clearColor]];
        [navigationView addSubview:backView];
        
        UIImageView *backImage = [[UIImageView alloc] initWithFrame:CGRectMake(5.0f, navigationView.frame.size.height - 34.0f, 24.0f, 24.0f)];
        [backImage setImage:[UIImage imageNamed:@"backPicto"]];
        [backImage setContentMode:UIViewContentModeScaleAspectFit];
        [backImage setClipsToBounds:YES];
        [backView addSubview:backImage];
        
        UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [backButton setFrame:backView.frame];
        [backButton addTarget:self action:@selector(backToParentView) forControlEvents:UIControlEventTouchUpInside];
        [backView addSubview:backButton];
        [self hideBackView];
        
        searchView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, navigationView.frame.origin.y + navigationView.frame.size.height, navigationView.frame.size.width, 58.0f)];
        [searchView setBackgroundColor:[UIColor whiteColor]];
        [self.view addSubview:searchView];
        
        searchBackground = [[UIView alloc] initWithFrame:CGRectMake(10.0f, 10.0f, searchView.frame.size.width - 20.0f, 38.0f)];
        [searchBackground setBackgroundColor:[UIColor whiteColor]];
        searchBackground.layer.borderWidth  = 0.5;
        searchBackground.layer.borderColor  = [UIColor colorWithRed:31.0f/255.0f green:139.0f/255.0f blue:186.0f/255.0f alpha:1.0f].CGColor;
        [searchView addSubview:searchBackground];
        
        UIImageView *searchImage = [[UIImageView alloc] initWithFrame:CGRectMake(searchBackground.frame.origin.x, searchBackground.frame.origin.y, searchBackground.frame.size.height, searchBackground.frame.size.height)];
        [searchImage setImage:[UIImage imageNamed:@"search_home"]];
        [searchImage setContentMode:UIViewContentModeScaleAspectFill];
        [searchImage setClipsToBounds:YES];
        [searchView addSubview:searchImage];
        
        searchTextField = [[UITextField alloc] initWithFrame:CGRectMake(searchImage.frame.origin.x + searchImage.frame.size.width + 5.0f, searchBackground.frame.origin.y + 10.0f, searchBackground.frame.size.width - searchImage.frame.origin.x - searchImage.frame.size.width - 0.0f, searchBackground.frame.size.height - 10.0f)];
        [searchTextField setClearButtonMode:UITextFieldViewModeWhileEditing];
        [searchTextField setPlaceholder:@"Rechercher une radio"];
        [searchTextField setDelegate:self];
        [searchTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
        [searchView addSubview:searchTextField];
        
        nowPlayingView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, searchView.frame.origin.y + searchView.frame.size.height, appDelegate.screenBounds.size.width, 50.0f)];
        nowPlayingView.backgroundColor = [UIColor colorWithRed:8.0f/255.0f green:41.0f/255.0f blue:55.0f/255.0f alpha:1.0f];
        nowPlayingView.layer.borderWidth  = 0.5;
        nowPlayingView.layer.borderColor  = [UIColor colorWithRed:160.0f/255.0f green:160.0f/255.0f blue:160.0f/255.0f alpha:1.0f].CGColor;
        //[self.view addSubview:nowPlayingView];
        
        UILabel *nowPlayingLabel = [[UILabel alloc] initWithFrame:CGRectMake(5.0f, 5.0f, appDelegate.screenBounds.size.width - 75.0f, 15.0f)];
        nowPlayingLabel.backgroundColor = [UIColor clearColor];
        nowPlayingLabel.textColor = [UIColor whiteColor];
        [nowPlayingLabel setText:@"Vous écoutez :"];
        nowPlayingLabel.font = [UIFont systemFontOfSize:12];
        nowPlayingLabel.numberOfLines = 1;
        [nowPlayingView addSubview:nowPlayingLabel];
        
        nowPlayingTitle = [[UILabel alloc] initWithFrame:CGRectMake(5.0f, 20.0f, appDelegate.screenBounds.size.width - 75.0f, 20.0f)];
        nowPlayingTitle.backgroundColor = [UIColor clearColor];
        nowPlayingTitle.textColor = [UIColor whiteColor];
        nowPlayingTitle.font = [UIFont systemFontOfSize:16];
        nowPlayingTitle.numberOfLines = 1;
        [nowPlayingView addSubview:nowPlayingTitle];
        
        UIButton *nowPlayingHeaderButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [nowPlayingHeaderButton setFrame:CGRectMake(0.0f, 0.0f, nowPlayingView.frame.size.width, nowPlayingView.frame.size.height)];
        [nowPlayingHeaderButton addTarget:self action:@selector(nowPlayingHeaderPressed) forControlEvents:UIControlEventTouchUpInside];
        [nowPlayingView addSubview:nowPlayingHeaderButton];
        
        nowPlayingPlayStopImage = [[UIImageView alloc] initWithFrame:CGRectMake(appDelegate.screenBounds.size.width - 65.0f, 15.0f, 20.0f, 20.0f)];
        [nowPlayingPlayStopImage setContentMode:UIViewContentModeScaleAspectFit];
        [nowPlayingPlayStopImage setImage:[UIImage imageNamed:@"stopButton"]];
        [nowPlayingPlayStopImage setClipsToBounds:YES];
        [nowPlayingView addSubview:nowPlayingPlayStopImage];
        
        nowPlayingPlayStopButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [nowPlayingPlayStopButton setFrame:nowPlayingPlayStopImage.frame];
        [nowPlayingPlayStopButton addTarget:self action:@selector(stopButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [nowPlayingView addSubview:nowPlayingPlayStopButton];
        
        nowPlayingLikeImage = [[UIImageView alloc] initWithFrame:CGRectMake(appDelegate.screenBounds.size.width - 35.0f, 12.0f, 25.0f, 25.0f)];
        [nowPlayingLikeImage setContentMode:UIViewContentModeScaleAspectFit];
        [nowPlayingLikeImage setClipsToBounds:YES];
        [nowPlayingView addSubview:nowPlayingLikeImage];
        
        nowPlayingLikeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [nowPlayingLikeButton setFrame:nowPlayingLikeImage.frame];
        [nowPlayingView addSubview:nowPlayingLikeButton];
        
        footerTabView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, appDelegate.screenBounds.size.height - 49.0f, appDelegate.screenBounds.size.width, 49.0f)];
        if (appDelegate.systemVersion < 7.0) {
            [footerTabView setFrame:CGRectMake(0.0f, appDelegate.screenBounds.size.height - 49.0f - 20.0f, appDelegate.screenBounds.size.width, 49.0f)];
        }
        footerTabView.backgroundColor = [UIColor blackColor];
        [self.view addSubview:footerTabView];
        
        allzicView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, (appDelegate.screenBounds.size.width/5), footerTabView.frame.size.height)];
        allzicView.backgroundColor = [UIColor clearColor];
        [footerTabView addSubview:allzicView];
        
        tabAllzicImage = [[UIImageView alloc] initWithFrame:CGRectMake(10.0f, 5.0f, allzicView.frame.size.width - 20.0f, 24.0f)];
        [tabAllzicImage setContentMode:UIViewContentModeScaleAspectFit];
        tabAllzicImage.image = [UIImage imageNamed:@"tabAllzic"];
        [allzicView addSubview:tabAllzicImage];
        tabAllzicTitle = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 30.0f, allzicView.frame.size.width, 15.0f)];
        tabAllzicTitle.textAlignment = NSTextAlignmentCenter;
        tabAllzicTitle.font = [UIFont systemFontOfSize:10.0f];
        tabAllzicTitle.textColor = [UIColor whiteColor];
        tabAllzicTitle.text = @"Allzic";
        tabAllzicTitle.backgroundColor = [UIColor clearColor];
        [allzicView addSubview:tabAllzicTitle];
        tabAllzicButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [tabAllzicButton setFrame:CGRectMake(0.0f, 0.0f, allzicView.frame.size.width, allzicView.frame.size.height)];
        tabAllzicButton.tag = 0;
        [tabAllzicButton addTarget:appDelegate action:@selector(selectTab:) forControlEvents:UIControlEventTouchUpInside];
        [allzicView addSubview:tabAllzicButton];
        
        
        
        categoriesView = [[UIView alloc] initWithFrame:CGRectMake((appDelegate.screenBounds.size.width/5), 0.0f, (appDelegate.screenBounds.size.width/5), footerTabView.frame.size.height)];
        categoriesView.backgroundColor = [UIColor clearColor];
        [footerTabView addSubview:categoriesView];
        
        tabCategoriesImage = [[UIImageView alloc] initWithFrame:CGRectMake(10.0f, 5.0f, categoriesView.frame.size.width - 20.0f, 24.0f)];
        [tabCategoriesImage setContentMode:UIViewContentModeScaleAspectFit];
        tabCategoriesImage.image = [UIImage imageNamed:@"tabCategories"];
        [categoriesView addSubview:tabCategoriesImage];
        tabCategoriesTitle = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 30.0f, categoriesView.frame.size.width, 15.0f)];
        tabCategoriesTitle.textAlignment = NSTextAlignmentCenter;
        tabCategoriesTitle.font = [UIFont systemFontOfSize:10.0f];
        tabCategoriesTitle.textColor = [UIColor whiteColor];
        tabCategoriesTitle.text = @"Catégories";
        tabCategoriesTitle.backgroundColor = [UIColor clearColor];
        [categoriesView addSubview:tabCategoriesTitle];
        tabCategoriesButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [tabCategoriesButton setFrame:CGRectMake(0.0f, 0.0f, categoriesView.frame.size.width, categoriesView.frame.size.height)];
        tabCategoriesButton.tag = 1;
        [tabCategoriesButton addTarget:appDelegate action:@selector(selectTab:) forControlEvents:UIControlEventTouchUpInside];
        [categoriesView addSubview:tabCategoriesButton];
        
        
        exploreView = [[UIView alloc] initWithFrame:CGRectMake(((appDelegate.screenBounds.size.width/5)*2), 0.0f, (appDelegate.screenBounds.size.width/5), footerTabView.frame.size.height)];
        exploreView.backgroundColor = [UIColor clearColor];
        [footerTabView addSubview:exploreView];
        
        tabExploreImage = [[UIImageView alloc] initWithFrame:CGRectMake(10.0f, 5.0f, exploreView.frame.size.width - 20.0f, 24.0f)];
        [tabExploreImage setContentMode:UIViewContentModeScaleAspectFit];
        tabExploreImage.image = [UIImage imageNamed:@"tabExplore"];
        [exploreView addSubview:tabExploreImage];
        tabExploreTitle = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 30.0f, exploreView.frame.size.width, 15.0f)];
        tabExploreTitle.textAlignment = NSTextAlignmentCenter;
        tabExploreTitle.font = [UIFont systemFontOfSize:10.0f];
        tabExploreTitle.textColor = [UIColor whiteColor];
        tabExploreTitle.text = @"Explorer";
        tabExploreTitle.backgroundColor = [UIColor clearColor];
        [exploreView addSubview:tabExploreTitle];
        tabExploreButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [tabExploreButton setFrame:CGRectMake(0.0f, 0.0f, exploreView.frame.size.width, exploreView.frame.size.height)];
        tabExploreButton.tag = 2;
        [tabExploreButton addTarget:appDelegate action:@selector(selectTab:) forControlEvents:UIControlEventTouchUpInside];
        [exploreView addSubview:tabExploreButton];
        
        
        favoritesView = [[UIView alloc] initWithFrame:CGRectMake((appDelegate.screenBounds.size.width/5)*3, 0.0f, (appDelegate.screenBounds.size.width/5), footerTabView.frame.size.height)];
        favoritesView.backgroundColor = [UIColor clearColor];
        [footerTabView addSubview:favoritesView];
        
        tabFavoritesImage = [[UIImageView alloc] initWithFrame:CGRectMake(10.0f, 5.0f, favoritesView.frame.size.width - 20.0f, 24.0f)];
        [tabFavoritesImage setContentMode:UIViewContentModeScaleAspectFit];
        tabFavoritesImage.image = [UIImage imageNamed:@"tabFavorite"];
        [favoritesView addSubview:tabFavoritesImage];
        tabFavoritesTitle = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 30.0f, favoritesView.frame.size.width, 15.0f)];
        tabFavoritesTitle.textAlignment = NSTextAlignmentCenter;
        tabFavoritesTitle.font = [UIFont systemFontOfSize:10.0f];
        tabFavoritesTitle.textColor = [UIColor whiteColor];
        tabFavoritesTitle.text = @"Favoris";
        tabFavoritesTitle.backgroundColor = [UIColor clearColor];
        [favoritesView addSubview:tabFavoritesTitle];
        tabFavoritesButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [tabFavoritesButton setFrame:CGRectMake(0.0f, 0.0f, favoritesView.frame.size.width, favoritesView.frame.size.height)];
        tabFavoritesButton.tag = 3;
        [tabFavoritesButton addTarget:appDelegate action:@selector(selectTab:) forControlEvents:UIControlEventTouchUpInside];
        [favoritesView addSubview:tabFavoritesButton];
        
        
        plusView = [[UIView alloc] initWithFrame:CGRectMake((appDelegate.screenBounds.size.width/5)*4, 0.0f, (appDelegate.screenBounds.size.width/5), footerTabView.frame.size.height)];
        plusView.backgroundColor = [UIColor clearColor];
        [footerTabView addSubview:plusView];
        
        tabPlusImage = [[UIImageView alloc] initWithFrame:CGRectMake(10.0f, 5.0f, plusView.frame.size.width - 20.0f, 24.0f)];
        [tabPlusImage setContentMode:UIViewContentModeScaleAspectFit];
        tabPlusImage.image = [UIImage imageNamed:@"tabPlus"];
        [plusView addSubview:tabPlusImage];
        tabPlusTitle = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 30.0f, plusView.frame.size.width, 15.0f)];
        tabPlusTitle.textAlignment = NSTextAlignmentCenter;
        tabPlusTitle.font = [UIFont systemFontOfSize:10.0f];
        tabPlusTitle.textColor = [UIColor whiteColor];
        tabPlusTitle.text = @"Plus";
        tabPlusTitle.backgroundColor = [UIColor clearColor];
        [plusView addSubview:tabPlusTitle];
        tabPlusButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [tabPlusButton setFrame:CGRectMake(0.0f, 0.0f, plusView.frame.size.width, plusView.frame.size.height)];
        tabPlusButton.tag = 4;
        [tabPlusButton addTarget:appDelegate action:@selector(selectTab:) forControlEvents:UIControlEventTouchUpInside];
        [plusView addSubview:tabPlusButton];
        
        dataTable = [[UITableView alloc] initWithFrame:CGRectMake(0.0f, searchView.frame.origin.y + searchView.frame.size.height, appDelegate.screenBounds.size.width, footerTabView.frame.origin.y - searchView.frame.origin.y - searchView.frame.size.height)];
        dataTable.dataSource = self;
        dataTable.delegate = self;
        dataTable.rowHeight = 45.0f;
        dataTable.separatorStyle = UITableViewCellSeparatorStyleNone;
        dataTable.backgroundColor = [UIColor clearColor];
        [self.view addSubview:dataTable];
        
        iconDownloaderDictionary = [[NSMutableDictionary alloc] init];
        
        
/////////////////////////////////
/////////////////////////////////
        
        loadingTableView = [[UIView alloc] initWithFrame:CGRectMake((dataTable.frame.size.width - 240.0f)/2, dataTable.frame.origin.y + 60.0f, 240.0f, 60.0f)];
        [loadingTableView setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.2]];
        [self.view addSubview:loadingTableView];
        [loadingTableView setHidden:YES];
        
        UIActivityIndicatorView *loadingWheel = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
        [loadingWheel setFrame:CGRectMake(25.0f, (loadingTableView.frame.size.height - loadingWheel.frame.size.height)/2, loadingWheel.frame.size.width, loadingWheel.frame.size.height)];
        [loadingWheel startAnimating];
        [loadingTableView addSubview:loadingWheel];
        
        UILabel *loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(loadingWheel.frame.origin.x + loadingWheel.frame.size.width + 10.0f, loadingWheel.frame.origin.y, 200.0f, loadingWheel.frame.size.height)];
        [loadingLabel setTextAlignment:NSTextAlignmentLeft];
        [loadingLabel setText:@"Chargement en cours"];
        [loadingLabel setTextColor:[UIColor whiteColor]];
        [loadingLabel setBackgroundColor:[UIColor clearColor]];
        [loadingLabel setFont:[UIFont systemFontOfSize:16.0f]];
        [loadingTableView addSubview:loadingLabel];
        
        noResultTableLabel = [[UILabel alloc]initWithFrame:CGRectMake(dataTable.frame.origin.x + 10.0f, dataTable.frame.origin.y + 60.0f, dataTable.frame.size.width - 20.0f, dataTable.rowHeight - 10.0f)];
        [noResultTableLabel setTextAlignment:NSTextAlignmentCenter];
        [noResultTableLabel setText:@"Aucun résultat"];
        [noResultTableLabel setFont:[UIFont boldSystemFontOfSize:16]];
        [noResultTableLabel setNumberOfLines:0];
        [noResultTableLabel setBackgroundColor:[UIColor clearColor]];
        [noResultTableLabel setTextColor:[UIColor grayColor]];
        [self.view addSubview:noResultTableLabel];
        [noResultTableLabel setHidden:YES];
        
/////////////////////////////////
/////////////////////////////////
        
    }
    return self;
}

- (void)setNavigationTitle:(NSString *)title {
    
    navigationTitleString = title;
    navigationTitle.text = navigationTitleString;
}

- (void)nowPlayingHeaderPressed {
    
    [appDelegate setOldVC:self];
    [appDelegate.window setRootViewController:appDelegate.playerVC];
}

- (void)displayBackView {
    
    [navigationView addSubview:backView];
}

- (void)hideBackView {
    
    [backView removeFromSuperview];
}

- (void)stopButtonPressed {
    
    [appDelegate.playerVC stopRadio];
}

- (void)playButtonPressed {
    
    [appDelegate.playerVC playRadio];
}

- (void)backToParentView {
    
}

- (void)setCurrentTabIndex:(int)index {
    
    currentTabIndex = index;
    switch (currentTabIndex) {
        case 0: {
            tabAllzicImage.image = [UIImage imageNamed:@"tabAllzicSelected"];
            tabAllzicTitle.textColor = [UIColor colorWithRed:31.0f/255.0f green:139.0f/255.0f blue:186.0f/255.0f alpha:1.0f];
            
            tabCategoriesImage.image = [UIImage imageNamed:@"tabCategories"];
            tabCategoriesTitle.textColor = [UIColor whiteColor];
            tabExploreImage.image = [UIImage imageNamed:@"tabExplore"];
            tabExploreTitle.textColor = [UIColor whiteColor];
            tabFavoritesImage.image = [UIImage imageNamed:@"tabFavorite"];
            tabFavoritesTitle.textColor = [UIColor whiteColor];
            tabPlusImage.image = [UIImage imageNamed:@"tabPlus"];
            tabPlusTitle.textColor = [UIColor whiteColor];
        }
            break;
        case 1: {
            tabAllzicImage.image = [UIImage imageNamed:@"tabAllzic"];
            tabAllzicTitle.textColor = [UIColor whiteColor];
            
            tabCategoriesImage.image = [UIImage imageNamed:@"tabCategoriesSelected"];
            tabCategoriesTitle.textColor = [UIColor colorWithRed:31.0f/255.0f green:139.0f/255.0f blue:186.0f/255.0f alpha:1.0f];
            
            tabExploreImage.image = [UIImage imageNamed:@"tabExplore"];
            tabExploreTitle.textColor = [UIColor whiteColor];
            tabFavoritesImage.image = [UIImage imageNamed:@"tabFavorite"];
            tabFavoritesTitle.textColor = [UIColor whiteColor];
            tabPlusImage.image = [UIImage imageNamed:@"tabPlus"];
            tabPlusTitle.textColor = [UIColor whiteColor];
        }
            break;
        case 2: {
            tabAllzicImage.image = [UIImage imageNamed:@"tabAllzic"];
            tabAllzicTitle.textColor = [UIColor whiteColor];
            tabCategoriesImage.image = [UIImage imageNamed:@"tabCategories"];
            tabCategoriesTitle.textColor = [UIColor whiteColor];
            
            tabExploreImage.image = [UIImage imageNamed:@"tabExploreSelected"];
            tabExploreTitle.textColor = [UIColor colorWithRed:31.0f/255.0f green:139.0f/255.0f blue:186.0f/255.0f alpha:1.0f];
            
            tabFavoritesImage.image = [UIImage imageNamed:@"tabFavorite"];
            tabFavoritesTitle.textColor = [UIColor whiteColor];
            tabPlusImage.image = [UIImage imageNamed:@"tabPlus"];
            tabPlusTitle.textColor = [UIColor whiteColor];
        }
            break;
        case 3: {
            tabAllzicImage.image = [UIImage imageNamed:@"tabAllzic"];
            tabAllzicTitle.textColor = [UIColor whiteColor];
            tabCategoriesImage.image = [UIImage imageNamed:@"tabCategories"];
            tabCategoriesTitle.textColor = [UIColor whiteColor];
            tabExploreImage.image = [UIImage imageNamed:@"tabExplore"];
            tabExploreTitle.textColor = [UIColor whiteColor];
            
            tabFavoritesImage.image = [UIImage imageNamed:@"tabFavoriteSelected"];
            tabFavoritesTitle.textColor = [UIColor colorWithRed:31.0f/255.0f green:139.0f/255.0f blue:186.0f/255.0f alpha:1.0f];
            
            tabPlusImage.image = [UIImage imageNamed:@"tabPlus"];
            tabPlusTitle.textColor = [UIColor whiteColor];
        }
            break;
        case 4: {
            tabAllzicImage.image = [UIImage imageNamed:@"tabAllzic"];
            tabAllzicTitle.textColor = [UIColor whiteColor];
            tabCategoriesImage.image = [UIImage imageNamed:@"tabCategories"];
            tabCategoriesTitle.textColor = [UIColor whiteColor];
            tabExploreImage.image = [UIImage imageNamed:@"tabExplore"];
            tabExploreTitle.textColor = [UIColor whiteColor];
            tabFavoritesImage.image = [UIImage imageNamed:@"tabFavorite"];
            tabFavoritesTitle.textColor = [UIColor whiteColor];
            
            tabPlusImage.image = [UIImage imageNamed:@"tabPlusSelected"];
            tabPlusTitle.textColor = [UIColor colorWithRed:31.0f/255.0f green:139.0f/255.0f blue:186.0f/255.0f alpha:1.0f];
        }
            break;
            
        default:
            break;
    }
}

- (void)refreshNowPlayingViewWithTitle:(NSString *)title {
    
    [nowPlayingTitle setText:title];
    [self.view addSubview:nowPlayingView];
    [dataTable setFrame:CGRectMake(0.0f, nowPlayingView.frame.origin.y + nowPlayingView.frame.size.height, appDelegate.screenBounds.size.width, footerTabView.frame.origin.y - nowPlayingView.frame.origin.y - nowPlayingView.frame.size.height)];
    if ([self isKindOfClass:[SearchViewController class]]) {
        [dataTable setFrame:CGRectMake(0.0f, dataTable.frame.origin.y, dataTable.frame.size.width, dataTable.frame.size.height + footerTabView.frame.size.height)];
    }
    
    if ([appDelegate.dataController isFavoriteRadioWithId:[[appDelegate.dataController.currentRadioArray objectAtIndex:appDelegate.dataController.currentRadioIndex] objectForKey:@"id"]] == NO) {
        [nowPlayingLikeButton removeTarget:self action:@selector(unlikeRadioButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [nowPlayingLikeButton addTarget:self action:@selector(likeRadioButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [nowPlayingLikeImage setImage:[UIImage imageNamed:@"likeRadio"]];
    } else {
        [nowPlayingLikeButton removeTarget:self action:@selector(likeRadioButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [nowPlayingLikeButton addTarget:self action:@selector(unlikeRadioButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [nowPlayingLikeImage setImage:[UIImage imageNamed:@"likeRadioSelected"]];
    }
}

- (void)refreshNowPlayingViewWithFavorite:(BOOL)isFavorite {
    
    if (isFavorite == YES) {
        [nowPlayingLikeButton removeTarget:self action:@selector(likeRadioButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [nowPlayingLikeButton addTarget:self action:@selector(unlikeRadioButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [nowPlayingLikeImage setImage:[UIImage imageNamed:@"likeRadioSelected"]];
    } else {
        [nowPlayingLikeButton removeTarget:self action:@selector(unlikeRadioButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [nowPlayingLikeButton addTarget:self action:@selector(likeRadioButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [nowPlayingLikeImage setImage:[UIImage imageNamed:@"likeRadio"]];
    }
}

- (void)startMiniPlayer {
    
    [nowPlayingPlayStopButton removeTarget:self action:@selector(playButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    [nowPlayingPlayStopButton addTarget:self action:@selector(stopButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    [nowPlayingPlayStopImage setImage:[UIImage imageNamed:@"stopButton"]];
}

- (void)stopMiniPlayer {
    
    [nowPlayingPlayStopButton removeTarget:self action:@selector(stopButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    [nowPlayingPlayStopButton addTarget:self action:@selector(playButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    [nowPlayingPlayStopImage setImage:[UIImage imageNamed:@"playButton"]];
}

- (void)likeRadioButtonPressed {
    
    [appDelegate likeRadio];
}

- (void)unlikeRadioButtonPressed {
    
    [appDelegate unlikeRadio];
}

- (void)refreshTableWithData:(NSArray *)data {
    
    [loadingTableView setHidden:YES];
    self.dataArray = data;
    infiniteDataArray = nil;
    infiniteDataArray = [[NSMutableArray alloc] init];
    iconDownloaderDictionary = [[NSMutableDictionary alloc] init];
    [self.dataTable reloadData];
    if (dataArray == nil || dataArray.count == 0) {
        [noResultTableLabel setHidden:NO];
    } else {
        [noResultTableLabel setHidden:YES];
    }
}

- (void)selectRadioAtIndex:(id)sender {
    
    int selectedRadioIndex;
    if ([sender isKindOfClass:[UIButton class]]) {
        [appDelegate setOldVC:appDelegate.allzicVC];
        [appDelegate.playerVC setNavigationTitle:@""];
        [appDelegate.playerVC.navigationView addSubview:appDelegate.playerVC.navTitleImage];
        selectedRadioIndex = [(UIButton *)sender tag];
    }
    else {
        [appDelegate.playerVC.navTitleImage removeFromSuperview];
        selectedRadioIndex = [sender intValue];
    }
    [appDelegate selectRadioWithData:dataArray atIndex:selectedRadioIndex];
}


//-----------------------------------------
//		UITextFieldDelegate Delegate
//-----------------------------------------

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    
    if (appDelegate.isSearching == NO) {
        [textField resignFirstResponder];
        [appDelegate setOldVC:self];
        [appDelegate.searchVC refreshTableWithData:nil];
        [appDelegate.window setRootViewController:appDelegate.searchVC];
        appDelegate.isSearching = YES;
        [appDelegate.searchVC.searchTextField performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0.2];
    }
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    [textField resignFirstResponder];
    return NO;
}

- (void)textFieldDidChange:(UITextField *)textField {
    
}


//-----------------------------------------
//		IconDownloader Delegate
//-----------------------------------------

- (void)appImageDidLoad:(IconDownloader *)downloader {
}


//-----------------------------------------
//		TableView Delegate
//-----------------------------------------

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}



-(UIStatusBarStyle)preferredStatusBarStyle {
    
    return UIStatusBarStyleLightContent;
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)])
    {
        [self setNeedsStatusBarAppearanceUpdate];
    }
}


- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
