self = [super initWithFrame:arg1]; | self = [super initWithFrame:arg1]; | ||||
instance = self; | instance = self; | ||||
if (self) { | if (self) { | ||||
self.stackHolder = [[UIView alloc] initWithFrame:arg1]; | |||||
self.stack = [[KAIStackView alloc] init]; | self.stack = [[KAIStackView alloc] init]; | ||||
self.stack.axis = kaiAlign==0 ? 1 : 0; | self.stack.axis = kaiAlign==0 ? 1 : 0; | ||||
self.stack.distribution = 0; | self.stack.distribution = 0; | ||||
self.stack.alignment = 0; | self.stack.alignment = 0; | ||||
self.oldCountOfDevices = -100; | self.oldCountOfDevices = -100; | ||||
self.queued = NO; | self.queued = NO; | ||||
[self setMinimumZoomScale:1]; | [self setMinimumZoomScale:1]; | ||||
[self setMaximumZoomScale:1]; | [self setMaximumZoomScale:1]; | ||||
[self addSubview:self.stack]; | |||||
[self addSubview:self.stackHolder]; | |||||
[self.stackHolder addSubview:self.stack]; | |||||
[self setContentSize:self.stack.frame.size]; | [self setContentSize:self.stack.frame.size]; | ||||
[self setContentOffset:CGPointMake(0,0)]; | [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]; | [self updateBattery]; | ||||
} | } | ||||
return self; | return self; | ||||
}]; | }]; | ||||
self.stackHolder.frame = self.frame; | |||||
} | } | ||||
-(void)refreshForPrefs { | -(void)refreshForPrefs { | ||||
self.stack.spacing = kaiAlign==0 ? 0 : spacingHorizontal; | self.stack.spacing = kaiAlign==0 ? 0 : spacingHorizontal; | ||||
[self setContentSize:self.stack.frame.size]; | [self setContentSize:self.stack.frame.size]; | ||||
for( UIView *view in self.stack.subviews ) { | for( UIView *view in self.stack.subviews ) { | ||||
[device resetKaiCellForNewPrefs]; | [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]; | [self updateBattery]; | ||||
} | } | ||||
@interface KAIStackView : UIStackView | @interface KAIStackView : UIStackView | ||||
@property (nonatomic, strong) NSLayoutConstraint *heightConstraint; | @property (nonatomic, strong) NSLayoutConstraint *heightConstraint; | ||||
@property (nonatomic, strong) NSLayoutConstraint *widthConstraint; | |||||
@property (nonatomic, strong) NSLayoutConstraint *aligner; | |||||
@end | @end | ||||
@interface KAIBatteryPlatter : UIScrollView <UIScrollViewDelegate> | @interface KAIBatteryPlatter : UIScrollView <UIScrollViewDelegate> | ||||
@property (nonatomic, strong) UIView *stackHolder; | |||||
@property (nonatomic, assign) NSInteger number; | @property (nonatomic, assign) NSInteger number; | ||||
@property (nonatomic, assign) NSInteger oldCountOfDevices; | @property (nonatomic, assign) NSInteger oldCountOfDevices; | ||||
@property (nonatomic, strong) NSLayoutConstraint *heightConstraint; | @property (nonatomic, strong) NSLayoutConstraint *heightConstraint; | ||||
@property (nonatomic, strong) NSLayoutConstraint *widthConstraint; | @property (nonatomic, strong) NSLayoutConstraint *widthConstraint; | ||||
@property (nonatomic, strong) NSLayoutConstraint *subviewAligner; | |||||
@property (nonatomic, strong) KAIStackView *stack; | @property (nonatomic, strong) KAIStackView *stack; | ||||
@property (nonatomic, assign) BOOL isUpdating; | @property (nonatomic, assign) BOOL isUpdating; | ||||
@property (nonatomic, assign) BOOL queued; | @property (nonatomic, assign) BOOL queued; |
-(void)addSubview:(UIView *)view { | -(void)addSubview:(UIView *)view { | ||||
[super addSubview: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)]) { | if(textColor==0 && [view respondsToSelector:@selector(updateInfo)]) { | ||||
KAIBatteryCell *cell = (KAIBatteryCell *)view; | KAIBatteryCell *cell = (KAIBatteryCell *)view; | ||||
-(void)layoutSubviews { | -(void)layoutSubviews { | ||||
[super layoutSubviews]; | [super layoutSubviews]; | ||||
[(KAIBatteryPlatter *)(self.superview) calculateHeight]; | |||||
[(KAIBatteryPlatter *)(self.superview.superview) calculateHeight]; | |||||
} | } | ||||
@end | @end |
%property (nonatomic, assign) BOOL hasKai; | %property (nonatomic, assign) BOOL hasKai; | ||||
-(void)_layoutStackView { | -(void)_layoutStackView { | ||||
%orig; | |||||
//this code is used to determine if kai is at the bottom of the stack view | //this code is used to determine if kai is at the bottom of the stack view | ||||
@try { | @try { | ||||
//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]; | |||||
}*/ | |||||
} | |||||
} @catch (NSException *exc) {} | } @catch (NSException *exc) {} | ||||
[[KAIBatteryPlatter sharedInstance] calculateHeight]; | [[KAIBatteryPlatter sharedInstance] calculateHeight]; | ||||
%orig; | |||||
} | } | ||||
-(void)setStackView:(UIStackView *)arg1 { | -(void)setStackView:(UIStackView *)arg1 { |