VLCBaseInterfaceController.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*****************************************************************************
  2. * VLCBaseInterfaceController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Author: Tobias Conradi <videolan # tobias-conradi.de>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. #import "VLCBaseInterfaceController.h"
  13. NSString *const VLCDBUpdateNotification = @"VLCUpdateDatabase";
  14. @interface VLCBaseInterfaceController()
  15. @property (nonatomic) BOOL needsUpdate;
  16. @end
  17. @implementation VLCBaseInterfaceController
  18. - (void)awakeWithContext:(id)context {
  19. [super awakeWithContext:context];
  20. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setNeedsUpdateData) name:VLCDBUpdateNotification object:nil];
  21. }
  22. - (void) dealloc {
  23. [[NSNotificationCenter defaultCenter] removeObserver:self name:VLCDBUpdateNotification object:nil];
  24. }
  25. - (void)addNowPlayingMenu {
  26. [self addMenuItemWithItemIcon:WKMenuItemIconMore title: NSLocalizedString(@"NOW_PLAYING", nil) action:@selector(showNowPlaying:)];
  27. }
  28. - (void)showNowPlaying:(id)sender {
  29. [self presentControllerWithName:@"nowPlaying" context:nil];
  30. }
  31. - (void)willActivate {
  32. [super willActivate];
  33. _activated = YES;
  34. [self updateDataIfNeeded];
  35. }
  36. - (void)didDeactivate {
  37. [super didDeactivate];
  38. _activated = NO;
  39. }
  40. - (void)setNeedsUpdateData
  41. {
  42. self.needsUpdate = YES;
  43. [self updateDataIfNeeded];
  44. }
  45. - (void)updateDataIfNeeded
  46. {
  47. // if not activated/visible we defer the update til activation
  48. if (self.needsUpdate && self.activated) {
  49. [self updateData];
  50. self.needsUpdate = NO;
  51. }
  52. }
  53. - (void)updateData
  54. {
  55. self.needsUpdate = NO;
  56. }
  57. @end