]> git.saurik.com Git - cydia.git/commitdiff
Move -init into -loadView -viewDidLoad and friends, as Apple wants. Add -navigationUR...
authorGrant Paul <chpwn@chpwn.com>
Sat, 12 Feb 2011 07:27:43 +0000 (23:27 -0800)
committerGrant Paul <chpwn@chpwn.com>
Sat, 12 Feb 2011 07:27:43 +0000 (23:27 -0800)
1  2 
MobileCydia.mm
UICaboodle/RVPage.h
UICaboodle/RVPage.mm

diff --cc MobileCydia.mm
index 17b17426c0137acf9f92576fad92c4f81553a23a,ccec42b8ab1744cffe5f23dc0ddf165ffaf34f57..bb01abd54eb25d8e79e1ad4638ce3fc0f7adaa03
@@@ -5504,11 -5544,11 +5541,16 @@@ bool DepSubstrate(const pkgCache::VerIt
  }
  #endif
  
++- (void) viewWillAppear:(BOOL)animated {
++    if (![self hasLoaded])
++        [self loadURL:[NSURL URLWithString:CydiaURL(@"ui/package/")]];
++    [super viewWillAppear:animated];
++}
++
  - (id) initWithDatabase:(Database *)database {
      if ((self = [super init]) != nil) {
          database_ = database;
          buttons_ = [[NSMutableArray alloc] initWithCapacity:4];
-         [self loadURL:[NSURL URLWithString:CydiaURL(@"ui/package/")]];
 -        [self loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"package" ofType:@"html"]]];
      } return self;
  }
  
  }
  
  - (void) reloadData {
++    [super reloadData];
++
      [self setPackage:[database_ packageWithName:name_]];
  }
  
  }
  
  - (void) reloadData {
++    [super reloadData];
++
      era_ = [database_ era];
      NSArray *packages = [database_ packages];
  
  
  @implementation HomeController
  
--+ (BOOL)shouldHideNavigationBar {
+++ (BOOL) shouldHideNavigationBar {
      return NO;
  }
  
      [alert show];
  }
  
--- (void) viewWillAppear:(BOOL)animated {
--    [super viewWillAppear:animated];
--
--    if ([[self class] shouldHideNavigationBar])
--        [[self navigationController] setNavigationBarHidden:YES animated:animated];
--}
--
  - (void) viewWillDisappear:(BOOL)animated {
      [super viewWillDisappear:animated];
  
          [[self navigationController] setNavigationBarHidden:NO animated:animated];
  }
  
--- (id) init {
--    if ((self = [super init]) != nil) {
 -        [self loadURL:[NSURL URLWithString:CydiaURL(@"")]];
++- (void) viewWillAppear:(BOOL)animated {
++    if (![self hasLoaded])
 +        [self loadURL:[NSURL URLWithString:CydiaURL(@"ui/home/")]];
  
--        [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
--            initWithTitle:UCLocalize("ABOUT")
--            style:UIBarButtonItemStylePlain
--            target:self
--            action:@selector(aboutButtonClicked)
--        ] autorelease]];
--    } return self;
++    [super viewWillAppear:animated];
++
++    if ([[self class] shouldHideNavigationBar])
++        [[self navigationController] setNavigationBarHidden:YES animated:animated];
++}
++
++- (void) viewDidLoad {
++    [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
++        initWithTitle:UCLocalize("ABOUT")
++        style:UIBarButtonItemStylePlain
++        target:self
++        action:@selector(aboutButtonClicked)
++    ] autorelease]];
  }
  
  @end
  
  @implementation ManageController
  
- - (id) init {
-     if ((self = [super init]) != nil) {
-         [[self navigationItem] setTitle:UCLocalize("MANAGE")];
+ - (NSURL *) navigationURL {
+     return [NSURL URLWithString:@"cydia://manage"];
+ }
  
 -- (id) init {
 -    if ((self = [super init]) != nil) {
 -        [[self navigationItem] setTitle:UCLocalize("MANAGE")];
++- (void) viewWillAppear:(BOOL)animated {
++    if (![self hasLoaded])
 +        [self loadURL:[NSURL URLWithString:CydiaURL(@"ui/manage/")]];
  
-         [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
-             initWithTitle:UCLocalize("SETTINGS")
-             style:UIBarButtonItemStylePlain
-             target:self
-             action:@selector(settingsButtonClicked)
-         ] autorelease]];
 -        [self loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"manage" ofType:@"html"]]];
++    [super viewWillAppear:animated];
++}
  
-         [self queueStatusDidChange];
-     } return self;
 -        [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
 -            initWithTitle:UCLocalize("SETTINGS")
 -            style:UIBarButtonItemStylePlain
 -            target:self
 -            action:@selector(settingsButtonClicked)
 -        ] autorelease]];
++- (void) viewDidLoad {
++    [[self navigationItem] setTitle:UCLocalize("MANAGE")];
 -        [self queueStatusDidChange];
 -    } return self;
++    [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
++        initWithTitle:UCLocalize("SETTINGS")
++        style:UIBarButtonItemStylePlain
++        target:self
++        action:@selector(settingsButtonClicked)
++    ] autorelease]];
++
++    [self queueStatusDidChange];
  }
  
  - (void) settingsButtonClicked {
  }
  
  - (void) applyLoadingTitle {
--    // No "Loading" title.
++    // Disable "Loading" title.
  }
  
  - (void) applyRightButton {
--    // No right button.
++    // Disable right button.
  }
  #endif
  
  }
  
  - (bool) isLoading {
++    // Never show as loading.
      return false;
  }
  
      id root_;
  }
  
 -- (NSArray *) navigationURLItems;
++- (NSArray *) navigationURLCollection;
  - (void) dropBar:(BOOL)animated;
  - (void) beginUpdate;
  - (void) raiseBar:(BOOL)animated;
  
  @implementation CYTabBarController
  
- - (void) reloadData {
-     size_t count([[self viewControllers] count]);
-     for (size_t i(0); i != count; ++i) {
-         CYNavigationController *page([[self viewControllers] objectAtIndex:(count - i - 1)]);
-         [page reloadData];
 -- (NSArray *) navigationURLItems {
++- (NSArray *) navigationURLCollection {
+     NSMutableArray *items([NSMutableArray array]);
 -    // XXX:Deal with transient view controllers.
++    // XXX: Should this deal with transient view controllers?
+     for (id navigation in [self viewControllers]) {
 -        NSArray *stack = [navigation performSelector:@selector(navigationURLStack)];
++        NSArray *stack = [navigation performSelector:@selector(navigationURLCollection)];
+         if (stack != nil)
+             [items addObject:stack];
      }
  
 -    size_t count([[self viewControllers] count]);
 -    for (size_t i(0); i != count; ++i) {
 -        CYNavigationController *page([[self viewControllers] objectAtIndex:(count - i - 1)]);
 -        [page reloadData];
 -    }
+     return items;
+ }
+ - (void) reloadData {
++    for (CYViewController *controller in [self viewControllers])
++        [controller reloadData];
      [(CYNavigationController *)[self transientViewController] reloadData];
  }
  
++- (void) dealloc {
++    [refreshbar_ release];
++    [[NSNotificationCenter defaultCenter] removeObserver:self];
++
++    [super dealloc];
++}
++
  - (id) initWithDatabase:(Database *)database {
      if ((self = [super init]) != nil) {
          database_ = database;
      }
  }
  
--- (void) dealloc {
--    [refreshbar_ release];
--    [[NSNotificationCenter defaultCenter] removeObserver:self];
--    [super dealloc];
--}
--
  @end
  /* }}} */
  /* Cydia Navigation Controller {{{ */
      _transient id<UINavigationControllerDelegate> delegate_;
  }
  
 -- (NSArray *) navigationURLStack;
++- (NSArray *) navigationURLCollection;
  - (id) initWithDatabase:(Database *)database;
  - (void) reloadData;
  
      [super dealloc];
  }
  
 -- (NSArray *) navigationURLStack {
++- (NSArray *) navigationURLCollection {
+     NSMutableArray *stack([NSMutableArray array]);
+     for (CYViewController *controller in [self viewControllers]) {
+         NSString *url = [[controller navigationURL] absoluteString];
+         if (url != nil)
+             [stack addObject:url];
+     }
+     return stack;
+ }
  - (void) reloadData {
--    size_t count([[self viewControllers] count]);
--    for (size_t i(0); i != count; ++i) {
--        CYViewController *page([[self viewControllers] objectAtIndex:(count - i - 1)]);
--        [page reloadData];
++    for (CYViewController *page in [self viewControllers]) {
++        if ([page hasLoaded])
++            [page reloadData];
      }
  }
  
  /* }}} */
  
  /* Section Controller {{{ */
 -@interface SectionController : FilteredPackageController {
 +@interface SectionController : FilteredPackageListController {
+     NSString *section_;
  }
  
  - (id) initWithDatabase:(Database *)database section:(NSString *)section;
      }
  }
  
++- (BOOL) isEditing {
++    return editing_;
++}
++
  - (void) setEditing:(BOOL)editing {
      if ((editing_ = editing))
          [list_ reloadData];
  - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      static NSString *reuseIdentifier = @"SectionCell";
  
--    SectionCell *cell = (SectionCell *) [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
++    SectionCell *cell = (SectionCell *)[tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
      if (cell == nil)
          cell = [[[SectionCell alloc] initWithFrame:CGRectZero reuseIdentifier:reuseIdentifier] autorelease];
  
      [super dealloc];
  }
  
+ - (NSURL *) navigationURL {
+     return [NSURL URLWithString:@"cydia://changes"];
+ }
++- (void) viewWillAppear:(BOOL)animated {
++    // Loads after it appears, so don't load beforehand.
++    loaded_ = YES;
++    [super viewWillAppear:animated];
++}
++
  - (void) viewDidAppear:(BOOL)animated {
      [super viewDidAppear:animated];
      if (!hasSentFirstLoad_) {
          hasSentFirstLoad_ = YES;
          [self performSelector:@selector(reloadData) withObject:nil afterDelay:0.0];
  - (id) initWithDatabase:(Database *)database {
      if ((self = [super init]) != nil) {
          database_ = database;
-         [[self navigationItem] setTitle:UCLocalize("CHANGES")];
  
 -        // We load after the view is visible, so don't "magically" load beforehand.
 -        loaded_ = YES;
 -
          packages_ = CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL);
          sections_ = [[NSMutableArray arrayWithCapacity:16] retain];
-         list_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain];
-         [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
-         [list_ setRowHeight:73];
-         [[self view] addSubview:list_];
-         [list_ setDataSource:self];
-         [list_ setDelegate:self];
      } return self;
  }
  
      [super dealloc];
  }
  
 -    return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://search/%@", [search_ text]]];
+ - (NSURL *) navigationURL {
++    if ([search_ text] == nil || [[search_ text] isEqualToString:@""])
++        return [NSURL URLWithString:@"cydia://search"];
++    else
++        return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://search/%@", [search_ text]]];
+ }
  - (void) setSearchTerm:(NSString *)searchTerm {
      [search_ setText:searchTerm];
+     [self reloadData];
  }
  
  - (void) searchBarSearchButtonClicked:(UISearchBar *)searchBar {
      }
  }
  
- - (void) _reloadData {
- }
  - (void) reloadData {
-     _profile(SearchController$reloadData)
-         [super reloadData];
-     _end
-     PrintTimes();
 -    [packages_ setObject:[search_ text]];
++    [self setObject:[search_ text]];
+     [super reloadData];
 -    [packages_ resetCursor];
 +    [self resetCursor];
  }
  
  - (void) didSelectPackage:(Package *)package {
      [table_ reloadData];
  }
  
--@end
--/* }}} */
--/* Signature Controller {{{ */
--@interface SignatureController : CYBrowserController {
--    _transient Database *database_;
--    NSString *package_;
--}
--
--- (id) initWithDatabase:(Database *)database package:(NSString *)package;
--
--@end
--
--@implementation SignatureController
--
--- (void) dealloc {
--    [package_ release];
--    [super dealloc];
 -}
 -
 -- (NSURL *) navigationURL {
 -    return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@/signature", package_]];
--}
--
--- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
--    // XXX: dude!
--    [super webView:view didClearWindowObject:window forFrame:frame];
--}
--
--- (id) initWithDatabase:(Database *)database package:(NSString *)package {
--    if ((self = [super init]) != nil) {
--        database_ = database;
--        package_ = [package retain];
--        [self reloadData];
--    } return self;
--}
--
--- (void) reloadData {
--    [self loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"signature" ofType:@"html"]]];
--}
--
  @end
  /* }}} */
  
  @end
  /* }}} */
  /* Source Controller {{{ */
 -@interface SourceController : FilteredPackageController {
 +@interface SourceController : FilteredPackageListController {
+     Source *source_;
  }
  
  - (id) initWithDatabase:(Database *)database source:(Source *)source;
      if (recently || loaded_ || ManualRefresh) {
          [self performSelectorOnMainThread:@selector(_loaded) withObject:nil waitUntilDone:NO];
  
--        // If we are cancelling due to ManualRefresh or a recent refresh
--        // we need to make sure it knows it's already loaded.
++        // If we are cancelling, we need to make sure it knows it's already loaded.
          loaded_ = true;
          return;
      } else {
          if ([base isEqualToString:@"package"]) {
              if ([arg2 isEqualToString:@"settings"]) {
                  controller = [[[PackageSettingsController alloc] initWithDatabase:database_ package:arg1] autorelease];
--            } else if ([arg2 isEqualToString:@"signature"]) {
--                controller = [[[SignatureController alloc] initWithDatabase:database_ package:arg1] autorelease];
              } else if ([arg2 isEqualToString:@"files"]) {
                  if (Package *package = [database_ packageWithName:arg1]) {
                      controller = [[[FileTable alloc] initWithDatabase:database_] autorelease];
          [super applicationWillResignActive:application];
  }
  
 -    [Metadata_ setObject:[tabbar_ navigationURLItems] forKey:@"InterfaceState"];
+ - (void) applicationWillTerminate:(UIApplication *)application {
++    Changed_ = true;
++    [Metadata_ setObject:[tabbar_ navigationURLCollection] forKey:@"InterfaceState"];
+     [Metadata_ setObject:[NSDate date] forKey:@"LastClosed"];
+     [Metadata_ setObject:[NSNumber numberWithInt:[tabbar_ selectedIndex]] forKey:@"InterfaceIndex"];
+     [self _saveConfig];
+ }
  - (void) addStashController {
      ++locked_;
      stash_ = [[StashController alloc] init];
index 1f39428a8d5a6ded7d3502036a788653c9ef1392,68ffb39d6cd6669eeb5eff6817aefb8edcc267cf..5d1346e81e856815491bcc0f95713b607e5d1a96
@@@ -2,10 -2,13 +2,31 @@@
  
  #import <UIKit/UIKit.h>
  
++@interface UIViewController (Cydia)
++- (BOOL) hasLoaded;
++@end
++
  @interface CYViewController : UIViewController {
      id delegate_;
+     BOOL loaded_;
  }
- - (void)setDelegate:(id)delegate;
++
++// The default implementation of this method is essentially a no-op,
++// but calling the superclass implementation is *required*.
 +- (void) reloadData;
++// This URL is used to save the state of the view controller. Return
++// nil if you cannot or should not save the URL for this page.
+ - (NSURL *)navigationURL;
++// By default, this delegate is unused. However, it's provided here in case
++// you need some kind of delegate in a subclass.
+ - (void) setDelegate:(id)delegate;
 -- (void) reloadData;
++- (id)delegate;
++// Override this in subclasses if you manage the "has seen first load" state yourself.
++- (BOOL) hasLoaded;
++// This is called when the view managed by the view controller is released.
++// That is not always when the controller itself is released: it also can
++// happen when more memory is needed by the system or whenever the controller
++// just happens not to be visible.
+ - (void) releaseSubviews;
  @end
  
index 3e6e69277335f29a04d2e4dd1ea4df265feaba66,d3de6d31bbd7ee725108e63414bfc25a546b6f03..05a1e25b4c16e5da20d94f072bb1d0c97d79481e
@@@ -5,15 -5,40 +5,58 @@@
  
  #import "RVBook.h"
  
 +extern bool IsWildcat_;
 +
++@implementation UIViewController (Cydia)
++
++- (BOOL) hasLoaded {
++    return YES;
++}
++
++@end
++
  @implementation CYViewController
  - (void) setDelegate:(id)delegate {
      delegate_ = delegate;
  }
 -    if (!loaded_)
++- (id) delegate {
++    return delegate_;
++}
++
+ - (void) viewWillAppear:(BOOL)animated {
+     [super viewWillAppear:animated];
++    if (![self hasLoaded])
+         [self reloadData];
+ }
++- (BOOL) hasLoaded {
++    return loaded_;
++}
++
+ - (void) releaseSubviews {
+     // Do nothing.
+ }
+ - (void) setView:(UIView *)view {
+     if (view == nil)
+         [self releaseSubviews];
+     [super setView:view];
+ }
  - (void) reloadData {
+     loaded_ = YES;
+ }
+ - (NSURL *) navigationURL {
+     return nil;
  }
  - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
 -    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad || orientation == UIInterfaceOrientationPortrait);
 +    return IsWildcat_ || orientation == UIInterfaceOrientationPortrait;
  }
  @end