From 8ef3fb0a587ff96c65ce601e6f112206e304738c Mon Sep 17 00:00:00 2001 From: Burrit0z Date: Wed, 3 Jun 2020 11:12:38 -0400 Subject: [PATCH] better management of adding and removing platter --- KAIBatteryPlatter.mm | 20 +++++++++++++++++--- Kai.xm | 6 +++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/KAIBatteryPlatter.mm b/KAIBatteryPlatter.mm index 2bf1389..d1fbd96 100755 --- a/KAIBatteryPlatter.mm +++ b/KAIBatteryPlatter.mm @@ -132,7 +132,10 @@ long long lastPercentage; self.number = [self.stack.subviews count]; 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) { [[[[objc_getClass("CSAdjunctListView") class] sharedListViewForKai] stackView] addArrangedSubview:self]; //[self performSelector:@selector(calculateHeight) withObject:self afterDelay:0.1]; @@ -142,9 +145,17 @@ long long lastPercentage; [UIView animateWithDuration:0.3 animations:^{ if(!self.heightConstraint) { + int height = (self.number * (bannerHeight + spacing)); + if(kaiAlign!=0) { + height = bannerHeight + spacing; + } - self.heightConstraint = [self.heightAnchor constraintEqualToConstant:(self.number * (bannerHeight + spacing))]; - self.stack.heightConstraint = [self.heightAnchor constraintEqualToConstant:(self.number * (bannerHeight + spacing))]; + if([self.superview.subviews count]>1) { + height = (height - spacing) + 1; + } + + self.heightConstraint = [self.heightAnchor constraintEqualToConstant:height]; + self.stack.heightConstraint = [self.heightAnchor constraintEqualToConstant:height]; self.heightConstraint.active = YES; self.stack.heightConstraint.active = YES; [self setContentSize:self.stack.frame.size]; @@ -166,7 +177,10 @@ long long lastPercentage; //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 { diff --git a/Kai.xm b/Kai.xm index ab0b3da..6871152 100755 --- a/Kai.xm +++ b/Kai.xm @@ -16,6 +16,9 @@ CSAdjunctListView *list; //and insert into last slot. [[self stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]]; [[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)]) { @@ -74,7 +77,6 @@ CSAdjunctListView *list; } 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.5]; } isUpdating = NO; @@ -106,11 +108,9 @@ CSAdjunctListView *list; } -(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 [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil]; - //} }