]> git.saurik.com Git - cydia.git/blob - CyteKit/TabBarController.mm
Reload the appcache if suspended over ten minutes.
[cydia.git] / CyteKit / TabBarController.mm
1 /* Cydia - iPhone UIKit Front-End for Debian APT
2 * Copyright (C) 2008-2014 Jay Freeman (saurik)
3 */
4
5 /* GNU General Public License, Version 3 {{{ */
6 /*
7 * Cydia is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
11 *
12 * Cydia is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 #include "CyteKit/TabBarController.h"
23
24 #include "iPhonePrivate.h"
25
26 @implementation UITabBarController (Cydia)
27
28 @end
29
30 @implementation CyteTabBarController
31
32 - (void) didReceiveMemoryWarning {
33 [super didReceiveMemoryWarning];
34
35 // presenting a UINavigationController on 2.x does not update its transitionView
36 // it thereby will not allow its topViewController to be unloaded by memory pressure
37 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
38 UIViewController *selected([self selectedViewController]);
39 for (UINavigationController *controller in [self viewControllers])
40 if (controller != selected)
41 if (UIViewController *top = [controller topViewController])
42 [top unloadView];
43 }
44 }
45
46 - (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
47 if ([self unselectedViewController])
48 [self setUnselectedViewController:nil];
49
50 // presenting a UINavigationController on 2.x does not update its transitionView
51 // if this view was unloaded, the tranitionView may currently be presenting nothing
52 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
53 UINavigationController *navigation((UINavigationController *) viewController);
54 [navigation pushViewController:[[[UIViewController alloc] init] autorelease] animated:NO];
55 [navigation popViewControllerAnimated:NO];
56 }
57 }
58
59 - (void) dismissModalViewControllerAnimated:(BOOL)animated {
60 if ([self modalViewController] == nil && [self unselectedViewController] != nil)
61 [self setUnselectedViewController:nil];
62 else
63 [super dismissModalViewControllerAnimated:YES];
64 }
65
66 - (void) setUnselectedViewController:(UIViewController *)transient {
67 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
68 if (transient != nil) {
69 [[[self viewControllers] objectAtIndex:0] pushViewController:transient animated:YES];
70 [self setSelectedIndex:0];
71 } return;
72 }
73
74 NSMutableArray *controllers = [[[self viewControllers] mutableCopy] autorelease];
75 if (transient != nil) {
76 UINavigationController *navigation([[[UINavigationController alloc] init] autorelease]);
77 [navigation setViewControllers:[NSArray arrayWithObject:transient]];
78 transient = navigation;
79
80 if (transient_ == nil)
81 remembered_ = [controllers objectAtIndex:0];
82 transient_ = transient;
83 [transient_ setTabBarItem:[remembered_ tabBarItem]];
84 [controllers replaceObjectAtIndex:0 withObject:transient_];
85 [self setSelectedIndex:0];
86 [self setViewControllers:controllers];
87 [self concealTabBarSelection];
88 } else if (remembered_ != nil) {
89 [remembered_ setTabBarItem:[transient_ tabBarItem]];
90 transient_ = transient;
91 [controllers replaceObjectAtIndex:0 withObject:remembered_];
92 remembered_ = nil;
93 [self setViewControllers:controllers];
94 [self revealTabBarSelection];
95 }
96 }
97
98 - (UIViewController *) unselectedViewController {
99 return transient_;
100 }
101
102 - (void) unloadData {
103 [super unloadData];
104
105 for (UINavigationController *controller in [self viewControllers])
106 [controller unloadData];
107
108 if (UIViewController *selected = [self selectedViewController])
109 [selected reloadData];
110
111 if (UIViewController *unselected = [self unselectedViewController]) {
112 [unselected unloadData];
113 [unselected reloadData];
114 }
115 }
116
117 @end