-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSWCellularWidgetView.m
More file actions
68 lines (56 loc) · 2.75 KB
/
SWCellularWidgetView.m
File metadata and controls
68 lines (56 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#import "SWCellularWidgetView.h"
#import <objc/runtime.h>
#import <math.h>
#import "utils.h"
@interface PSUICellularPlanManagerCache : NSObject
+(id)sharedInstance;
-(NSArray *)planItems;
-(BOOL)isAirplaneModeEnabled;
@end
static inline float BtoGB(unsigned long long bytes) {
return (float)bytes / 1024 / 1024 / 1024;
}
@implementation SWCellularWidgetView
-(NSString *)iconImage {
return @"cellularicon";
}
-(NSString *)widgetHeaderLocalizationString {
return @"CELLULAR_WIDGET_HEADER";
}
-(NSString *)prefsURL {
return @"prefs:root=MOBILE_DATA_SETTINGS_ID";
}
-(void)setup {
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateForDataReceived:) name:@"SWCellularDataProcessedNotification" object:nil];
[super setup];
}
-(void)additionalSetup {
_loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleMedium];
_loadingView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview: _loadingView];
[_loadingView.leadingAnchor constraintEqualToAnchor: self.centerXAnchor constant: -10].active = YES;
[_loadingView.trailingAnchor constraintEqualToAnchor: self.centerXAnchor constant: 10].active = YES;
[_loadingView.topAnchor constraintEqualToAnchor: self.bottomAnchor constant: -35].active = YES;
[_loadingView.bottomAnchor constraintEqualToAnchor: self.bottomAnchor constant: -15].active = YES;
[_loadingView startAnimating];
_dataUsageLabel = [[UILabel alloc] init];
//_useBatteryHealth ? [NSString stringWithFormat:@"Max Capacity: %@", _maximumCapacityPercent] : [NSString stringWithFormat:@"Battery Level: %.0f%%", [UIDevice currentDevice].batteryLevel*100];
_dataUsageLabel.font = [UIFont boldSystemFontOfSize:13];
_dataUsageLabel.textAlignment = NSTextAlignmentCenter;
_dataUsageLabel.adjustsFontSizeToFitWidth = YES;
_dataUsageLabel.minimumScaleFactor = 0.6;
_dataUsageLabel.numberOfLines = 1;
_dataUsageLabel.hidden = YES;
_dataUsageLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview: _dataUsageLabel];
[_dataUsageLabel.bottomAnchor constraintEqualToAnchor: self.bottomAnchor constant: -15].active = YES;
[_dataUsageLabel.leadingAnchor constraintEqualToAnchor: self.leadingAnchor constant: 10].active = YES;
[_dataUsageLabel.trailingAnchor constraintEqualToAnchor: self.trailingAnchor constant: -10].active = YES;
}
-(void)updateForData:(NSDictionary *)receievedData {
[_loadingView removeFromSuperview];
_dataUsageLabel.hidden = NO;
unsigned long long cellularDataUsage = [receievedData[@"cellularUsage"] unsignedLongLongValue];
_dataUsageLabel.text = [NSString stringWithFormat:@"%@: %.01fGB", localizedStringForKey(@"DATA_USAGE"), round(BtoGB(cellularDataUsage) * 10.0) / 10.0];
}
@end