diff --git a/KAIBatteryCell.h b/KAIBatteryCell.h index 5605374..66c3667 100644 --- a/KAIBatteryCell.h +++ b/KAIBatteryCell.h @@ -28,6 +28,7 @@ @property (nonatomic, strong) NSString *name; @property (nonatomic, assign) long long percentCharge; @property (nonatomic, assign) BOOL charging; +@property (nonatomic, assign) BOOL internal; @property (nonatomic, assign) BOOL batterySaverModeActive; @property (nonatomic, strong) NSString *identifier; -(id)glyph; diff --git a/KAIBatteryCell.mm b/KAIBatteryCell.mm index 9d90772..fce536f 100644 --- a/KAIBatteryCell.mm +++ b/KAIBatteryCell.mm @@ -13,21 +13,23 @@ BOOL charging = MSHookIvar(device, "_charging"); BOOL LPM = MSHookIvar(device, "_batterySaverModeActive"); - UIView *blank; + UIView *blur; + UIView *blurPlatter = [[UIView alloc] init]; if(bannerStyle==1) { if(kCFCoreFoundationVersionNumber > 1600) { - blank = [[[objc_getClass("MTMaterialView") class] alloc] _initWithRecipe:1 configuration:1 initialWeighting:1 scaleAdjustment:nil]; + blur = [[[objc_getClass("MTMaterialView") class] alloc] _initWithRecipe:1 configuration:1 initialWeighting:1 scaleAdjustment:nil]; } else if(kCFCoreFoundationVersionNumber < 1600) { - blank = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; + blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; } } else if(bannerStyle==2) { - blank = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]]; + blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]]; } else if(bannerStyle==3) { - blank = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; + blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; } - blank.layer.masksToBounds = YES; - blank.layer.continuousCorners = YES; - blank.layer.cornerRadius = cornerRadius; + blur.layer.masksToBounds = YES; + blur.layer.continuousCorners = YES; + blur.layer.cornerRadius = cornerRadius; + blurPlatter.alpha = bannerAlpha; NSString *labelText = [NSString stringWithFormat:@"%@", deviceName]; @@ -77,45 +79,52 @@ self.glyphView.contentMode = UIViewContentModeScaleAspectFit; [self.glyphView setImage:glyph]; - [self addSubview:blank]; + [self addSubview:blurPlatter]; + [blurPlatter addSubview:blur]; [self addSubview:self.percentLabel]; [self addSubview:self.label]; [self addSubview:self.battery]; [self addSubview:self.glyphView]; - blank.translatesAutoresizingMaskIntoConstraints = NO; + blurPlatter.translatesAutoresizingMaskIntoConstraints = NO; if(bannerAlign==2) { //center - [blank.centerXAnchor constraintEqualToAnchor:self.centerXAnchor constant:horizontalOffset].active = YES; + [blurPlatter.centerXAnchor constraintEqualToAnchor:self.centerXAnchor constant:horizontalOffset].active = YES; } else if(bannerAlign==1) { //left - [blank.leftAnchor constraintEqualToAnchor:self.leftAnchor constant:horizontalOffset].active = YES; + [blurPlatter.leftAnchor constraintEqualToAnchor:self.leftAnchor constant:horizontalOffset].active = YES; } else if(bannerAlign==3) { //right - [blank.rightAnchor constraintEqualToAnchor:self.rightAnchor constant:horizontalOffset].active = YES; + [blurPlatter.rightAnchor constraintEqualToAnchor:self.rightAnchor constant:horizontalOffset].active = YES; } - [blank.topAnchor constraintEqualToAnchor:self.topAnchor].active = YES; - [blank.widthAnchor constraintEqualToConstant:((self.frame.size.width) + bannerWidthFactor)].active = YES; - [blank.heightAnchor constraintEqualToConstant:bannerHeight].active = YES; + [blurPlatter.topAnchor constraintEqualToAnchor:self.topAnchor].active = YES; + [blurPlatter.widthAnchor constraintEqualToConstant:((self.frame.size.width) + bannerWidthFactor)].active = YES; + [blurPlatter.heightAnchor constraintEqualToConstant:bannerHeight].active = YES; + + blur.translatesAutoresizingMaskIntoConstraints = NO; + [blur.centerXAnchor constraintEqualToAnchor:blurPlatter.centerXAnchor].active = YES; + [blur.topAnchor constraintEqualToAnchor:blurPlatter.topAnchor].active = YES; + [blur.widthAnchor constraintEqualToAnchor:blurPlatter.widthAnchor].active = YES; + [blur.heightAnchor constraintEqualToAnchor:blurPlatter.heightAnchor].active = YES; self.percentLabel.translatesAutoresizingMaskIntoConstraints = NO; - [self.percentLabel.leftAnchor constraintEqualToAnchor:blank.rightAnchor constant:(- 96)].active = YES; - [self.percentLabel.centerYAnchor constraintEqualToAnchor:blank.centerYAnchor].active = YES; + [self.percentLabel.leftAnchor constraintEqualToAnchor:blurPlatter.rightAnchor constant:(- 96)].active = YES; + [self.percentLabel.centerYAnchor constraintEqualToAnchor:blurPlatter.centerYAnchor].active = YES; [self.percentLabel.widthAnchor constraintEqualToConstant:37].active = YES; [self.percentLabel.heightAnchor constraintEqualToConstant:12].active = YES; self.label.translatesAutoresizingMaskIntoConstraints = NO; [self.label.leftAnchor constraintEqualToAnchor:self.glyphView.rightAnchor constant:4.5].active = YES; - [self.label.centerYAnchor constraintEqualToAnchor:blank.centerYAnchor].active = YES; + [self.label.centerYAnchor constraintEqualToAnchor:blurPlatter.centerYAnchor].active = YES; [self.label.rightAnchor constraintEqualToAnchor:self.percentLabel.leftAnchor constant:-4.5].active = YES; [self.label.heightAnchor constraintEqualToConstant:25].active = YES; self.glyphView.translatesAutoresizingMaskIntoConstraints = NO; - [self.glyphView.leftAnchor constraintEqualToAnchor:blank.leftAnchor constant:20.5].active = YES; - [self.glyphView.centerYAnchor constraintEqualToAnchor:blank.centerYAnchor].active = YES; + [self.glyphView.leftAnchor constraintEqualToAnchor:blurPlatter.leftAnchor constant:20.5].active = YES; + [self.glyphView.centerYAnchor constraintEqualToAnchor:blurPlatter.centerYAnchor].active = YES; [self.glyphView.widthAnchor constraintEqualToConstant:glyphSize].active = YES; [self.glyphView.heightAnchor constraintEqualToConstant:glyphSize].active = YES; self.battery.translatesAutoresizingMaskIntoConstraints = NO; - [self.battery.leftAnchor constraintEqualToAnchor:blank.rightAnchor constant:(- 49)].active = YES; - [self.battery.centerYAnchor constraintEqualToAnchor:blank.centerYAnchor].active = YES; + [self.battery.leftAnchor constraintEqualToAnchor:blurPlatter.rightAnchor constant:(- 49)].active = YES; + [self.battery.centerYAnchor constraintEqualToAnchor:blurPlatter.centerYAnchor].active = YES; [self.battery.widthAnchor constraintEqualToConstant:20].active = YES; [self.battery.heightAnchor constraintEqualToConstant:10].active = YES; @@ -161,14 +170,15 @@ self.battery.chargePercent = (batteryPercentage*0.01); [self.glyphView setImage:[self.device glyph]]; + [self.heightAnchor constraintEqualToConstant:(bannerHeight + spacing)].active = YES; - if(!self.height) { + /*if(!self.height) { self.height.active = NO; self.height = [self.heightAnchor constraintEqualToConstant:(bannerHeight + spacing)]; self.height.active = YES; - } //else { + }*/ //else { //int height = (bannerHeight + spacing); //self.height.constant = height; //} diff --git a/KAIBatteryStack.mm b/KAIBatteryStack.mm index 9a81427..f06f2ff 100644 --- a/KAIBatteryStack.mm +++ b/KAIBatteryStack.mm @@ -52,10 +52,13 @@ long long lastPercentage; for (BCBatteryDevice *device in devices) { KAIBatteryCell *cell = [device kaiCellForDevice]; BOOL charging = MSHookIvar(device, "_charging"); + BOOL internal = MSHookIvar(device, "_internal"); BOOL shouldAdd = NO; if(showAll) { shouldAdd = YES; + } else if(showAllMinusInternal && !internal) { + shouldAdd = YES; } else if(!showAll && charging) { shouldAdd = YES; } @@ -99,6 +102,29 @@ long long lastPercentage; self.queued = YES; } + self.number = [self.subviews count]; + + [UIView animateWithDuration:0.3 animations:^{ + + if(!self.heightConstraint) { + + self.heightConstraint.active = NO; + self.heightConstraint = [self.heightAnchor constraintEqualToConstant:(self.number * (bannerHeight + spacing))]; + //set an initial constraint + self.heightConstraint.active = YES; + + } else { + int height = (self.number * (bannerHeight + spacing)); //big brain math + //self.heightConstraint.active = NO; //deactivation + self.heightConstraint.constant = height; + //self.heightConstraint.active = YES; //forcing reactivation + + 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) + } + + }]; }); @@ -113,7 +139,7 @@ long long lastPercentage; if(!self.heightConstraint) { self.heightConstraint.active = NO; - self.heightConstraint = [self.heightAnchor constraintEqualToConstant:85]; + self.heightConstraint = [self.heightAnchor constraintEqualToConstant:(self.number * (bannerHeight + spacing))]; //set an initial constraint self.heightConstraint.active = YES; @@ -153,7 +179,7 @@ long long lastPercentage; if(!self.heightConstraint) { self.heightConstraint.active = NO; - self.heightConstraint = [self.heightAnchor constraintEqualToConstant:85]; + self.heightConstraint = [self.heightAnchor constraintEqualToConstant:(self.number * (bannerHeight + spacing))]; //set an initial constraint self.heightConstraint.active = YES; diff --git a/Kai.h b/Kai.h index bdd7cdf..5c97707 100644 --- a/Kai.h +++ b/Kai.h @@ -40,6 +40,7 @@ BOOL showAll; BOOL belowMusic; BOOL hideDeviceLabel; BOOL hideChargingAnimation; +BOOL showAllMinusInternal; NSInteger bannerStyle; NSInteger bannerAlign; NSInteger textColor; @@ -49,6 +50,7 @@ double bannerHeight; double cornerRadius; double bannerWidthFactor; double horizontalOffset; +double bannerAlpha; //by importing here, I can use vars in the .mm files #import "KAIBatteryCell.mm" @@ -116,6 +118,8 @@ static void preferencesChanged() belowMusic = boolValueForKey(@"belowMusic", NO); hideChargingAnimation = boolValueForKey(@"hideChargingAnimation", YES); textColor = numberForValue(@"textColor", 0); + bannerAlpha = numberForValue(@"bannerAlpha", 1); + showAllMinusInternal = boolValueForKey(@"showAllMinusInternal", NO); if(disableGlyphs) { glyphSize = 0; diff --git a/kaiprefs/Resources/Root.plist b/kaiprefs/Resources/Root.plist index b4fffbc..9990b6c 100644 --- a/kaiprefs/Resources/Root.plist +++ b/kaiprefs/Resources/Root.plist @@ -39,6 +39,8 @@ cell PSGroupCell + footerText + By having the show all devices option on, all deviecs, not only devices that are charging, will show. When the always show bluetooth devices option is on, kai will show all connected bluetooth devices if they are charging or not. cell @@ -52,6 +54,18 @@ label Show all devices + + cell + PSSwitchCell + default + + defaults + com.burritoz.kaiprefs + key + showAllMinusInternal + label + Always show bluetooth devices + cell PSSwitchCell @@ -328,6 +342,30 @@ key cornerRadius + + cell + PSGroupCell + label + Banner Blur Alpha (1) + + + default + 1 + cell + PSSliderCell + min + 0.0 + max + 1 + isSegmented + + showValue + + defaults + com.burritoz.kaiprefs + key + bannerAlpha + title kai