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

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];
[self removeArrangedSubview:cell];
[UIView animateWithDuration:0.3 animations:^{
cell.alpha = 0;
} completion:^(BOOL finished) {
[cell removeFromSuperview];
[self removeArrangedSubview:cell];
cell.alpha = 1;
}];
} }


} }
//BCBatteryDevice *device = cell.device; //BCBatteryDevice *device = cell.device;
[cell updateInfo]; [cell updateInfo];
if(![devices containsObject:cell.device]) { 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

} }


-(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];
}
//}
} }


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];



Loading…
Cancel
Save