1
0
mirror of https://github.com/Burrit0z/kai synced 2025-07-01 07:06:48 +00:00
This commit is contained in:
Burrit0z
2020-06-02 20:01:15 -04:00
parent c77f972168
commit 5bd0d5495c
5 changed files with 57 additions and 14 deletions

View File

@ -1,4 +1,4 @@
@interface KAIBatteryPlatter : UIStackView @interface KAIBatteryPlatter : UIScrollView <UIScrollViewDelegate>
@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;
@ -6,7 +6,7 @@
@property (nonatomic, assign) BOOL isUpdating; @property (nonatomic, assign) BOOL isUpdating;
@property (nonatomic, assign) BOOL queued; @property (nonatomic, assign) BOOL queued;
+(KAIBatteryPlatter *)sharedInstance; +(KAIBatteryPlatter *)sharedInstance;
-(instancetype)init; -(instancetype)initWithFrame:(CGRect)arg1;
-(void)refreshForPrefs; -(void)refreshForPrefs;
-(void)updateBattery; -(void)updateBattery;
@end @end

View File

@ -5,18 +5,25 @@ NSTimer *queueTimer = nil;
@implementation KAIBatteryPlatter @implementation KAIBatteryPlatter
-(instancetype)init { -(instancetype)initWithFrame:(CGRect)arg1 {
self = [super init]; self = [super initWithFrame:arg1];
instance = self; instance = self;
if (self) { if (self) {
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.spacing = kaiAlign==0 ? 0 : spacing; self.stack.spacing = kaiAlign==0 ? 0 : spacingHorizontal;
self.stack.alignment = 0; self.stack.alignment = 0;
self.oldCountOfDevices = -100; self.oldCountOfDevices = -100;
self.queued = NO; self.queued = NO;
[self setMinimumZoomScale:1];
[self setMaximumZoomScale:1];
[self addSubview:self.stack]; [self addSubview:self.stack];
[self setContentSize:self.stack.frame.size];
[self setContentOffset:CGPointMake(0,0)];
//[self setDelegate:self];
[self updateBattery]; [self updateBattery];
} }
return self; return self;
@ -107,6 +114,10 @@ long long lastPercentage;
} }
-(void)setContentOffset:(CGPoint)arg1 {
[super setContentOffset:CGPointMake(arg1.x, 0)];
}
-(void)setNumber:(NSInteger)arg1 { -(void)setNumber:(NSInteger)arg1 {
_number = arg1; _number = arg1;
[UIView animateWithDuration:0.3 animations:^{ [UIView animateWithDuration:0.3 animations:^{
@ -117,13 +128,14 @@ long long lastPercentage;
self.stack.heightConstraint = [self.heightAnchor constraintEqualToConstant:(self.number * (bannerHeight + spacing))]; self.stack.heightConstraint = [self.heightAnchor constraintEqualToConstant:(self.number * (bannerHeight + spacing))];
self.heightConstraint.active = YES; self.heightConstraint.active = YES;
self.stack.heightConstraint.active = YES; self.stack.heightConstraint.active = YES;
[self setContentSize:self.stack.frame.size];
} else { } else {
int height = (self.number * (bannerHeight + spacing)); int height = (self.number * (bannerHeight + spacing));
if(kaiAlign==0 && [self.superview.subviews count]>1) { if(kaiAlign==0 && [self.superview.subviews count]>1) {
height = (self.number * (bannerHeight + spacing)) - spacing; height = (self.number * (bannerHeight + spacing)) - spacing;
} else { } else {
height = bannerHeight; height = bannerHeight + spacing;
} }
self.heightConstraint.constant = height; self.heightConstraint.constant = height;
self.stack.heightConstraint.constant = height; self.stack.heightConstraint.constant = height;
@ -131,19 +143,20 @@ long long lastPercentage;
UIStackView *s = (UIStackView *)(self.superview); 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.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) //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 { -(void)addSubview:(UIView *)view {
[super addArrangedSubview:view]; [super addSubview:view];
self.number = [self.stack.subviews count]; self.number = [self.stack.subviews count];
if([self.superview.superview.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) { if([self.superview.superview.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) {
[(NCNotificationListView *)(self.superview.superview.superview) fixComplicationsViewFrame]; [(NCNotificationListView *)(self.superview.superview.superview) fixComplicationsViewFrame];
} }
if(textColor==0) { if(textColor==0 && [view respondsToSelector:@selector(updateInfo)]) {
KAIBatteryCell *cell = (KAIBatteryCell *)view; KAIBatteryCell *cell = (KAIBatteryCell *)view;
if(@available(iOS 12.0, *)) { if(@available(iOS 12.0, *)) {
if(self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { if(self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
@ -157,9 +170,7 @@ long long lastPercentage;
} }
} }
-(void)removeArrangedSubview:(UIView *)view { -(void)layoutSubviews {
[super removeArrangedSubview:view];
self.number = [self.stack.subviews count];
if([self.superview.superview.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) { if([self.superview.superview.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) {
[(NCNotificationListView *)(self.superview.superview.superview) fixComplicationsViewFrame]; [(NCNotificationListView *)(self.superview.superview.superview) fixComplicationsViewFrame];
} }
@ -167,6 +178,8 @@ long long lastPercentage;
} }
-(void)refreshForPrefs { -(void)refreshForPrefs {
self.stack.spacing = kaiAlign==0 ? 0 : spacingHorizontal;
[self setContentSize:self.stack.frame.size];
for( UIView *view in self.stack.subviews ) { for( UIView *view in self.stack.subviews ) {
@try { @try {
[view removeFromSuperview]; [view removeFromSuperview];

2
Kai.h
View File

@ -58,6 +58,7 @@ double bannerWidthFactor;
double horizontalOffset; double horizontalOffset;
double bannerAlpha; double bannerAlpha;
double kaiAlign; double kaiAlign;
double spacingHorizontal;
//by importing here, I can use vars in the .mm files //by importing here, I can use vars in the .mm files
#import "KAIBatteryCell.mm" #import "KAIBatteryCell.mm"
@ -129,6 +130,7 @@ static void preferencesChanged()
bannerAlpha = numberForValue(@"bannerAlpha", 1); bannerAlpha = numberForValue(@"bannerAlpha", 1);
showAllMinusInternal = boolValueForKey(@"showAllMinusInternal", NO); showAllMinusInternal = boolValueForKey(@"showAllMinusInternal", NO);
kaiAlign = numberForValue(@"kaiAlign", 0); kaiAlign = numberForValue(@"kaiAlign", 0);
spacingHorizontal = numberForValue(@"spacingHorizontal", 8);
if(disableGlyphs) { if(disableGlyphs) {
glyphSize = 0; glyphSize = 0;

2
Kai.xm
View File

@ -29,7 +29,7 @@
-(void)setStackView:(UIStackView *)arg1 { -(void)setStackView:(UIStackView *)arg1 {
if(!KAISelf.hasKai) { if(!KAISelf.hasKai) {
KAIBatteryPlatter *battery = [[KAIBatteryPlatter alloc] init]; KAIBatteryPlatter *battery = [[KAIBatteryPlatter alloc] initWithFrame:[self stackView].frame];
//Add noti observer //Add noti observer
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self

View File

@ -276,7 +276,9 @@
<key>cell</key> <key>cell</key>
<string>PSGroupCell</string> <string>PSGroupCell</string>
<key>label</key> <key>label</key>
<string>Banner Spacing (5)</string> <string>Banner Spacing - Vertical (5)</string>
<key>footerText</key>
<string>This is the spacing between cells vertically, for kai's vertical mode.</string>
</dict> </dict>
<dict> <dict>
<key>default</key> <key>default</key>
@ -296,6 +298,32 @@
<key>key</key> <key>key</key>
<string>spacing</string> <string>spacing</string>
</dict> </dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>Banner Spacing - Horizontal (8)</string>
<key>footerText</key>
<string>This is the spacing between cells horizontally, for kai's horizontal mode.</string>
</dict>
<dict>
<key>default</key>
<real>8</real>
<key>cell</key>
<string>PSSliderCell</string>
<key>min</key>
<real>-100.0</real>
<key>max</key>
<real>300</real>
<key>isSegmented</key>
<false/>
<key>showValue</key>
<true/>
<key>defaults</key>
<string>com.burritoz.kaiprefs</string>
<key>key</key>
<string>spacingHorizontal</string>
</dict>
<dict> <dict>
<key>cell</key> <key>cell</key>
<string>PSGroupCell</string> <string>PSGroupCell</string>