@property (nonatomic, strong) NSString *identifier; | @property (nonatomic, strong) NSString *identifier; | ||||
-(id)glyph; | -(id)glyph; | ||||
-(id)kaiCellForDevice; | -(id)kaiCellForDevice; | ||||
-(void)resetKaiCellForNewPrefs; | |||||
@end | @end | ||||
@interface KAIBatteryCell : UIView | @interface KAIBatteryCell : UIView | ||||
@property (nonatomic, strong) NSLayoutConstraint *height; | @property (nonatomic, strong) NSLayoutConstraint *height; | ||||
-(instancetype)initWithFrame:(CGRect)arg1 device:(BCBatteryDevice *)device; | -(instancetype)initWithFrame:(CGRect)arg1 device:(BCBatteryDevice *)device; | ||||
-(void)updateInfo; | -(void)updateInfo; | ||||
+(instancetype)cellForDeviceIfExists:(BCBatteryDevice *)device frameToCreateNew:(CGRect)arg2; | |||||
+(void)resetArray; | |||||
@end | @end |
#import "KAIBatteryCell.h" | #import "KAIBatteryCell.h" | ||||
NSMutableArray *deviceInstances = [[NSMutableArray alloc] init]; | |||||
@implementation KAIBatteryCell | @implementation KAIBatteryCell | ||||
-(instancetype)initWithFrame:(CGRect)arg1 device:(BCBatteryDevice *)device { | -(instancetype)initWithFrame:(CGRect)arg1 device:(BCBatteryDevice *)device { | ||||
[self.battery.widthAnchor constraintEqualToConstant:20].active = YES; | [self.battery.widthAnchor constraintEqualToConstant:20].active = YES; | ||||
[self.battery.heightAnchor constraintEqualToConstant:10].active = YES; | [self.battery.heightAnchor constraintEqualToConstant:10].active = YES; | ||||
[deviceInstances addObject:self]; | |||||
} | } | ||||
return self; | return self; | ||||
} | } | ||||
+(instancetype)cellForDeviceIfExists:(BCBatteryDevice *)device frameToCreateNew:(CGRect)arg2 { | |||||
KAIBatteryCell *foundCell; | |||||
//NSString *deviceName = MSHookIvar<NSString *>(device, "_name"); | |||||
for(KAIBatteryCell *cell in deviceInstances) { | |||||
if(cell.device == device || [cell.device.identifier isEqualToString:device.identifier]) { | |||||
foundCell = cell; | |||||
break; | |||||
} | |||||
} | |||||
if(foundCell == nil) { | |||||
foundCell = [[KAIBatteryCell alloc] initWithFrame:arg2 device:device]; | |||||
} | |||||
return foundCell; | |||||
//return deviceInstances; | |||||
} | |||||
+(void)resetArray { | |||||
deviceInstances = [[NSMutableArray alloc] init]; | |||||
} | |||||
@end | @end |
@property (nonatomic, assign) BOOL isUpdating; | @property (nonatomic, assign) BOOL isUpdating; | ||||
+(KAIBatteryStack *)sharedInstance; | +(KAIBatteryStack *)sharedInstance; | ||||
-(instancetype)init; | -(instancetype)init; | ||||
-(void)removeAllAndRefresh; | |||||
-(void)refreshForPrefs; | |||||
-(void)updateBattery; | -(void)updateBattery; | ||||
@end | @end |
BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance]; | BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance]; | ||||
NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices"); | NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices"); | ||||
NSLog(@"kai: devices are %@", devices); | |||||
//NSLog(@"kai: devices are %@", devices); | |||||
for (BCBatteryDevice *device in devices) { | for (BCBatteryDevice *device in devices) { | ||||
KAIBatteryCell *cell = [device kaiCellForDevice]; | KAIBatteryCell *cell = [device kaiCellForDevice]; | ||||
} | } | ||||
} | } | ||||
for(KAIBatteryCell *cell in self.subviews) { | |||||
//BCBatteryDevice *device = cell.device; | |||||
[cell updateInfo]; | |||||
if(![devices containsObject:cell.device]) { | |||||
[UIView animateWithDuration:0.3 animations:^{ | |||||
cell.alpha = 0; | |||||
} completion:^(BOOL finished) { | |||||
[cell removeFromSuperview]; | |||||
[self removeArrangedSubview:cell]; | |||||
cell.alpha = 1; | |||||
}]; | |||||
} | |||||
} | |||||
self.number = [self.subviews count]; | self.number = [self.subviews count]; | ||||
} | } | ||||
self.number = [self.subviews count]; | self.number = [self.subviews count]; | ||||
} | } | ||||
-(void)removeAllAndRefresh { | |||||
for( UIView *view in self.subviews ) { | |||||
@try { | |||||
[view removeFromSuperview]; | |||||
} @catch (NSException *exception) { | |||||
//Panik | |||||
} | |||||
-(void)refreshForPrefs { | |||||
BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance]; | |||||
NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices"); | |||||
for(BCBatteryDevice *device in devices) { | |||||
[device resetKaiCellForNewPrefs]; | |||||
} | } | ||||
[KAIBatteryCell resetArray]; | |||||
[self updateBattery]; | |||||
} | } | ||||
+(KAIBatteryStack *)sharedInstance { | +(KAIBatteryStack *)sharedInstance { |
isUpdating = YES; | isUpdating = YES; | ||||
[[KAIBatteryStack sharedInstance] removeAllAndRefresh]; | |||||
[[KAIBatteryStack sharedInstance] refreshForPrefs]; | |||||
[(CSAdjunctListView *)([KAIBatteryStack sharedInstance].superview.superview) KaiUpdate]; | [(CSAdjunctListView *)([KAIBatteryStack sharedInstance].superview.superview) KaiUpdate]; | ||||
isUpdating = NO; | isUpdating = NO; |
-(void)KaiUpdate { | -(void)KaiUpdate { | ||||
KAIBatteryStack *battery = [KAIBatteryStack sharedInstance]; | KAIBatteryStack *battery = [KAIBatteryStack sharedInstance]; | ||||
//battery.number = [battery.subviews count]; | //battery.number = [battery.subviews count]; | ||||
BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance]; | |||||
NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices"); | |||||
for(KAIBatteryCell *cell in battery.subviews) { | |||||
//BCBatteryDevice *device = cell.device; | |||||
[cell updateInfo]; | |||||
if(![devices containsObject:cell.device]) { | |||||
[UIView animateWithDuration:0.3 animations:^{ | |||||
cell.alpha = 0; | |||||
} completion:^(BOOL finished) { | |||||
[cell removeFromSuperview]; | |||||
[battery removeArrangedSubview:cell]; | |||||
cell.alpha = 1; | |||||
}]; | |||||
} | |||||
} | |||||
[UIView animateWithDuration:0.3 animations:^{ | [UIView animateWithDuration:0.3 animations:^{ | ||||
return self.kaiCell; | return self.kaiCell; | ||||
} | } | ||||
%new | |||||
-(void)resetKaiCellForNewPrefs { | |||||
self.kaiCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0,0,[KAIBatteryStack sharedInstance].frame.size.width,0) device:self]; | |||||
((KAIBatteryCell *)self.kaiCell).translatesAutoresizingMaskIntoConstraints = NO; | |||||
[((KAIBatteryCell *)self.kaiCell).heightAnchor constraintEqualToConstant:bannerHeight].active = YES; | |||||
[(KAIBatteryCell *)self.kaiCell updateInfo]; | |||||
} | |||||
%end | %end | ||||
%hook KAICSTarget //Again, not a class | %hook KAICSTarget //Again, not a class |