diff --git a/KAIBatteryStack.mm b/KAIBatteryStack.mm index 1b84c83..d22dcc1 100644 --- a/KAIBatteryStack.mm +++ b/KAIBatteryStack.mm @@ -40,23 +40,33 @@ long long lastPercentage; for (BCBatteryDevice *device in devices) { KAIBatteryCell *cell = [device kaiCellForDevice]; + BOOL charging = MSHookIvar(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; + }]; } } diff --git a/Kai.xm b/Kai.xm index f3ee1a5..1a63d98 100644 --- a/Kai.xm +++ b/Kai.xm @@ -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];