|
|
|
|
|
|
|
|
#import "KAIBattery.h" |
|
|
#import "KAIBattery.h" |
|
|
|
|
|
|
|
|
KAIBattery *instance; |
|
|
KAIBattery *instance; |
|
|
NSMutableArray *addedCells = [[NSMutableArray alloc] init]; |
|
|
|
|
|
|
|
|
//NSMutableArray *showingCells = [[NSMutableArray alloc] init]; |
|
|
|
|
|
|
|
|
@implementation KAIBattery |
|
|
@implementation KAIBattery |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-(void)updateBattery { |
|
|
-(void)updateBattery { |
|
|
dispatch_async(dispatch_get_main_queue(), ^{ |
|
|
dispatch_async(dispatch_get_main_queue(), ^{ |
|
|
NSLog(@"kai: battery platter called to update"); |
|
|
|
|
|
|
|
|
//NSLog(@"kai: battery platter called to update"); |
|
|
if(!self.isUpdating) { |
|
|
if(!self.isUpdating) { |
|
|
self.isUpdating = YES; |
|
|
self.isUpdating = YES; |
|
|
self.number = 0; |
|
|
self.number = 0; |
|
|
|
|
|
|
|
|
BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance]; |
|
|
BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance]; |
|
|
NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices"); |
|
|
NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices"); |
|
|
|
|
|
|
|
|
/*for( UIView *view in self.subviews ) { |
|
|
|
|
|
@try { |
|
|
|
|
|
[view removeFromSuperview]; |
|
|
|
|
|
} @catch (NSException *exception) { |
|
|
|
|
|
//Panik |
|
|
|
|
|
} |
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
for(KAIBatteryCell *cell in addedCells) { |
|
|
|
|
|
if(cell.device!=nil) { |
|
|
|
|
|
NSString *cellName = MSHookIvar<NSString *>(cell.device, "_name"); |
|
|
|
|
|
if(![addedCells containsObject:cellName]) { |
|
|
|
|
|
cell.device = nil; |
|
|
|
|
|
[cell removeFromSuperview]; |
|
|
|
|
|
[self.displayingDevices removeObject:cell.label.text]; //lmaoo |
|
|
|
|
|
} else { |
|
|
|
|
|
[cell updateInfo]; |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
//[cell removeFromSuperview]; |
|
|
|
|
|
//[addedCells removeObject:cell]; |
|
|
|
|
|
|
|
|
for(KAIBatteryCell *cell in self.subviews) { |
|
|
|
|
|
if([cell respondsToSelector:@selector(updateInfo)] && ![devices containsObject:cell.device]) { //to confirm is a cell and battery device does not exist |
|
|
|
|
|
[cell removeFromSuperview]; |
|
|
|
|
|
} else if([cell respondsToSelector:@selector(updateInfo)]) { |
|
|
|
|
|
[cell updateInfo]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (BCBatteryDevice *device in devices) { |
|
|
for (BCBatteryDevice *device in devices) { |
|
|
NSString *deviceName = MSHookIvar<NSString *>(device, "_name"); |
|
|
NSString *deviceName = MSHookIvar<NSString *>(device, "_name"); |
|
|
//double batteryPercentage = MSHookIvar<long long>(device, "_percentCharge"); |
|
|
//double batteryPercentage = MSHookIvar<long long>(device, "_percentCharge"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(showAll) { |
|
|
if(showAll) { |
|
|
shouldAdd = YES; |
|
|
shouldAdd = YES; |
|
|
NSLog(@"Kai: SHOULD ADD"); |
|
|
|
|
|
|
|
|
//NSLog(@"Kai: SHOULD ADD"); |
|
|
} else if(!showAll && charging) { |
|
|
} else if(!showAll && charging) { |
|
|
shouldAdd = YES; |
|
|
shouldAdd = YES; |
|
|
NSLog(@"Kai: SHOULD ADD"); |
|
|
|
|
|
|
|
|
//NSLog(@"Kai: SHOULD ADD"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
KAIBatteryCell *cell = [KAIBatteryCell cellForDeviceIfExists:device]; |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
@property (nonatomic, assign) BOOL lastChargingState; |
|
|
|
|
|
@property (nonatomic, assign) BOOL lastLPM; |
|
|
|
|
|
@property (nonatomic, assign) double lastPercent; |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
KAIBatteryCell *cell = [KAIBatteryCell cellForDeviceIfExists:device frameToCreateNew:CGRectMake(0, y, self.frame.size.width, bannerHeight)]; |
|
|
|
|
|
|
|
|
if(shouldAdd && [deviceName length]!=0) { |
|
|
if(shouldAdd && [deviceName length]!=0) { |
|
|
|
|
|
|
|
|
if(cell==nil && ![self.displayingDevices containsObject:deviceName]) { |
|
|
|
|
|
KAIBatteryCell *newCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0, y, self.frame.size.width, bannerHeight) device:device]; |
|
|
|
|
|
[self addSubview:newCell]; |
|
|
|
|
|
[self.displayingDevices addObject:deviceName]; |
|
|
|
|
|
[addedCells addObject:newCell]; |
|
|
|
|
|
//y+=bannerHeight + spacing; |
|
|
|
|
|
|
|
|
if(![self.subviews containsObject:cell]) { |
|
|
|
|
|
cell.frame = CGRectMake(0, y, self.frame.size.width, bannerHeight); |
|
|
|
|
|
[self addSubview:cell]; |
|
|
} |
|
|
} |
|
|
//self.number +=1; |
|
|
|
|
|
y+=bannerHeight + spacing; |
|
|
y+=bannerHeight + spacing; |
|
|
|
|
|
|
|
|
} else if(!shouldAdd) { |
|
|
} else if(!shouldAdd) { |
|
|
|
|
|
|
|
|
if([self.displayingDevices containsObject:deviceName]) { |
|
|
|
|
|
cell.device = nil; |
|
|
|
|
|
[cell removeFromSuperview]; |
|
|
|
|
|
[self.displayingDevices removeObject:deviceName]; |
|
|
|
|
|
[addedCells removeObject:cell]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[cell removeFromSuperview]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
//[self.heightAnchor constraintEqualToConstant:(self.number * 85)].active = YES; |
|
|
//[self.heightAnchor constraintEqualToConstant:(self.number * 85)].active = YES; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
self.displayingDevices = [[NSMutableArray alloc] init]; |
|
|
|
|
|
|
|
|
//self.displayingDevices = [[NSMutableArray alloc] init]; |
|
|
|
|
|
|
|
|
addedCells = nil; |
|
|
|
|
|
|
|
|
//addedCells = nil; |
|
|
[self updateBattery]; |
|
|
[self updateBattery]; |
|
|
} |
|
|
} |
|
|
|
|
|
|