diff options
author | Jay Freeman (saurik) <saurik@saurik.com> | 2014-05-25 05:05:27 -0700 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2014-05-25 05:05:27 -0700 |
commit | 98ddcefda3a904d30ac6342beb783843fb801db6 (patch) | |
tree | 40e93bce3934eb777fd93307bc096c7b97ae1ce4 /MobileCydia.mm | |
parent | 5af08e16fe0433b9618892fa5a13b0992555ba3e (diff) |
Add the day as section header to Installed/Recent.
Diffstat (limited to 'MobileCydia.mm')
-rw-r--r-- | MobileCydia.mm | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm index df0c131..a4d462c 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -3132,7 +3132,11 @@ struct PackageNameOrdering : return source_ == (Source *) [NSNull null] ? nil : source_; } -- (uint32_t) updated { +- (time_t) updated { + return updated_; +} + +- (uint32_t) updatedRadix { return std::numeric_limits<uint32_t>::max() - updated_; } @@ -7948,10 +7952,6 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi return [NSURL URLWithString:@"cydia://installed"]; } -- (bool) showsSections { - return sectioned_; -} - - (void) useUpdated { sectioned_ = false; @@ -7961,7 +7961,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi }]; [self setSorter:[](NSMutableArray *packages) { - [packages radixSortUsingSelector:@selector(updated)]; + [packages radixSortUsingSelector:@selector(updatedRadix)]; }]; } } @@ -7980,6 +7980,42 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi [self setSorter:nullptr]; } } +- (NSArray *) sectionsForPackages:(NSMutableArray *)packages { + if (sectioned_) + return [super sectionsForPackages:packages]; + + CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, Locale_, kCFDateFormatterLongStyle, kCFDateFormatterNoStyle)); + + NSMutableArray *sections([NSMutableArray arrayWithCapacity:16]); + + Section *section; + + time_t last(0); + + for (size_t offset(0), count([packages count]); offset != count; ++offset) { + Package *package([packages objectAtIndex:offset]); + + time_t updated([package updated]); + updated -= updated % (60 * 60 * 24); + + if (updated != last) { + last = updated; + + NSString *name; + name = (NSString *) CFDateFormatterCreateStringWithDate(NULL, formatter, (CFDateRef) [NSDate dateWithTimeIntervalSince1970:updated]); + [name autorelease]; + + section = [[[Section alloc] initWithName:name row:offset localize:NO] autorelease]; + [sections addObject:section]; + } + + [section addToCount]; + } + + CFRelease(formatter); + return sections; +} + - (id) initWithDatabase:(Database *)database { if ((self = [super initWithDatabase:database title:UCLocalize("INSTALLED")]) != nil) { UISegmentedControl *segmented([[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:UCLocalize("USER"), UCLocalize("EXPERT"), UCLocalize("RECENT"), nil]] autorelease]); |