From: Grant Paul Date: Sat, 12 Feb 2011 07:27:43 +0000 (-0800) Subject: Move -init into -loadView -viewDidLoad and friends, as Apple wants. Add -navigationUR... X-Git-Tag: v1.1.0%b1~367 X-Git-Url: https://git.saurik.com/cydia.git/commitdiff_plain/35f0a3b5de5a22872f7fbd96183f510a5ad80aa0 Move -init into -loadView -viewDidLoad and friends, as Apple wants. Add -navigationURL and persistance (15 minute timeout) of Cydia sessions, with full lazy-loading of view controllers. Still failed to fix the URL->blackscreen bug, although now it just shows the wrong tab instaed of a black screen (really, WTF, UITabBarController?) --- 35f0a3b5de5a22872f7fbd96183f510a5ad80aa0 diff --cc MobileCydia.mm index 17b17426,ccec42b8..bb01abd5 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@@ -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; } @@@ -5570,6 -5610,6 +5612,8 @@@ } - (void) reloadData { ++ [super reloadData]; ++ [self setPackage:[database_ packageWithName:name_]]; } @@@ -5792,6 -5760,6 +5836,8 @@@ } - (void) reloadData { ++ [super reloadData]; ++ era_ = [database_ era]; NSArray *packages = [database_ packages]; @@@ -5953,7 -6005,7 +5999,7 @@@ @implementation HomeController --+ (BOOL)shouldHideNavigationBar { +++ (BOOL) shouldHideNavigationBar { return NO; } @@@ -5985,13 -6041,13 +6035,6 @@@ [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]; @@@ -5999,17 -6055,17 +6042,23 @@@ [[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 @@@ -6023,21 -6079,25 +6072,28 @@@ @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 { @@@ -6050,11 -6110,11 +6106,11 @@@ } - (void) applyLoadingTitle { -- // No "Loading" title. ++ // Disable "Loading" title. } - (void) applyRightButton { -- // No right button. ++ // Disable right button. } #endif @@@ -6074,6 -6134,6 +6130,7 @@@ } - (bool) isLoading { ++ // Never show as loading. return false; } @@@ -6213,6 -6273,7 +6270,7 @@@ id root_; } -- (NSArray *) navigationURLItems; ++- (NSArray *) navigationURLCollection; - (void) dropBar:(BOOL)animated; - (void) beginUpdate; - (void) raiseBar:(BOOL)animated; @@@ -6222,16 -6283,29 +6280,33 @@@ @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]; } + return items; + } + + - (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]; - } ++ 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; @@@ -6456,12 -6530,12 +6531,6 @@@ } } --- (void) dealloc { -- [refreshbar_ release]; -- [[NSNotificationCenter defaultCenter] removeObserver:self]; -- [super dealloc]; --} -- @end /* }}} */ /* Cydia Navigation Controller {{{ */ @@@ -6470,6 -6544,7 +6539,7 @@@ _transient id delegate_; } -- (NSArray *) navigationURLStack; ++- (NSArray *) navigationURLCollection; - (id) initWithDatabase:(Database *)database; - (void) reloadData; @@@ -6482,11 -6557,23 +6552,22 @@@ [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]; } } @@@ -6605,7 -6692,8 +6686,8 @@@ /* }}} */ /* Section Controller {{{ */ -@interface SectionController : FilteredPackageController { +@interface SectionController : FilteredPackageListController { + NSString *section_; } - (id) initWithDatabase:(Database *)database section:(NSString *)section; @@@ -6676,6 -6773,6 +6767,10 @@@ } } ++- (BOOL) isEditing { ++ return editing_; ++} ++ - (void) setEditing:(BOOL)editing { if ((editing_ = editing)) [list_ reloadData]; @@@ -6711,7 -6808,7 +6806,7 @@@ - (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]; @@@ -6854,8 -6953,13 +6951,19 @@@ [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]; @@@ -6929,18 -7051,12 +7055,9 @@@ - (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; } @@@ -7081,8 -7198,13 +7199,16 @@@ [super dealloc]; } + - (NSURL *) navigationURL { - return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://search/%@", [search_ text]]]; ++ 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 { @@@ -7120,15 -7246,10 +7250,10 @@@ } } - - (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 { @@@ -7274,42 -7415,46 +7419,6 @@@ [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 /* }}} */ @@@ -7470,7 -7626,8 +7581,8 @@@ @end /* }}} */ /* Source Controller {{{ */ -@interface SourceController : FilteredPackageController { +@interface SourceController : FilteredPackageListController { + Source *source_; } - (id) initWithDatabase:(Database *)database source:(Source *)source; @@@ -8301,8 -8509,8 +8464,7 @@@ 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 { @@@ -8813,8 -9001,8 +8949,6 @@@ 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]; @@@ -8856,6 -9044,14 +8990,15 @@@ [super applicationWillResignActive:application]; } + - (void) applicationWillTerminate:(UIApplication *)application { - [Metadata_ setObject:[tabbar_ navigationURLItems] forKey:@"InterfaceState"]; ++ 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]; diff --cc UICaboodle/RVPage.h index 1f39428a,68ffb39d..5d1346e8 --- a/UICaboodle/RVPage.h +++ b/UICaboodle/RVPage.h @@@ -2,10 -2,13 +2,31 @@@ #import ++@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 diff --cc UICaboodle/RVPage.mm index 3e6e6927,d3de6d31..05a1e25b --- a/UICaboodle/RVPage.mm +++ b/UICaboodle/RVPage.mm @@@ -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; } + ++- (id) delegate { ++ return delegate_; ++} ++ + - (void) viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + - if (!loaded_) ++ 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