Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance: Internal rework related to searchbar #1044

Merged
merged 3 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion XBMC Remote/DetailViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
NSString *libraryCachePath;
CGFloat bottomPadding;
NSString *epgCachePath;
BOOL showbar;
BOOL showSearchbar;
dispatch_queue_t epglockqueue;
LogoBackgroundType logoBackgroundMode;
BOOL showkeyboard;
Expand Down
93 changes: 62 additions & 31 deletions XBMC Remote/DetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,8 @@ - (NSString*)getAmountOfSearchResultsString {
return results;
}

- (void)setSearchBarColor:(UIColor*)albumColor {
UITextField *searchTextField = [self getSearchTextField];
- (void)setSearchBar:(UISearchBar*)searchBar toColor:(UIColor*)albumColor {
UITextField *searchTextField = [self getSearchTextField:searchBar];
UIColor *lightAlbumColor = [Utilities updateColor:albumColor
lightColor:[Utilities getGrayColor:255 alpha:0.7]
darkColor:[Utilities getGrayColor:0 alpha:0.6]];
Expand All @@ -757,9 +757,9 @@ - (void)setSearchBarColor:(UIColor*)albumColor {
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;
searchBar.backgroundColor = albumColor;
searchBar.tintColor = lightAlbumColor;
searchBar.barTintColor = lightAlbumColor;
}

- (void)setViewColor:(UIView*)view image:(UIImage*)image isTopMost:(BOOL)isTopMost label1:(UILabel*)label1 label2:(UILabel*)label2 label3:(UILabel*)label3 label4:(UILabel*)label4 {
Expand Down Expand Up @@ -792,7 +792,8 @@ - (void)setViewColor:(UIView*)view image:(UIImage*)image isTopMost:(BOOL)isTopMo
// Only the top most item shall define albumcolor, searchbar tint and navigationbar tint
if (isTopMost) {
albumColor = mainColor;
[self setSearchBarColor:albumColor];
[self setSearchBar:self.searchController.searchBar toColor:albumColor];
[self setSearchBar:(UISearchBar*)dataList.tableHeaderView toColor:albumColor];
self.navigationController.navigationBar.tintColor = [Utilities lighterColorForColor:albumColor];
}
}
Expand All @@ -810,12 +811,16 @@ - (BOOL)doesShowSearchResults {
}

- (UITextField*)getSearchTextField {
return [self getSearchTextField:self.searchController.searchBar];
}

- (UITextField*)getSearchTextField:(UISearchBar*)searchBar {
UITextField *textfield = nil;
if (@available(iOS 13.0, *)) {
textfield = self.searchController.searchBar.searchTextField;
textfield = searchBar.searchTextField;
}
else {
textfield = [self.searchController.searchBar valueForKey:@"searchField"];
textfield = [searchBar valueForKey:@"searchField"];
}
return textfield;
}
Expand Down Expand Up @@ -912,7 +917,6 @@ - (void)toggleOpen:(UITapGestureRecognizer*)sender {
[dataList endUpdates];
}
toggleButton.selected = expandSection;
dataList.tableHeaderView = self.searchController.searchBar;

// Refresh layout (moves section header to top when expanding any season or when toggling the first season)
int visibleRows = 0;
Expand Down Expand Up @@ -1166,9 +1170,7 @@ - (void)configureLibraryView {
collectionView.scrollsToTop = YES;
activeLayoutView = collectionView;

[self initSearchController];
self.searchController.searchBar.backgroundColor = [Utilities getGrayColor:22 alpha:1];
self.searchController.searchBar.tintColor = ICON_TINT_COLOR;
[self setSearchBar:self.searchController.searchBar toDark:YES];
}
else {
dataList.delegate = self;
Expand All @@ -1179,21 +1181,12 @@ - (void)configureLibraryView {
collectionView.scrollsToTop = NO;
activeLayoutView = dataList;

// Ensure the searchController is properly attached to the dataList header view.
dataList.tableHeaderView = self.searchController.searchBar;

[self initSearchController];
self.searchController.searchBar.backgroundColor = [Utilities getSystemGray6];
self.searchController.searchBar.tintColor = [Utilities get2ndLabelColor];
[self setSearchBar:self.searchController.searchBar toDark:NO];
}
[self initIndexView];
[self buildIndexView];
[self setIndexViewVisibility];
[self setGridListButtonImage:enableCollectionView];

if (!isViewDidLoad) {
[activeLayoutView addSubview:self.searchController.searchBar];
}
}

- (void)setUpSort:(NSDictionary*)methods parameters:(NSDictionary*)parameters {
Expand Down Expand Up @@ -1318,7 +1311,7 @@ - (void)handleChangeTab:(int)newChoosedTab fromMoreItems:(BOOL)fromMoreItems {
dataList.separatorColor = [Utilities getGrayColor:38 alpha:1];
}
else {
self.searchController.searchBar.tintColor = [Utilities get2ndLabelColor];
[self setSearchBar:self.searchController.searchBar toDark:NO];
dataList.separatorColor = [Utilities getGrayColor:191 alpha:1];
}
if (methods[@"method"] != nil) {
Expand Down Expand Up @@ -1722,6 +1715,7 @@ - (void)initCollectionView {
}];
[collectionView setShowsPullToRefresh:enableDiskCache];
collectionView.alwaysBounceVertical = YES;
[collectionView addSubview:[self createFakeSearchbarInDark:YES]];
[self.view insertSubview:collectionView belowSubview:buttonsView];
}
}
Expand Down Expand Up @@ -2176,6 +2170,39 @@ - (void)choseParams { // DA OTTIMIZZARE TROPPI IF!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#pragma mark - Table Management

- (void)setSearchBar:(UISearchBar*)searchBar toDark:(BOOL)isDark {
if (isDark) {
searchBar.backgroundColor = [Utilities getGrayColor:22 alpha:1];
searchBar.tintColor = ICON_TINT_COLOR;
}
else {
searchBar.backgroundColor = [Utilities getSystemGray6];
searchBar.tintColor = [Utilities get2ndLabelColor];
}
}

- (UISearchBar*)createFakeSearchbarInDark:(BOOL)isDark {
// Create non-used search controller. This is added as tableHeaderView and lets iOS gracefully handle insets
UISearchController *searchCtrl = [[UISearchController alloc] initWithSearchResultsController:nil];
searchCtrl.searchBar.showsCancelButton = YES;
searchCtrl.searchBar.frame = self.searchController.searchBar.frame;
searchCtrl.searchBar.searchBarStyle = UISearchBarStyleMinimal;
searchCtrl.searchBar.barStyle = UIBarStyleBlack;
searchCtrl.searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self setSearchBar:searchCtrl.searchBar toDark:isDark];

// Create a transparent view on top of the unused searchbar. This receives a tap gesture to start a search.
UIView *tapOverlay = [[UIView alloc] initWithFrame:searchCtrl.searchBar.frame];
tapOverlay.backgroundColor = UIColor.clearColor;
[searchCtrl.searchBar addSubview:tapOverlay];

// Add tap gesture to create a detached search bar
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openSearchBar)];
[tapOverlay addGestureRecognizer:tapGesture];

return searchCtrl.searchBar;
}

- (void)scrollViewDidScroll:(UIScrollView*)theScrollView {
// Hide keyboard on drag
showkeyboard = NO;
Expand Down Expand Up @@ -2875,8 +2902,7 @@ - (UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)s
if (seasonIdx != NSNotFound && self.extraSectionRichResults.count > seasonIdx) {
BOOL isFirstListedSeason = [item[@"season"] intValue] == firstListedSeason;
if (isFirstListedSeason) {
self.searchController.searchBar.backgroundColor = [Utilities getSystemGray6];
self.searchController.searchBar.tintColor = [Utilities get2ndLabelColor];
[self setSearchBar:self.searchController.searchBar toDark:NO];
}

// Get show name ("genre") and season ("label")
Expand Down Expand Up @@ -5283,7 +5309,6 @@ - (void)viewDidAppear:(BOOL)animated {
self.navigationController.navigationBar.tintColor = ICON_TINT_COLOR;
}
if (isViewDidLoad) {
[activeLayoutView addSubview:self.searchController.searchBar];
[self initIpadCornerInfo];
if (globalSearchView) {
[self retrieveGlobalData:NO];
Expand Down Expand Up @@ -5535,36 +5560,41 @@ - (void)initSearchController {
self.searchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;
self.searchController.searchBar.barStyle = UIBarStyleBlack;
self.searchController.searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.searchController.searchBar setShowsCancelButton:YES animated:NO];
self.searchController.searchBar.showsCancelButton = YES;
[self.searchController.searchBar sizeToFit];
[self.searchController setActive:NO];
}

- (void)showSearchBar {
UISearchBar *searchbar = self.searchController.searchBar;
searchbar.frame = CGRectMake(0, 0, self.view.frame.size.width, searchbar.frame.size.height);
if (showbar) {
if (showSearchbar) {
[self.view addSubview:searchbar];
}
else {
[searchbar removeFromSuperview];
[activeLayoutView addSubview:searchbar];
}
}

- (void)openSearchBar {
showSearchbar = YES;
[self showSearchBar];
[self.searchController.searchBar becomeFirstResponder];
}

- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
[self showSearchBar];
viewWidth = self.view.bounds.size.width;
}

- (void)willPresentSearchController:(UISearchController*)controller {
showbar = YES;
showSearchbar = YES;
[self showSearchBar];
}

- (void)willDismissSearchController:(UISearchController*)controller {
showbar = NO;
showSearchbar = NO;
[self showSearchBar];
[self setIndexViewVisibility];
}
Expand Down Expand Up @@ -5659,6 +5689,7 @@ - (void)viewDidLoad {
self.navigationController.view.backgroundColor = UIColor.blackColor;
self.definesPresentationContext = NO;
iOSYDelta = self.searchController.searchBar.frame.size.height;
dataList.tableHeaderView = [self createFakeSearchbarInDark:NO];

if (@available(iOS 15.0, *)) {
dataList.sectionHeaderTopPadding = 0;
Expand Down