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

Commit

Permalink
Version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
张国晔 committed Apr 20, 2014
0 parents commit 3359253
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
*.deb
obj/
_/
*theos
1 change: 1 addition & 0 deletions CellularUsageOrder.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ Filter = { Bundles = ( "com.apple.preferences-framework" ); }; }
5 changes: 5 additions & 0 deletions Entry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@interface Entry : NSObject
@property(nonatomic) NSInteger index;
@property(strong, nonatomic) NSNumber *data;
- (id)initWithIndex:(NSInteger)index data:(NSNumber *)data;
@end
9 changes: 9 additions & 0 deletions Entry.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#import "Entry.h"

@implementation Entry
- (id)initWithIndex:(NSInteger)index data:(NSNumber *)data {
self.index = index;
self.data = data;
return self;
}
@end
23 changes: 23 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright (c) 2014, 张国晔
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ARCHS = armv7 armv7s arm64
TARGET = iphone:clang:7.1:7.0

include theos/makefiles/common.mk

TWEAK_NAME = CellularUsageOrder
CellularUsageOrder_FILES = Tweak.x Entry.m

include $(THEOS_MAKE_PATH)/tweak.mk
ADDITIONAL_OBJCFLAGS = -fobjc-arc

after-install::
install.exec "killall -9 Preferences"
14 changes: 14 additions & 0 deletions Tweak.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#import "Entry.h"

@interface PSSpecifier
@property(strong, nonatomic) NSString *identifier;
@end

@interface PSListController
- (PSSpecifier *)specifier;
- (NSInteger)numberOfSectionsInTableView:(id)view;
- (id)tableView:(id)view cellForRowAtIndexPath:(NSIndexPath *)indexPath;
@end

@interface PSSubtitleSwitchTableCell
@end
49 changes: 49 additions & 0 deletions Tweak.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#import "Tweak.h"

%hook PSListController

NSArray *map;
NSInteger count = 0;

- (NSInteger)tableView:(id)view numberOfRowsInSection:(NSInteger)section {
NSInteger result = %orig(view, section);
if ([[self specifier].identifier isEqualToString:@"MOBILE_DATA_SETTINGS_ID"] && section == [self numberOfSectionsInTableView:view] - 2) {
count = 0;
if (result > 1) {
NSInteger num;
if ([[self tableView:view cellForRowAtIndexPath:[NSIndexPath indexPathForRow:result - 2 inSection:section]] isKindOfClass:[%c(PSSubtitleSwitchTableCell) class]])
num = result - 1;
else
num = result - 2;
NSMutableArray *data = [NSMutableArray arrayWithCapacity:num];
for (NSInteger i = 0; i < num; i++) {
NSString *size = [[(UITableViewCell *)[self tableView:view cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:section]] detailTextLabel] text];
NSArray *parts = [size componentsSeparatedByString:@" "];
if ([parts count] == 2)
[data addObject:[[Entry alloc] initWithIndex:i data:@([parts[0] floatValue] * [@{@"KB": @1, @"MB": @1000, @"GB": @1000000, @"TB": @1000000000}[parts[1]] intValue])]];
else
[data addObject:[[Entry alloc] initWithIndex:i data:@0]];
}
map = [data sortedArrayUsingComparator:^NSComparisonResult(Entry *a, Entry *b) {
return [b.data compare: a.data];
}];
count = num;
}
}
return result;
}

- (id)tableView:(id)view cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row < count && [[self specifier].identifier isEqualToString:@"MOBILE_DATA_SETTINGS_ID"] && indexPath.section == [self numberOfSectionsInTableView:view] - 2)
return %orig(view, [NSIndexPath indexPathForRow:((Entry *)map[indexPath.row]).index inSection:indexPath.section]);
else
return %orig(view, indexPath);
}

- (void)viewWillDisappear:(BOOL)animated {
%orig(animated);
map = nil;
count = 0;
}

%end
1 change: 1 addition & 0 deletions Tweak.x
8 changes: 8 additions & 0 deletions control
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Package: com.ccdog.cellularusageorder
Name: CellularUsageOrder
Depends: firmware (>= 7.0), mobilesubstrate
Version: 1.0
Architecture: iphoneos-arm
Description: Order Cellular Data Usage by Size.
Author: CC-Dog <[email protected]>
Section: Tweaks

0 comments on commit 3359253

Please sign in to comment.