Browse Source

so damn close

pull/1/head
Burrit0z 4 years ago
parent
commit
e937a735c6
2 changed files with 24 additions and 9 deletions
  1. +21
    -6
      KAIBatteryStack.mm
  2. +3
    -3
      Kai.xm

+ 21
- 6
KAIBatteryStack.mm View File

@@ -40,23 +40,33 @@ long long lastPercentage;
for (BCBatteryDevice *device in devices) {
KAIBatteryCell *cell = [device kaiCellForDevice];
BOOL charging = MSHookIvar<long long>(device, "_charging");

[cell updateInfo];
BOOL shouldAdd = NO;

if(showAll) {
shouldAdd = YES;
} else if(!showAll && device.charging) {
} else if(!showAll && charging) {
shouldAdd = YES;
}

if(![self.subviews containsObject:cell] && shouldAdd && [devices containsObject:device]) {
[cell setFrame:CGRectMake(0,0,self.frame.size.width, bannerHeight + spacing)];
//[cell setFrame:CGRectMake(0,0,self.frame.size.width, bannerHeight)];
cell.alpha = 0;
[self addSubview:cell];
[self addArrangedSubview:cell];
[UIView animateWithDuration:0.3 animations:^{
cell.alpha = 1;
}];
} else if([self.subviews containsObject:cell] && !shouldAdd){
[cell removeFromSuperview];
[self removeArrangedSubview:cell];
[UIView animateWithDuration:0.3 animations:^{
cell.alpha = 0;
} completion:^(BOOL finished) {
[cell removeFromSuperview];
[self removeArrangedSubview:cell];
cell.alpha = 1;
}];
}

}
@@ -65,8 +75,13 @@ long long lastPercentage;
//BCBatteryDevice *device = cell.device;
[cell updateInfo];
if(![devices containsObject:cell.device]) {
[cell removeFromSuperview];
[self removeArrangedSubview:cell];
[UIView animateWithDuration:0.3 animations:^{
cell.alpha = 0;
} completion:^(BOOL finished) {
[cell removeFromSuperview];
[self removeArrangedSubview:cell];
cell.alpha = 1;
}];
}
}

+ 3
- 3
Kai.xm View File

@@ -111,11 +111,11 @@
}

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
if([self isMemberOfClass:[objc_getClass("BCBatteryDevice") class]] && [self respondsToSelector:@selector(_kaiCell)] && object == self && ([keyPath isEqualToString:@"charging"] || [keyPath isEqualToString:@"percentCharge"] || [keyPath isEqualToString:@"batterySaverModeActive"])) {
//if([self isMemberOfClass:[objc_getClass("BCBatteryDevice") class]] && [self respondsToSelector:@selector(_kaiCell)] && object == self && ([keyPath isEqualToString:@"charging"] || [keyPath isEqualToString:@"percentCharge"] || [keyPath isEqualToString:@"batterySaverModeActive"])) {

//sends the noti to update battery info
[[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
}
//}
}

@@ -124,7 +124,7 @@
if(self && self.kaiCell == nil) {
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 + spacing].active = YES;
[((KAIBatteryCell *)self.kaiCell).heightAnchor constraintEqualToConstant:bannerHeight].active = YES;

[(KAIBatteryCell *)self.kaiCell updateInfo];


Loading…
Cancel
Save