]> git.saurik.com Git - cydia.git/commitdiff
Add the day as section header to Installed/Recent.
authorJay Freeman (saurik) <saurik@saurik.com>
Sun, 25 May 2014 12:05:27 +0000 (05:05 -0700)
committerJay Freeman (saurik) <saurik@saurik.com>
Sun, 25 May 2014 12:05:27 +0000 (05:05 -0700)
MobileCydia.mm

index df0c131f84e3bf345d9e45d973324b9055519b87..a4d462ce874c03834edd5d3bb935b5b3807649ab 100644 (file)
@@ -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]);