diff --git a/KAIBatteryPlatter.h b/KAIBatteryPlatter.h index 81e662b..cd987ff 100755 --- a/KAIBatteryPlatter.h +++ b/KAIBatteryPlatter.h @@ -1,4 +1,4 @@ -@interface KAIBatteryPlatter : UIStackView +@interface KAIBatteryPlatter : UIScrollView @property (nonatomic, assign) NSInteger number; @property (nonatomic, assign) NSInteger oldCountOfDevices; @property (nonatomic, strong) NSLayoutConstraint *heightConstraint; @@ -6,7 +6,7 @@ @property (nonatomic, assign) BOOL isUpdating; @property (nonatomic, assign) BOOL queued; +(KAIBatteryPlatter *)sharedInstance; --(instancetype)init; +-(instancetype)initWithFrame:(CGRect)arg1; -(void)refreshForPrefs; -(void)updateBattery; @end \ No newline at end of file diff --git a/KAIBatteryPlatter.mm b/KAIBatteryPlatter.mm index d13ae25..b2f1474 100755 --- a/KAIBatteryPlatter.mm +++ b/KAIBatteryPlatter.mm @@ -5,18 +5,25 @@ NSTimer *queueTimer = nil; @implementation KAIBatteryPlatter --(instancetype)init { - self = [super init]; +-(instancetype)initWithFrame:(CGRect)arg1 { + self = [super initWithFrame:arg1]; instance = self; if (self) { self.stack = [[KAIStackView alloc] init]; self.stack.axis = kaiAlign==0 ? 1 : 0; self.stack.distribution = 0; - self.stack.spacing = kaiAlign==0 ? 0 : spacing; + self.stack.spacing = kaiAlign==0 ? 0 : spacingHorizontal; self.stack.alignment = 0; self.oldCountOfDevices = -100; self.queued = NO; + + [self setMinimumZoomScale:1]; + [self setMaximumZoomScale:1]; [self addSubview:self.stack]; + [self setContentSize:self.stack.frame.size]; + [self setContentOffset:CGPointMake(0,0)]; + //[self setDelegate:self]; + [self updateBattery]; } return self; @@ -107,6 +114,10 @@ long long lastPercentage; } +-(void)setContentOffset:(CGPoint)arg1 { + [super setContentOffset:CGPointMake(arg1.x, 0)]; +} + -(void)setNumber:(NSInteger)arg1 { _number = arg1; [UIView animateWithDuration:0.3 animations:^{ @@ -117,13 +128,14 @@ long long lastPercentage; self.stack.heightConstraint = [self.heightAnchor constraintEqualToConstant:(self.number * (bannerHeight + spacing))]; self.heightConstraint.active = YES; self.stack.heightConstraint.active = YES; + [self setContentSize:self.stack.frame.size]; } else { int height = (self.number * (bannerHeight + spacing)); if(kaiAlign==0 && [self.superview.subviews count]>1) { height = (self.number * (bannerHeight + spacing)) - spacing; } else { - height = bannerHeight; + height = bannerHeight + spacing; } self.heightConstraint.constant = height; self.stack.heightConstraint.constant = height; @@ -131,19 +143,20 @@ long long lastPercentage; 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)); //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)addArrangedSubview:(UIView *)view { - [super addArrangedSubview:view]; +-(void)addSubview:(UIView *)view { + [super addSubview:view]; self.number = [self.stack.subviews count]; if([self.superview.superview.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) { [(NCNotificationListView *)(self.superview.superview.superview) fixComplicationsViewFrame]; } - if(textColor==0) { + if(textColor==0 && [view respondsToSelector:@selector(updateInfo)]) { KAIBatteryCell *cell = (KAIBatteryCell *)view; if(@available(iOS 12.0, *)) { if(self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { @@ -157,9 +170,7 @@ long long lastPercentage; } } --(void)removeArrangedSubview:(UIView *)view { - [super removeArrangedSubview:view]; - self.number = [self.stack.subviews count]; +-(void)layoutSubviews { if([self.superview.superview.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) { [(NCNotificationListView *)(self.superview.superview.superview) fixComplicationsViewFrame]; } @@ -167,6 +178,8 @@ long long lastPercentage; } -(void)refreshForPrefs { + self.stack.spacing = kaiAlign==0 ? 0 : spacingHorizontal; + [self setContentSize:self.stack.frame.size]; for( UIView *view in self.stack.subviews ) { @try { [view removeFromSuperview]; diff --git a/Kai.h b/Kai.h index 1300657..08ae1f8 100755 --- a/Kai.h +++ b/Kai.h @@ -58,6 +58,7 @@ double bannerWidthFactor; double horizontalOffset; double bannerAlpha; double kaiAlign; +double spacingHorizontal; //by importing here, I can use vars in the .mm files #import "KAIBatteryCell.mm" @@ -129,6 +130,7 @@ static void preferencesChanged() bannerAlpha = numberForValue(@"bannerAlpha", 1); showAllMinusInternal = boolValueForKey(@"showAllMinusInternal", NO); kaiAlign = numberForValue(@"kaiAlign", 0); + spacingHorizontal = numberForValue(@"spacingHorizontal", 8); if(disableGlyphs) { glyphSize = 0; diff --git a/Kai.xm b/Kai.xm index a1b429e..b45e95d 100755 --- a/Kai.xm +++ b/Kai.xm @@ -29,7 +29,7 @@ -(void)setStackView:(UIStackView *)arg1 { if(!KAISelf.hasKai) { - KAIBatteryPlatter *battery = [[KAIBatteryPlatter alloc] init]; + KAIBatteryPlatter *battery = [[KAIBatteryPlatter alloc] initWithFrame:[self stackView].frame]; //Add noti observer [[NSNotificationCenter defaultCenter] addObserver:self diff --git a/kaiprefs/Resources/Root.plist b/kaiprefs/Resources/Root.plist index a6a359d..54b2829 100644 --- a/kaiprefs/Resources/Root.plist +++ b/kaiprefs/Resources/Root.plist @@ -276,7 +276,9 @@ cell PSGroupCell label - Banner Spacing (5) + Banner Spacing - Vertical (5) + footerText + This is the spacing between cells vertically, for kai's vertical mode. default @@ -296,6 +298,32 @@ key spacing + + cell + PSGroupCell + label + Banner Spacing - Horizontal (8) + footerText + This is the spacing between cells horizontally, for kai's horizontal mode. + + + default + 8 + cell + PSSliderCell + min + -100.0 + max + 300 + isSegmented + + showValue + + defaults + com.burritoz.kaiprefs + key + spacingHorizontal + cell PSGroupCell