Commit 890f21be authored by Tobias's avatar Tobias

the info panel container controller doesn't need to know the specifics when an...

the info panel container controller doesn't need to know the specifics when an info panel should be visible or not instead the classes of the different info panels know best if that info panel shouldn't be visible
parent eaa42d42
......@@ -65,6 +65,12 @@
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
+ (BOOL)shouldBeVisibleForPlaybackController:(VLCPlaybackController *)vpc
{
return vpc.currentMediaHasChapters;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
......
......@@ -11,7 +11,14 @@
#import <UIKit/UIKit.h>
@interface VLCPlaybackInfoPanelTVViewController : UIViewController
@class VLCPlaybackController;
@protocol VLCPlaybackInfoPanelTVViewController <NSObject>
+ (BOOL)shouldBeVisibleForPlaybackController:(VLCPlaybackController *)vpc;
@end
@interface VLCPlaybackInfoPanelTVViewController : UIViewController <VLCPlaybackInfoPanelTVViewController>
// subclasses should override preferred content size to enable
......
......@@ -48,4 +48,9 @@ static inline void sharedSetup(VLCPlaybackInfoPanelTVViewController *self)
return NO;
}
+ (BOOL)shouldBeVisibleForPlaybackController:(VLCPlaybackController *)vpc
{
return YES;
}
@end
......@@ -31,6 +31,12 @@
return CGSizeMake(CGRectGetWidth(self.view.bounds), 100);
}
+ (BOOL)shouldBeVisibleForPlaybackController:(VLCPlaybackController *)vpc
{
return vpc.mediaPlayer.isSeekable;
}
- (void)viewDidLoad
{
[super viewDidLoad];
......
......@@ -24,10 +24,7 @@
@interface VLCPlaybackInfoTVViewController ()
{
VLCPlaybackInfoMediaInfoTVViewController *_mediaInfoVC;
VLCPlaybackInfoChaptersTVViewController *_chaptersVC;
VLCPlaybackInfoTracksTVViewController *_tracksVC;
VLCPlaybackInfoRateTVViewController *_rateVC;
NSArray<UIViewController<VLCPlaybackInfoPanelTVViewController> *> *_allTabViewControllers;
}
@end
......@@ -36,17 +33,9 @@
- (NSArray<UIViewController*>*)tabViewControllers
{
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
NSMutableArray *vcArray = [NSMutableArray arrayWithObject:_mediaInfoVC];
if (vpc.mediaPlayer.isSeekable)
[vcArray addObject:_rateVC];
[vcArray addObject:_tracksVC];
if (vpc.currentMediaHasChapters)
[vcArray addObject:_chaptersVC];
return [vcArray copy];
return [_allTabViewControllers filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id<VLCPlaybackInfoPanelTVViewController> _Nonnull evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
return [[evaluatedObject class] shouldBeVisibleForPlaybackController:vpc];
}]];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
......@@ -64,10 +53,13 @@
[self setupTabBarItemAppearance];
_mediaInfoVC = [[VLCPlaybackInfoMediaInfoTVViewController alloc] initWithNibName:nil bundle:nil];
_chaptersVC = [[VLCPlaybackInfoChaptersTVViewController alloc] initWithNibName:nil bundle:nil];
_tracksVC = [[VLCPlaybackInfoTracksTVViewController alloc] initWithNibName:nil bundle:nil];
_rateVC = [[VLCPlaybackInfoRateTVViewController alloc] initWithNibName:nil bundle:nil];
_allTabViewControllers = @[
[[VLCPlaybackInfoMediaInfoTVViewController alloc] initWithNibName:nil bundle:nil],
[[VLCPlaybackInfoChaptersTVViewController alloc] initWithNibName:nil bundle:nil],
[[VLCPlaybackInfoTracksTVViewController alloc] initWithNibName:nil bundle:nil],
[[VLCPlaybackInfoRateTVViewController alloc] initWithNibName:nil bundle:nil],
];
UITabBarController *controller = [[VLCPlaybackInfoTVTabBarController alloc] init];
controller.delegate = self;
......@@ -87,7 +79,14 @@
- (void)viewWillAppear:(BOOL)animated
{
self.tabBarController.viewControllers = [self tabViewControllers];
UITabBarController *tabBarController = self.tabBarController;
UIViewController *oldSelectedVC = tabBarController.selectedViewController;
tabBarController.viewControllers = [self tabViewControllers];
NSUInteger newIndex = [tabBarController.viewControllers indexOfObject:oldSelectedVC];
if (newIndex == NSNotFound) {
newIndex = 0;
}
tabBarController.selectedIndex = newIndex;
[super viewWillAppear:animated];
}
......
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