Commit 35b3005d authored by Carola Nitz's avatar Carola Nitz

add searchbar to videoviewcontroller

parent 450d41c4
//
// PresentationOptionsView.swift
// VLC-iOS
//
// Created by Carola Nitz on 12/3/17.
// Copyright © 2017 VideoLAN. All rights reserved.
//
import Foundation
......@@ -8,16 +8,18 @@
import Foundation
public protocol VLCVideoControllerDelegate: class {
@objc public protocol VLCVideoControllerDelegate: class {
func videoViewControllerDidSelectMediaObject(VLCVideoViewController: VLCVideoViewController, mediaObject:NSManagedObject)
func videoViewControllerDidSelectBackbutton(VLCVideoViewController: VLCVideoViewController)
}
public class VLCVideoViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout
public class VLCVideoViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout, UISearchResultsUpdating, UISearchControllerDelegate
{
private var mediaDataSource: VLCMediaDataSource
private let cellPadding:CGFloat = 5.0
public weak var delegate: VLCVideoControllerDelegate?
private var searchController: UISearchController?
private let searchDataSource = VLCLibrarySearchDisplayDataSource()
@objc public weak var delegate: VLCVideoControllerDelegate?
@available(iOS 11.0, *)
lazy var dragAndDropManager:VLCDragAndDropManager = {
......@@ -45,10 +47,11 @@ public class VLCVideoViewController: UICollectionViewController, UICollectionVie
setupCollectionView()
setupNavigationbar()
setupSearchController()
_ = (MLMediaLibrary.sharedMediaLibrary() as AnyObject).perform(#selector(MLMediaLibrary.libraryDidAppear))
mediaDataSource.updateContents(forSelection: nil)
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
self.mediaDataSource.addAllFolders()
self.mediaDataSource.addRemainingFiles()
self.collectionView?.reloadData()
......@@ -59,6 +62,7 @@ public class VLCVideoViewController: UICollectionViewController, UICollectionVie
let playlistnib = UINib(nibName: "VLCPlaylistCollectionViewCell", bundle:nil)
collectionView?.register(playlistnib, forCellWithReuseIdentifier: VLCPlaylistCollectionViewCell.cellIdentifier())
collectionView?.backgroundColor = .white
collectionView?.alwaysBounceVertical = true
if #available(iOS 11.0, *) {
collectionView?.dragDelegate = dragAndDropManager
collectionView?.dropDelegate = dragAndDropManager
......@@ -72,15 +76,35 @@ public class VLCVideoViewController: UICollectionViewController, UICollectionVie
let attributes = [NSAttributedStringKey.foregroundColor : UIColor.white]
navigationController?.navigationBar.largeTitleTextAttributes = attributes
}
self.navigationItem.leftBarButtonItem = UIBarButtonItem.themedRevealMenuButton(withTarget: self, andSelector: #selector(revealMenu))
self.navigationItem.leftBarButtonItem = UIBarButtonItem.themedRevealMenuButton(withTarget: self, andSelector: #selector(backbutton))
}
func setupSearchController() {
searchController = UISearchController(searchResultsController: nil)
searchController?.searchResultsUpdater = self
searchController?.dimsBackgroundDuringPresentation = false
searchController?.delegate = self
if let textfield = searchController?.searchBar.value(forKey: "searchField") as? UITextField {
if let backgroundview = textfield.subviews.first {
backgroundview.backgroundColor = UIColor.white
backgroundview.layer.cornerRadius = 10;
backgroundview.clipsToBounds = true;
}
}
if #available(iOS 11.0, *) {
navigationItem.searchController = searchController
} else {
navigationItem.titleView = searchController?.searchBar
searchController?.hidesNavigationBarDuringPresentation = false
}
}
@objc func revealMenu() {
VLCSidebarController.sharedInstance().toggleSidebar()
@objc func backbutton() {
delegate?.videoViewControllerDidSelectBackbutton(VLCVideoViewController: self)
}
//MARK: - CollectionViewDelegate & DataSource
override public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
print(Int(mediaDataSource.numberOfFiles()))
return Int(mediaDataSource.numberOfFiles())
}
......@@ -121,4 +145,18 @@ public class VLCVideoViewController: UICollectionViewController, UICollectionVie
override public func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
collectionView?.collectionViewLayout.invalidateLayout()
}
//MARK: - Search
public func updateSearchResults(for searchController: UISearchController) {
searchDataSource.shouldReloadTable(forSearch: searchController.searchBar.text, searchableFiles: mediaDataSource.allObjects())
collectionView?.reloadData()
}
public func didPresentSearchController(_ searchController: UISearchController) {
collectionView?.dataSource = searchDataSource
}
public func didDismissSearchController(_ searchController: UISearchController) {
collectionView?.dataSource = self
}
}
......@@ -210,8 +210,7 @@ NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorize
// For the edit selection indicators
[[UITableView appearance] setTintColor:vlcOrange];
[[UISwitch appearance] setOnTintColor:vlcOrange];
[[UISearchBar appearance] setBarTintColor:vlcOrange];
[[UISearchBar appearance] setTintColor:[UIColor whiteColor]];
[[UISearchBar appearance] setBarTintColor:[UIColor whiteColor]];
}
- (void)dealloc
......
......@@ -10,7 +10,7 @@
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
@interface VLCLibrarySearchDisplayDataSource : NSObject<UITableViewDataSource>
@interface VLCLibrarySearchDisplayDataSource : NSObject<UITableViewDataSource, UICollectionViewDataSource>
- (NSManagedObject *)objectAtIndex:(NSUInteger)index;
- (void)shouldReloadTableForSearchString:(NSString *)searchString searchableFiles:(NSArray *)files;
......
......@@ -12,6 +12,7 @@
#import "VLCLibrarySearchDisplayDataSource.h"
#import "VLCPlaylistTableViewCell.h"
#import "VLCPlaylistCollectionViewCell.h"
@interface VLCLibrarySearchDisplayDataSource() <UITableViewDataSource>
{
......@@ -47,6 +48,21 @@
return cell;
}
- (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
VLCPlaylistCollectionViewCell *cell = (VLCPlaylistCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:kPlaylistCellIdentifier forIndexPath:indexPath];
NSInteger row = indexPath.row;
if (row < _searchData.count)
cell.mediaObject = _searchData[row];
return cell;
}
- (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return _searchData.count;
}
- (NSManagedObject *)objectAtIndex:(NSUInteger)index
{
return index < _searchData.count ? _searchData[index] : nil;
......
......@@ -40,7 +40,7 @@
static NSString *CellIdentifier = @"VLCMenuCell";
static NSString *WiFiCellIdentifier = @"VLCMenuWiFiCell";
@interface VLCMenuTableViewController () <UITableViewDataSource, UITableViewDelegate>
@interface VLCMenuTableViewController () <UITableViewDataSource, UITableViewDelegate, VLCVideoControllerDelegate>
{
NSArray *_sectionHeaderTexts;
NSArray *_menuItemsSectionOne;
......@@ -234,8 +234,9 @@ static NSString *WiFiCellIdentifier = @"VLCMenuWiFiCell";
- (VLCVideoViewController *)videoViewController
{
if (!_videoViewController){
if (!_videoViewController) {
_videoViewController = [[VLCVideoViewController alloc] initWithCollectionViewLayout:[UICollectionViewFlowLayout new]];
_videoViewController.delegate = self;
}
return _videoViewController;
}
......@@ -298,5 +299,14 @@ static NSString *WiFiCellIdentifier = @"VLCMenuWiFiCell";
if (motion == UIEventSubtypeMotionShake)
[[VLCBugreporter sharedInstance] handleBugreportRequest];
}
#pragma mark - VLCVideoControllerDelegate
- (void)videoViewControllerDidSelectMediaObjectWithVLCVideoViewController:(VLCVideoViewController *)VLCVideoViewController mediaObject:(NSManagedObject *)mediaObject
{
}
- (void)videoViewControllerDidSelectBackbuttonWithVLCVideoViewController:(VLCVideoViewController *)VLCVideoViewController {
[[VLCSidebarController sharedInstance] toggleSidebar];
}
@end
......@@ -138,7 +138,7 @@ static NSString *const VLCPlayerDisplayControllerDisplayModeKey = @"VLCPlayerDis
#else
_movieViewController = [[VLCFullscreenMovieTVViewController alloc] initWithNibName:nil bundle:nil];
#endif
[VLCPlaybackController sharedInstance].delegate = _movieViewController;
self.playbackController.delegate = _movieViewController;
}
return _movieViewController;
}
......@@ -150,8 +150,7 @@ static NSString *const VLCPlayerDisplayControllerDisplayModeKey = @"VLCPlayerDis
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL enforceFullscreen = [[defaults objectForKey:kVLCSettingVideoFullscreenPlayback] boolValue];
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
if (vpc.fullscreenSessionRequested && enforceFullscreen) {
if (self.playbackController.fullscreenSessionRequested && enforceFullscreen) {
[self showFullscreenPlayback];
return;
}
......
......@@ -12,3 +12,4 @@
#import "UIBarButtonItem+Theme.h"
#import "VLCSidebarController.h"
#import "VLCPlayerDisplayController.h"
#import "VLCLibrarySearchDisplayDataSource.h"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment