Browse Source

better management of adding and removing platter

pull/1/head
Burrit0z 4 years ago
parent
commit
8ef3fb0a58
2 changed files with 20 additions and 6 deletions
  1. +17
    -3
      KAIBatteryPlatter.mm
  2. +3
    -3
      Kai.xm

+ 17
- 3
KAIBatteryPlatter.mm View File

self.number = [self.stack.subviews count]; self.number = [self.stack.subviews count];


if(self.number==0) { if(self.number==0) {
[(UIStackView *)(self.superview) removeArrangedSubview:self];
UIStackView *s = (UIStackView *)(self.superview);
s.frame = CGRectMake(s.frame.origin.x, s.frame.origin.y, s.frame.size.width, (s.frame.size.height - 1));
[s removeArrangedSubview:self];
[self removeFromSuperview];
} else if(self.number!=0 && self.superview == nil) { } else if(self.number!=0 && self.superview == nil) {
[[[[objc_getClass("CSAdjunctListView") class] sharedListViewForKai] stackView] addArrangedSubview:self]; [[[[objc_getClass("CSAdjunctListView") class] sharedListViewForKai] stackView] addArrangedSubview:self];
//[self performSelector:@selector(calculateHeight) withObject:self afterDelay:0.1]; //[self performSelector:@selector(calculateHeight) withObject:self afterDelay:0.1];
[UIView animateWithDuration:0.3 animations:^{ [UIView animateWithDuration:0.3 animations:^{


if(!self.heightConstraint) { if(!self.heightConstraint) {
int height = (self.number * (bannerHeight + spacing));
if(kaiAlign!=0) {
height = bannerHeight + spacing;
}

if([self.superview.subviews count]>1) {
height = (height - spacing) + 1;
}


self.heightConstraint = [self.heightAnchor constraintEqualToConstant:(self.number * (bannerHeight + spacing))];
self.stack.heightConstraint = [self.heightAnchor constraintEqualToConstant:(self.number * (bannerHeight + spacing))];
self.heightConstraint = [self.heightAnchor constraintEqualToConstant:height];
self.stack.heightConstraint = [self.heightAnchor constraintEqualToConstant:height];
self.heightConstraint.active = YES; self.heightConstraint.active = YES;
self.stack.heightConstraint.active = YES; self.stack.heightConstraint.active = YES;
[self setContentSize:self.stack.frame.size]; [self setContentSize:self.stack.frame.size];
//literally does nothing but makes the stack view lay itself out (doesnt adjust frame because translatesAutoreszingMaskIntoConstraints = NO on stack views) //literally does nothing but makes the stack view lay itself out (doesnt adjust frame because translatesAutoreszingMaskIntoConstraints = NO on stack views)
} }


[self setContentSize:self.stack.frame.size];

}]; }];

} }


-(void)refreshForPrefs { -(void)refreshForPrefs {

+ 3
- 3
Kai.xm View File

//and insert into last slot. //and insert into last slot.
[[self stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]]; [[self stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
[[self stackView] insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:([[self stackView].subviews count] -1)]; [[self stackView] insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:([[self stackView].subviews count] -1)];
} else if([[self stackView].subviews objectAtIndex:0] != [KAIBatteryPlatter sharedInstance] && !belowMusic) {
[[self stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
[[self stackView] insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:0];
} }


if([KAISelf.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) { if([KAISelf.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) {
} }
if([KAISelf.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) { if([KAISelf.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) {
[KAISelf.superview performSelector:@selector(fixComplicationsViewFrame) withObject:KAISelf.superview afterDelay:0.35]; [KAISelf.superview performSelector:@selector(fixComplicationsViewFrame) withObject:KAISelf.superview afterDelay:0.35];
//[KAISelf.superview performSelector:@selector(fixComplicationsViewFrame) withObject:KAISelf.superview afterDelay:0.5];
} }


isUpdating = NO; isUpdating = NO;
} }


-(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"])) {


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



Loading…
Cancel
Save