diff options
author | Jay Freeman (saurik) <saurik@saurik.com> | 2017-02-15 10:29:44 -0800 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2017-02-15 10:29:44 -0800 |
commit | 7ccc1484ab74ebf5797820bdd24edccfd42aaa50 (patch) | |
tree | 6bf6278957d2ff267d8685fb863c4d4da61e4056 /CyteKit | |
parent | f8c9fd4c9a853ca14ac1d1fb123e2e6200879bb4 (diff) |
Move some of our clearly shared code into CyteKit.
Diffstat (limited to 'CyteKit')
-rw-r--r-- | CyteKit/Application.h | 33 | ||||
-rw-r--r-- | CyteKit/Application.mm | 60 | ||||
-rw-r--r-- | CyteKit/NavigationController.h | 34 | ||||
-rw-r--r-- | CyteKit/NavigationController.mm | 71 | ||||
-rw-r--r-- | CyteKit/TabBarController.h | 1 | ||||
-rw-r--r-- | CyteKit/TabBarController.mm | 13 | ||||
-rw-r--r-- | CyteKit/ViewController.h | 17 | ||||
-rw-r--r-- | CyteKit/ViewController.mm | 8 |
8 files changed, 224 insertions, 13 deletions
diff --git a/CyteKit/Application.h b/CyteKit/Application.h new file mode 100644 index 0000000..d95ad1c --- /dev/null +++ b/CyteKit/Application.h @@ -0,0 +1,33 @@ +/* Cydia - iPhone UIKit Front-End for Debian APT + * Copyright (C) 2008-2015 Jay Freeman (saurik) +*/ + +/* GNU General Public License, Version 3 {{{ */ +/* + * Cydia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * Cydia is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cydia. If not, see <http://www.gnu.org/licenses/>. +**/ +/* }}} */ + +#ifndef CyteKit_Application_H +#define CyteKit_Application_H + +#include <UIKit/UIKit.h> + +@interface CyteApplication : UIApplication + +- (void) applicationDidFinishLaunching:(id)unused; + +@end + +#endif//CyteKit_Application_H diff --git a/CyteKit/Application.mm b/CyteKit/Application.mm new file mode 100644 index 0000000..d1d6142 --- /dev/null +++ b/CyteKit/Application.mm @@ -0,0 +1,60 @@ +/* Cydia - iPhone UIKit Front-End for Debian APT + * Copyright (C) 2008-2015 Jay Freeman (saurik) +*/ + +/* GNU General Public License, Version 3 {{{ */ +/* + * Cydia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * Cydia is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cydia. If not, see <http://www.gnu.org/licenses/>. +**/ +/* }}} */ + +#include "CyteKit/UCPlatform.h" + +#include <Foundation/Foundation.h> +#include <UIKit/UIKit.h> + +#include "iPhonePrivate.h" +#include <Menes/ObjectHandle.h> + +@implementation CyteApplication : UIApplication { +} + +- (void) _sendMemoryWarningNotification { + if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) // XXX: maybe 4_0? + [[NSNotificationCenter defaultCenter] postNotificationName:@"UIApplicationMemoryWarningNotification" object:[UIApplication sharedApplication]]; + else + [[NSNotificationCenter defaultCenter] postNotificationName:@"UIApplicationDidReceiveMemoryWarningNotification" object:[UIApplication sharedApplication]]; +} + +- (void) _sendMemoryWarningNotifications { + while (true) { + [self performSelectorOnMainThread:@selector(_sendMemoryWarningNotification) withObject:nil waitUntilDone:NO]; + sleep(2); + //usleep(2000000); + } +} + +- (void) applicationDidReceiveMemoryWarning:(UIApplication *)application { + NSLog(@"--"); + [[NSURLCache sharedURLCache] removeAllCachedResponses]; +} + +- (void) applicationDidFinishLaunching:(id)unused { + //[NSThread detachNewThreadSelector:@selector(_sendMemoryWarningNotifications) toTarget:self withObject:nil]; + + if ([self respondsToSelector:@selector(setApplicationSupportsShakeToEdit:)]) + [self setApplicationSupportsShakeToEdit:NO]; +} + +@end diff --git a/CyteKit/NavigationController.h b/CyteKit/NavigationController.h new file mode 100644 index 0000000..b295858 --- /dev/null +++ b/CyteKit/NavigationController.h @@ -0,0 +1,34 @@ +/* Cydia - iPhone UIKit Front-End for Debian APT + * Copyright (C) 2008-2015 Jay Freeman (saurik) +*/ + +/* GNU General Public License, Version 3 {{{ */ +/* + * Cydia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * Cydia is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cydia. If not, see <http://www.gnu.org/licenses/>. +**/ +/* }}} */ + +#ifndef CyteKit_NavigationController_H +#define CyteKit_NavigationController_H + +#include <UIKit/UIKit.h> + +@interface UINavigationController (Cydia) + +- (NSArray *) navigationURLCollection; +- (void) unloadData; + +@end + +#endif//CyteKit_NavigationController_H diff --git a/CyteKit/NavigationController.mm b/CyteKit/NavigationController.mm new file mode 100644 index 0000000..f53ad85 --- /dev/null +++ b/CyteKit/NavigationController.mm @@ -0,0 +1,71 @@ +/* Cydia - iPhone UIKit Front-End for Debian APT + * Copyright (C) 2008-2015 Jay Freeman (saurik) +*/ + +/* GNU General Public License, Version 3 {{{ */ +/* + * Cydia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * Cydia is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cydia. If not, see <http://www.gnu.org/licenses/>. +**/ +/* }}} */ + +#include "CyteKit/UCPlatform.h" + +#include <Foundation/Foundation.h> +#include <UIKit/UIKit.h> + +#include "CyteKit/NavigationController.h" +#include "CyteKit/ViewController.h" + +#include "iPhonePrivate.h" +#include <Menes/ObjectHandle.h> + +@implementation UINavigationController (Cydia) + +- (NSArray *) navigationURLCollection { + NSMutableArray *stack([NSMutableArray array]); + + for (CyteViewController *controller in [self viewControllers]) { + NSString *url = [[controller navigationURL] absoluteString]; + if (url != nil) + [stack addObject:url]; + } + + return stack; +} + +- (void) reloadData { + [super reloadData]; + + UIViewController *visible([self visibleViewController]); + if (visible != nil) + [visible reloadData]; + + // on the iPad, this view controller is ALSO visible. :( + extern bool IsWildcat_; + if (IsWildcat_) + if (UIViewController *modal = [self modalViewController]) + if ([modal modalPresentationStyle] == UIModalPresentationFormSheet) + if (UIViewController *top = [self topViewController]) + if (top != visible) + [top reloadData]; +} + +- (void) unloadData { + for (CyteViewController *page in [self viewControllers]) + [page unloadData]; + + [super unloadData]; +} + +@end diff --git a/CyteKit/TabBarController.h b/CyteKit/TabBarController.h index 7aee767..2aa403c 100644 --- a/CyteKit/TabBarController.h +++ b/CyteKit/TabBarController.h @@ -31,6 +31,7 @@ @interface CyteTabBarController : UITabBarController +- (NSArray *) navigationURLCollection; - (UIViewController *) unselectedViewController; - (void) setUnselectedViewController:(UIViewController *)transient; diff --git a/CyteKit/TabBarController.mm b/CyteKit/TabBarController.mm index 7a4ead3..35a2bd0 100644 --- a/CyteKit/TabBarController.mm +++ b/CyteKit/TabBarController.mm @@ -35,6 +35,19 @@ _H<UIViewController> remembered_; } +- (NSArray *) navigationURLCollection { + NSMutableArray *items([NSMutableArray array]); + + // XXX: Should this deal with transient view controllers? + for (id navigation in [self viewControllers]) { + NSArray *stack = [navigation performSelector:@selector(navigationURLCollection)]; + if (stack != nil) + [items addObject:stack]; + } + + return items; +} + - (void) didReceiveMemoryWarning { [super didReceiveMemoryWarning]; diff --git a/CyteKit/ViewController.h b/CyteKit/ViewController.h index 3b637f0..156f3cb 100644 --- a/CyteKit/ViewController.h +++ b/CyteKit/ViewController.h @@ -25,13 +25,9 @@ #include <UIKit/UIKit.h> @interface UIViewController (Cydia) -- (BOOL) hasLoaded; -- (void) reloadData; -- (void) unloadData; -- (UIViewController *) parentOrPresentingViewController; -@end -@interface CyteViewController : UIViewController +// Override this in subclasses if you manage the "has seen first load" state yourself. +- (BOOL) hasLoaded; // The default implementation of this method is essentially a no-op, // but calling the superclass implementation is *required*. @@ -39,18 +35,21 @@ - (void) unloadData; +- (UIViewController *) parentOrPresentingViewController; + // 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; +@end + +@interface CyteViewController : UIViewController + // 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; - (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 diff --git a/CyteKit/ViewController.mm b/CyteKit/ViewController.mm index 52c925d..28c7c43 100644 --- a/CyteKit/ViewController.mm +++ b/CyteKit/ViewController.mm @@ -52,6 +52,10 @@ return nil; } +- (NSURL *) navigationURL { + return nil; +} + @end @implementation CyteViewController { @@ -109,10 +113,6 @@ [super unloadData]; } -- (NSURL *) navigationURL { - return nil; -} - - (void) setPageColor:(UIColor *)color { if (color == nil) color = [UIColor groupTableViewBackgroundColor]; |