diff --git a/KAIBatteryPlatter.mm b/KAIBatteryPlatter.mm index 8fadeac..877bd63 100755 --- a/KAIBatteryPlatter.mm +++ b/KAIBatteryPlatter.mm @@ -8,6 +8,7 @@ NSTimer *queueTimer = nil; self = [super initWithFrame:arg1]; instance = self; if (self) { + self.stackHolder = [[UIView alloc] initWithFrame:arg1]; self.stack = [[KAIStackView alloc] init]; self.stack.axis = kaiAlign==0 ? 1 : 0; self.stack.distribution = 0; @@ -15,13 +16,33 @@ NSTimer *queueTimer = nil; self.stack.alignment = 0; self.oldCountOfDevices = -100; self.queued = NO; - + [self setMinimumZoomScale:1]; [self setMaximumZoomScale:1]; - [self addSubview:self.stack]; + [self addSubview:self.stackHolder]; + [self.stackHolder addSubview:self.stack]; [self setContentSize:self.stack.frame.size]; [self setContentOffset:CGPointMake(0,0)]; + //Keeping this link here to leak... + //https://cdn.discordapp.com/attachments/683698397634756646/718122118990266518/unknown.png + + self.stackHolder.translatesAutoresizingMaskIntoConstraints = NO; + + if(bannerAlign==2) { //center + self.subviewAligner = [self.stackHolder.centerXAnchor constraintEqualToAnchor:self.centerXAnchor]; + } else if(bannerAlign==1) { //left + self.subviewAligner = [self.stackHolder.leftAnchor constraintEqualToAnchor:self.leftAnchor]; + } else if(bannerAlign==3) { //right + self.subviewAligner = [self.stackHolder.rightAnchor constraintEqualToAnchor:self.rightAnchor]; + } + + [self.stackHolder.heightAnchor constraintEqualToAnchor:self.heightAnchor].active = YES; + [self.stackHolder.widthAnchor constraintEqualToAnchor:self.stack.widthAnchor].active = YES; + [self.stackHolder.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES; + + self.subviewAligner.active = YES; + [self updateBattery]; } return self; @@ -191,9 +212,12 @@ long long lastPercentage; }]; + self.stackHolder.frame = self.frame; + } -(void)refreshForPrefs { + self.stack.spacing = kaiAlign==0 ? 0 : spacingHorizontal; [self setContentSize:self.stack.frame.size]; for( UIView *view in self.stack.subviews ) { @@ -210,6 +234,18 @@ long long lastPercentage; [device resetKaiCellForNewPrefs]; } + self.subviewAligner.active = NO; + [self.stackHolder removeConstraint:self.subviewAligner]; + if(bannerAlign==2) { //center + self.subviewAligner = [self.stackHolder.centerXAnchor constraintEqualToAnchor:self.centerXAnchor]; + } else if(bannerAlign==1) { //left + self.subviewAligner = [self.stackHolder.leftAnchor constraintEqualToAnchor:self.leftAnchor]; + } else if(bannerAlign==3) { //right + self.subviewAligner = [self.stackHolder.rightAnchor constraintEqualToAnchor:self.rightAnchor]; + } + + self.subviewAligner.active = YES; + [self updateBattery]; } diff --git a/KAIStackView.h b/KAIStackView.h index 04112aa..d50a5bf 100644 --- a/KAIStackView.h +++ b/KAIStackView.h @@ -1,14 +1,14 @@ @interface KAIStackView : UIStackView @property (nonatomic, strong) NSLayoutConstraint *heightConstraint; -@property (nonatomic, strong) NSLayoutConstraint *widthConstraint; -@property (nonatomic, strong) NSLayoutConstraint *aligner; @end @interface KAIBatteryPlatter : UIScrollView +@property (nonatomic, strong) UIView *stackHolder; @property (nonatomic, assign) NSInteger number; @property (nonatomic, assign) NSInteger oldCountOfDevices; @property (nonatomic, strong) NSLayoutConstraint *heightConstraint; @property (nonatomic, strong) NSLayoutConstraint *widthConstraint; +@property (nonatomic, strong) NSLayoutConstraint *subviewAligner; @property (nonatomic, strong) KAIStackView *stack; @property (nonatomic, assign) BOOL isUpdating; @property (nonatomic, assign) BOOL queued; diff --git a/KAIStackView.mm b/KAIStackView.mm index 87f9c83..c88e1fb 100644 --- a/KAIStackView.mm +++ b/KAIStackView.mm @@ -10,7 +10,7 @@ -(void)addSubview:(UIView *)view { [super addSubview:view]; - [(UIScrollView *)self.superview setContentSize:self.frame.size]; + [(UIScrollView *)self.superview.superview setContentSize:self.frame.size]; if(textColor==0 && [view respondsToSelector:@selector(updateInfo)]) { KAIBatteryCell *cell = (KAIBatteryCell *)view; @@ -28,7 +28,7 @@ -(void)layoutSubviews { [super layoutSubviews]; - [(KAIBatteryPlatter *)(self.superview) calculateHeight]; + [(KAIBatteryPlatter *)(self.superview.superview) calculateHeight]; } @end \ No newline at end of file diff --git a/Kai.xm b/Kai.xm index 8c995c6..7cd19f5 100755 --- a/Kai.xm +++ b/Kai.xm @@ -9,6 +9,7 @@ CSAdjunctListView *list; %property (nonatomic, assign) BOOL hasKai; -(void)_layoutStackView { + %orig; //this code is used to determine if kai is at the bottom of the stack view @try { @@ -17,10 +18,7 @@ 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]; - }*/ + } } @catch (NSException *exc) {} @@ -30,7 +28,6 @@ CSAdjunctListView *list; [[KAIBatteryPlatter sharedInstance] calculateHeight]; - %orig; } -(void)setStackView:(UIStackView *)arg1 {