Quellcode durchsuchen

iOS: Change search bar discovery method

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
Soomin Lee vor 8 Jahren
Ursprung
Commit
a82a31c06f

+ 1 - 0
NEWS

@@ -2,6 +2,7 @@ iOS 2.8.0:
 ----------
 * Added support for NFS shares
 * Added Bonjour discovery for SMB shares
+* Improved search bar discovery method
 
 iOS 2.7.7:
 ----------

+ 9 - 19
Sources/LocalNetworkConnectivity/VLCNetworkListViewController.m

@@ -30,7 +30,6 @@ NSString *VLCNetworkListCellIdentifier = @"VLCNetworkListCellIdentifier";
 
 - (void)dealloc
 {
-    [_tapTwiceGestureRecognizer removeTarget:self action:NULL];
 }
 
 - (void)loadView
@@ -72,10 +71,8 @@ NSString *VLCNetworkListCellIdentifier = @"VLCNetworkListCellIdentifier";
     _searchDisplayController.searchResultsTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
     _searchDisplayController.searchBar.searchBarStyle = UIBarStyleBlack;
     _searchBar.delegate = self;
-    _searchBar.hidden = YES;
 
-    _tapTwiceGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(tapTwiceGestureAction:)];
-    [_tapTwiceGestureRecognizer setNumberOfTapsRequired:2];
+    self.tableView.tableHeaderView = _searchBar;
 
     self.navigationItem.rightBarButtonItems = @[[UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(menuButtonAction:)],
                                                 [UIBarButtonItem themedPlayAllButtonWithTarget:self andSelector:@selector(playAllAction:)]];
@@ -84,13 +81,19 @@ NSString *VLCNetworkListCellIdentifier = @"VLCNetworkListCellIdentifier";
     [_searchData removeAllObjects];
 }
 
+- (void)viewWillAppear:(BOOL)animated
+{
+    [super viewWillAppear:animated];
+    CGPoint contentOffset = self.tableView.contentOffset;
+    contentOffset.y += CGRectGetHeight(self.tableView.tableHeaderView.frame);
+    self.tableView.contentOffset = contentOffset;
+}
+
 - (void)viewDidAppear:(BOOL)animated {
     [super viewDidAppear:animated];
-    [self.navigationController.navigationBar addGestureRecognizer:_tapTwiceGestureRecognizer];
 }
 - (void)viewWillDisappear:(BOOL)animated {
     [super viewDidDisappear:animated];
-    [self.navigationController.navigationBar removeGestureRecognizer:_tapTwiceGestureRecognizer];
 }
 
 - (BOOL)shouldAutorotate
@@ -151,17 +154,4 @@ NSString *VLCNetworkListCellIdentifier = @"VLCNetworkListCellIdentifier";
     tableView.backgroundColor = [UIColor blackColor];
 }
 
-#pragma mark - Gesture Action
-
-- (void)tapTwiceGestureAction:(UIGestureRecognizer *)recognizer
-{
-    _searchBar.hidden = !_searchBar.hidden;
-    if (_searchBar.hidden)
-        self.tableView.tableHeaderView = nil;
-    else
-        self.tableView.tableHeaderView = _searchBar;
-
-    [self.tableView setContentOffset:CGPointMake(0.0f, -self.tableView.contentInset.top) animated:NO];
-}
-
 @end

+ 17 - 21
Sources/VLCLibraryViewController.m

@@ -60,7 +60,6 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
     BOOL _isSelected;
     BOOL _deleteFromTableView;
     UILongPressGestureRecognizer *_longPressGestureRecognizer;
-    UITapGestureRecognizer *_tapTwiceGestureRecognizer;
 
     NSMutableArray *_searchData;
     UISearchBar *_searchBar;
@@ -86,7 +85,6 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
 
 - (void)dealloc
 {
-    [_tapTwiceGestureRecognizer removeTarget:self action:NULL];
 }
 
 + (void)initialize
@@ -130,6 +128,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
             _tableView.opaque = YES;
             _tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
             _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
+            _tableView.tableHeaderView = _searchBar;
         }
         _tableView.frame = contentView.bounds;
         [contentView addSubview:_tableView];
@@ -242,11 +241,8 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
     _searchDisplayController.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
     _searchDisplayController.searchResultsTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
     _searchBar.delegate = self;
-    _searchBar.hidden = YES;
 
-    _tapTwiceGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(tapTwiceGestureAction:)];
-    [_tapTwiceGestureRecognizer setNumberOfTapsRequired:2];
-    [self.navigationController.navigationBar addGestureRecognizer:_tapTwiceGestureRecognizer];
+    [self setSearchBar:YES resetContent:YES];
 
     @synchronized (self) {
         _searchData = [[NSMutableArray alloc] init];
@@ -492,6 +488,17 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
     [self updateViewsForCurrentDisplayMode];
 }
 
+- (void)setSearchBar:(BOOL)enable resetContent:(BOOL)resetContent
+{
+    self.tableView.tableHeaderView = enable ? _searchBar : nil;
+
+    if (resetContent) {
+        CGPoint contentOffset = self.tableView.contentOffset;
+        contentOffset.y += CGRectGetHeight(self.tableView.tableHeaderView.frame);
+        self.tableView.contentOffset = contentOffset;
+    }
+}
+
 - (void)libraryUpgradeComplete
 {
     self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", nil);
@@ -811,21 +818,6 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
     [cell showMetadata:!cell.showsMetaData];
 }
 
-- (void)tapTwiceGestureAction:(UIGestureRecognizer *)recognizer
-{
-    if (!self.usingTableViewToShowData)
-        return;
-
-    _searchBar.hidden = !_searchBar.hidden;
-
-    if (_searchBar.hidden)
-        self.tableView.tableHeaderView = nil;
-    else
-        self.tableView.tableHeaderView = _searchBar;
-
-    [self.tableView setContentOffset:CGPointMake(0.0f, -self.tableView.contentInset.top) animated:NO];
-}
-
 #pragma mark - Collection View
 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
 {
@@ -1273,6 +1265,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
         [self.navigationItem setRightBarButtonItems:editing ? [self.navigationItem.rightBarButtonItems arrayByAddingObject:_selectAllBarButtonItem] : [self.navigationItem rightBarButtonItems] animated:YES];
 
     if (self.usingTableViewToShowData) {
+        [self setSearchBar:!editing resetContent:!editing];
         self.tableView.allowsMultipleSelectionDuringEditing = editing;
         [self.tableView setEditing:editing animated:YES];
         [self.editButtonItem setTitle:editing ? NSLocalizedString(@"BUTTON_CANCEL", nil) : NSLocalizedString(@"BUTTON_EDIT", nil)];
@@ -1351,6 +1344,9 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
     toolbarItems[2] = createFolderItem;
     self.toolbarItems = toolbarItems;
     [self setLibraryMode:_previousLibraryMode];
+    if (!self.isEditing) {
+        [self setSearchBar:YES resetContent:NO];
+    }
     [self updateViewContents];
 }