mirror of
https://github.com/Burrit0z/kai
synced 2025-07-01 10:26:47 +00:00
so damn close
This commit is contained in:
@ -40,23 +40,33 @@ long long lastPercentage;
|
|||||||
|
|
||||||
for (BCBatteryDevice *device in devices) {
|
for (BCBatteryDevice *device in devices) {
|
||||||
KAIBatteryCell *cell = [device kaiCellForDevice];
|
KAIBatteryCell *cell = [device kaiCellForDevice];
|
||||||
|
BOOL charging = MSHookIvar<long long>(device, "_charging");
|
||||||
|
|
||||||
[cell updateInfo];
|
[cell updateInfo];
|
||||||
BOOL shouldAdd = NO;
|
BOOL shouldAdd = NO;
|
||||||
|
|
||||||
if(showAll) {
|
if(showAll) {
|
||||||
shouldAdd = YES;
|
shouldAdd = YES;
|
||||||
} else if(!showAll && device.charging) {
|
} else if(!showAll && charging) {
|
||||||
shouldAdd = YES;
|
shouldAdd = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(![self.subviews containsObject:cell] && shouldAdd && [devices containsObject:device]) {
|
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 addSubview:cell];
|
||||||
[self addArrangedSubview:cell];
|
[self addArrangedSubview:cell];
|
||||||
|
[UIView animateWithDuration:0.3 animations:^{
|
||||||
|
cell.alpha = 1;
|
||||||
|
}];
|
||||||
} else if([self.subviews containsObject:cell] && !shouldAdd){
|
} else if([self.subviews containsObject:cell] && !shouldAdd){
|
||||||
[cell removeFromSuperview];
|
[UIView animateWithDuration:0.3 animations:^{
|
||||||
[self removeArrangedSubview:cell];
|
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;
|
//BCBatteryDevice *device = cell.device;
|
||||||
[cell updateInfo];
|
[cell updateInfo];
|
||||||
if(![devices containsObject:cell.device]) {
|
if(![devices containsObject:cell.device]) {
|
||||||
[cell removeFromSuperview];
|
[UIView animateWithDuration:0.3 animations:^{
|
||||||
[self removeArrangedSubview:cell];
|
cell.alpha = 0;
|
||||||
|
} completion:^(BOOL finished) {
|
||||||
|
[cell removeFromSuperview];
|
||||||
|
[self removeArrangedSubview:cell];
|
||||||
|
cell.alpha = 1;
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
Kai.xm
6
Kai.xm
@ -111,11 +111,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
|
-(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
|
//sends the noti to update battery info
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
|
||||||
}
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +124,7 @@
|
|||||||
if(self && self.kaiCell == nil) {
|
if(self && self.kaiCell == nil) {
|
||||||
self.kaiCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0,0,[KAIBatteryStack sharedInstance].frame.size.width,0) device:self]; }
|
self.kaiCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0,0,[KAIBatteryStack sharedInstance].frame.size.width,0) device:self]; }
|
||||||
((KAIBatteryCell *)self.kaiCell).translatesAutoresizingMaskIntoConstraints = NO;
|
((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];
|
[(KAIBatteryCell *)self.kaiCell updateInfo];
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user