@@ -1,6 +1,5 @@ | |||
@interface KAIBattery : UIView | |||
@property (nonatomic, strong) NSMutableArray *displayingDevices; | |||
@property (nonatomic, strong) NSArray *devices; | |||
@property (nonatomic, assign) NSInteger number; | |||
@property (nonatomic, strong) NSLayoutConstraint *heightConstraint; | |||
@property (nonatomic, assign) BOOL isUpdating; |
@@ -7,6 +7,7 @@ KAIBattery *instance; | |||
self = [super init]; | |||
instance = self; | |||
if (self) { | |||
self.displayingDevices = [[NSMutableArray alloc] init]; | |||
[self updateBattery]; | |||
self.userInteractionEnabled = NO; | |||
} | |||
@@ -25,16 +26,16 @@ long long lastPercentage; | |||
BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance]; | |||
NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices"); | |||
for( UIView *view in self.subviews ) { | |||
/*for( UIView *view in self.subviews ) { | |||
@try { | |||
[view removeFromSuperview]; | |||
} @catch (NSException *exception) { | |||
//Panik | |||
} | |||
} | |||
}*/ | |||
for (BCBatteryDevice *device in devices) { | |||
//NSString *deviceName = MSHookIvar<NSString *>(device, "_name"); | |||
NSString *deviceName = MSHookIvar<NSString *>(device, "_name"); | |||
double batteryPercentage = MSHookIvar<long long>(device, "_percentCharge"); | |||
BOOL charging = MSHookIvar<long long>(device, "_charging"); | |||
BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive"); | |||
@@ -43,8 +44,10 @@ long long lastPercentage; | |||
if(showAll) { | |||
shouldAdd = YES; | |||
NSLog(@"Kai: SHOULD ADD"); | |||
} else if(!showAll && charging) { | |||
shouldAdd = YES; | |||
NSLog(@"Kai: SHOULD ADD"); | |||
} | |||
BOOL shouldRefresh = NO; | |||
@@ -58,25 +61,31 @@ long long lastPercentage; | |||
*/ | |||
if(cell.lastChargingState != charging || cell.lastLPM != LPM || cell.lastPercent != batteryPercentage) { | |||
shouldRefresh = YES; | |||
NSLog(@"Kai: SHOULD REFRESH"); | |||
} | |||
if(shouldAdd) { | |||
if(shouldAdd && [deviceName length]!=0) { | |||
if([self.displayingDevices containsObject:device] && shouldRefresh) { | |||
[cell updateInfo]; | |||
} else if(![self.displayingDevices containsObject:device]) { | |||
KAIBatteryCell *newCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0, y, self.frame.size.width, self.frame.size.width)]; | |||
[self addSubview:newCell]; | |||
[self.displayingDevices addObject:device]; | |||
y+=bannerHeight + spacing; | |||
self.number +=1; | |||
NSLog(@"Kai: Updating cell: %@ for device:%@", cell, device); | |||
} else if(![self.displayingDevices containsObject:deviceName]) { | |||
KAIBatteryCell *newCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0, y, self.frame.size.width, bannerHeight) device:device]; | |||
[self.superview addSubview:newCell]; | |||
[self.displayingDevices addObject:deviceName]; | |||
//y+=bannerHeight + spacing; | |||
NSLog(@"Kai: Added cell: %@ for device:%@", cell, device); | |||
} | |||
self.number +=1; | |||
y+=bannerHeight + spacing; | |||
NSLog(@"Kai: incremented y, so now it is %f", y); | |||
[cell updateInfo]; | |||
} else if(!shouldAdd) { | |||
if([self.displayingDevices containsObject:device]) { | |||
[cell removeFromSuperview]; | |||
[self.displayingDevices removeObject:device]; | |||
NSLog(@"Kai: Removed cell: %@ for device: %@", cell, device); | |||
} | |||
} |
@@ -86,7 +86,7 @@ NSMutableArray *deviceInstances; | |||
[blank.rightAnchor constraintEqualToAnchor:self.rightAnchor constant:horizontalOffset].active = YES; | |||
} | |||
[blank.topAnchor constraintEqualToAnchor:self.topAnchor constant:self.frame.origin.y].active = YES; | |||
[blank.widthAnchor constraintEqualToConstant:((self.superview.bounds.size.width - 16) + bannerWidthFactor)].active = YES; | |||
[blank.widthAnchor constraintEqualToConstant:((self.frame.size.width) + bannerWidthFactor)].active = YES; | |||
[blank.heightAnchor constraintEqualToConstant:bannerHeight].active = YES; | |||
self.percentLabel.translatesAutoresizingMaskIntoConstraints = NO; | |||
@@ -131,7 +131,7 @@ NSMutableArray *deviceInstances; | |||
self.label.text = [NSString stringWithFormat:@"%@", deviceName]; | |||
[self.percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]]; | |||
self.battery.chargePercent = (batteryPercentage*0.01); | |||
if(charging) self.battery.chargingState = 1; | |||
if(charging) { self.battery.chargingState = 1; } else { self.battery.chargingState = 0; } | |||
self.battery.showsInlineChargingIndicator = YES; | |||
if(LPM) self.battery.saverModeActive = YES; | |||
if(kCFCoreFoundationVersionNumber > 1600) { |
@@ -112,8 +112,15 @@ static void applyPrefs() | |||
{ | |||
preferencesChanged(); | |||
//here I remotely refresh the KAIView. | |||
isUpdating = YES; | |||
[[KAIBattery sharedInstance] updateBattery]; | |||
[(CSAdjunctListView *)([KAIBattery sharedInstance].superview.superview) KaiUpdate]; | |||
isUpdating = NO; | |||
//here I remotely refresh the KAIView. | |||
/*isUpdating = YES; | |||
[UIView animateWithDuration:0.3 animations:^{ | |||
[KAIBattery sharedInstance].alpha = 0; | |||
} completion:^(BOOL finished){ | |||
@@ -124,6 +131,6 @@ static void applyPrefs() | |||
} completion:^(BOOL finished){ | |||
isUpdating = NO; | |||
}]; | |||
}]; | |||
}];*/ | |||
} |
@@ -6,14 +6,14 @@ | |||
-(void)_layoutStackView { | |||
NSInteger lastSlot = [[self stackView].subviews count] -1; | |||
//NSInteger lastSlot = [[self stackView].subviews count] -1; | |||
//this code is used to determine if kai is at the bottom of the stack view | |||
if([[self stackView].subviews objectAtIndex:lastSlot] != [KAIBattery sharedInstance] && belowMusic) { | |||
//if([[self stackView].subviews objectAtIndex:lastSlot] != [KAIBattery sharedInstance] && belowMusic) { | |||
//if it is not, but the option to have kai below music is on, i simply remove from it's current pos. | |||
//and insert into last slot. | |||
[[self stackView] removeArrangedSubview:[KAIBattery sharedInstance]]; | |||
[[self stackView] insertArrangedSubview:[KAIBattery sharedInstance] atIndex:lastSlot]; | |||
} | |||
//[[self stackView] removeArrangedSubview:[KAIBattery sharedInstance]]; | |||
//[[self stackView] insertArrangedSubview:[KAIBattery sharedInstance] atIndex:lastSlot]; | |||
//} | |||
//makes kai lay itself out when the stack does | |||
[self KaiUpdate]; | |||
@@ -78,6 +78,13 @@ | |||
if(!isUpdating) { | |||
isUpdating = YES; | |||
[[KAIBattery sharedInstance] updateBattery]; | |||
[self KaiUpdate]; | |||
isUpdating = NO; | |||
/*isUpdating = YES; | |||
[UIView animateWithDuration:0.3 animations:^{ | |||
//nice fade out | |||
@@ -94,7 +101,7 @@ | |||
isUpdating = NO; | |||
}]; | |||
}]; | |||
}];*/ | |||
} | |||
@@ -83,7 +83,7 @@ NSBundle *tweakBundle; | |||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { | |||
CGFloat offsetY = scrollView.contentOffset.y; | |||
if (offsetY > 140) { | |||
if (offsetY > 120) { | |||
[UIView animateWithDuration:0.2 animations:^{ | |||
self.iconView.alpha = 1.0; | |||
self.titleLabel.alpha = 0.0; |