Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 3359253

Browse files
author
张国晔
committed
Version 1.0
0 parents  commit 3359253

10 files changed

+128
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
*.deb
3+
obj/
4+
_/
5+
*theos

CellularUsageOrder.plist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ Filter = { Bundles = ( "com.apple.preferences-framework" ); }; }

Entry.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@interface Entry : NSObject
2+
@property(nonatomic) NSInteger index;
3+
@property(strong, nonatomic) NSNumber *data;
4+
- (id)initWithIndex:(NSInteger)index data:(NSNumber *)data;
5+
@end

Entry.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#import "Entry.h"
2+
3+
@implementation Entry
4+
- (id)initWithIndex:(NSInteger)index data:(NSNumber *)data {
5+
self.index = index;
6+
self.data = data;
7+
return self;
8+
}
9+
@end

LICENSE.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright (c) 2014, 张国晔
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright notice, this
11+
list of conditions and the following disclaimer in the documentation and/or
12+
other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
ARCHS = armv7 armv7s arm64
2+
TARGET = iphone:clang:7.1:7.0
3+
4+
include theos/makefiles/common.mk
5+
6+
TWEAK_NAME = CellularUsageOrder
7+
CellularUsageOrder_FILES = Tweak.x Entry.m
8+
9+
include $(THEOS_MAKE_PATH)/tweak.mk
10+
ADDITIONAL_OBJCFLAGS = -fobjc-arc
11+
12+
after-install::
13+
install.exec "killall -9 Preferences"

Tweak.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#import "Entry.h"
2+
3+
@interface PSSpecifier
4+
@property(strong, nonatomic) NSString *identifier;
5+
@end
6+
7+
@interface PSListController
8+
- (PSSpecifier *)specifier;
9+
- (NSInteger)numberOfSectionsInTableView:(id)view;
10+
- (id)tableView:(id)view cellForRowAtIndexPath:(NSIndexPath *)indexPath;
11+
@end
12+
13+
@interface PSSubtitleSwitchTableCell
14+
@end

Tweak.m

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#import "Tweak.h"
2+
3+
%hook PSListController
4+
5+
NSArray *map;
6+
NSInteger count = 0;
7+
8+
- (NSInteger)tableView:(id)view numberOfRowsInSection:(NSInteger)section {
9+
NSInteger result = %orig(view, section);
10+
if ([[self specifier].identifier isEqualToString:@"MOBILE_DATA_SETTINGS_ID"] && section == [self numberOfSectionsInTableView:view] - 2) {
11+
count = 0;
12+
if (result > 1) {
13+
NSInteger num;
14+
if ([[self tableView:view cellForRowAtIndexPath:[NSIndexPath indexPathForRow:result - 2 inSection:section]] isKindOfClass:[%c(PSSubtitleSwitchTableCell) class]])
15+
num = result - 1;
16+
else
17+
num = result - 2;
18+
NSMutableArray *data = [NSMutableArray arrayWithCapacity:num];
19+
for (NSInteger i = 0; i < num; i++) {
20+
NSString *size = [[(UITableViewCell *)[self tableView:view cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:section]] detailTextLabel] text];
21+
NSArray *parts = [size componentsSeparatedByString:@" "];
22+
if ([parts count] == 2)
23+
[data addObject:[[Entry alloc] initWithIndex:i data:@([parts[0] floatValue] * [@{@"KB": @1, @"MB": @1000, @"GB": @1000000, @"TB": @1000000000}[parts[1]] intValue])]];
24+
else
25+
[data addObject:[[Entry alloc] initWithIndex:i data:@0]];
26+
}
27+
map = [data sortedArrayUsingComparator:^NSComparisonResult(Entry *a, Entry *b) {
28+
return [b.data compare: a.data];
29+
}];
30+
count = num;
31+
}
32+
}
33+
return result;
34+
}
35+
36+
- (id)tableView:(id)view cellForRowAtIndexPath:(NSIndexPath *)indexPath {
37+
if (indexPath.row < count && [[self specifier].identifier isEqualToString:@"MOBILE_DATA_SETTINGS_ID"] && indexPath.section == [self numberOfSectionsInTableView:view] - 2)
38+
return %orig(view, [NSIndexPath indexPathForRow:((Entry *)map[indexPath.row]).index inSection:indexPath.section]);
39+
else
40+
return %orig(view, indexPath);
41+
}
42+
43+
- (void)viewWillDisappear:(BOOL)animated {
44+
%orig(animated);
45+
map = nil;
46+
count = 0;
47+
}
48+
49+
%end

Tweak.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Tweak.m

control

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Package: com.ccdog.cellularusageorder
2+
Name: CellularUsageOrder
3+
Depends: firmware (>= 7.0), mobilesubstrate
4+
Version: 1.0
5+
Architecture: iphoneos-arm
6+
Description: Order Cellular Data Usage by Size.
7+
Author: CC-Dog <[email protected]>
8+
Section: Tweaks

0 commit comments

Comments
 (0)