From 16f294d77fcc0faa3aa41fb2ae46bbb01fcb8219 Mon Sep 17 00:00:00 2001 From: Burrit0z Date: Thu, 21 May 2020 21:00:28 -0400 Subject: [PATCH] progress towards rewrite (code trash rn) --- KAIBattery.h | 1 - KAIBattery.mm | 31 ++++++++++++++++++++----------- KAIBatteryCell.mm | 4 ++-- Kai.h | 11 +++++++++-- Kai.xm | 19 +++++++++++++------ kaiprefs/KAIRootListController.m | 2 +- 6 files changed, 45 insertions(+), 23 deletions(-) diff --git a/KAIBattery.h b/KAIBattery.h index d0fc261..aff1ca6 100644 --- a/KAIBattery.h +++ b/KAIBattery.h @@ -1,6 +1,5 @@ @interface KAIBattery : UIView @property (nonatomic, strong) NSMutableArray *displayingDevices; -@property (nonatomic, strong) NSArray *devices; @property (nonatomic, assign) NSInteger number; @property (nonatomic, strong) NSLayoutConstraint *heightConstraint; @property (nonatomic, assign) BOOL isUpdating; diff --git a/KAIBattery.mm b/KAIBattery.mm index de9063b..5adde72 100644 --- a/KAIBattery.mm +++ b/KAIBattery.mm @@ -7,6 +7,7 @@ KAIBattery *instance; self = [super init]; instance = self; if (self) { + self.displayingDevices = [[NSMutableArray alloc] init]; [self updateBattery]; self.userInteractionEnabled = NO; } @@ -25,16 +26,16 @@ long long lastPercentage; BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance]; NSArray *devices = MSHookIvar(bcb, "_sortedDevices"); - for( UIView *view in self.subviews ) { + /*for( UIView *view in self.subviews ) { @try { [view removeFromSuperview]; } @catch (NSException *exception) { //Panik } - } + }*/ for (BCBatteryDevice *device in devices) { - //NSString *deviceName = MSHookIvar(device, "_name"); + NSString *deviceName = MSHookIvar(device, "_name"); double batteryPercentage = MSHookIvar(device, "_percentCharge"); BOOL charging = MSHookIvar(device, "_charging"); BOOL LPM = MSHookIvar(device, "_batterySaverModeActive"); @@ -43,8 +44,10 @@ long long lastPercentage; if(showAll) { shouldAdd = YES; + NSLog(@"Kai: SHOULD ADD"); } else if(!showAll && charging) { shouldAdd = YES; + NSLog(@"Kai: SHOULD ADD"); } BOOL shouldRefresh = NO; @@ -58,25 +61,31 @@ long long lastPercentage; */ if(cell.lastChargingState != charging || cell.lastLPM != LPM || cell.lastPercent != batteryPercentage) { shouldRefresh = YES; + NSLog(@"Kai: SHOULD REFRESH"); } - if(shouldAdd) { + if(shouldAdd && [deviceName length]!=0) { if([self.displayingDevices containsObject:device] && shouldRefresh) { - [cell updateInfo]; - } else if(![self.displayingDevices containsObject:device]) { - KAIBatteryCell *newCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0, y, self.frame.size.width, self.frame.size.width)]; - [self addSubview:newCell]; - [self.displayingDevices addObject:device]; - y+=bannerHeight + spacing; - self.number +=1; + NSLog(@"Kai: Updating cell: %@ for device:%@", cell, device); + } else if(![self.displayingDevices containsObject:deviceName]) { + KAIBatteryCell *newCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0, y, self.frame.size.width, bannerHeight) device:device]; + [self.superview addSubview:newCell]; + [self.displayingDevices addObject:deviceName]; + //y+=bannerHeight + spacing; + NSLog(@"Kai: Added cell: %@ for device:%@", cell, device); } + self.number +=1; + y+=bannerHeight + spacing; + NSLog(@"Kai: incremented y, so now it is %f", y); + [cell updateInfo]; } else if(!shouldAdd) { if([self.displayingDevices containsObject:device]) { [cell removeFromSuperview]; [self.displayingDevices removeObject:device]; + NSLog(@"Kai: Removed cell: %@ for device: %@", cell, device); } } diff --git a/KAIBatteryCell.mm b/KAIBatteryCell.mm index 23b0117..33d8050 100644 --- a/KAIBatteryCell.mm +++ b/KAIBatteryCell.mm @@ -86,7 +86,7 @@ NSMutableArray *deviceInstances; [blank.rightAnchor constraintEqualToAnchor:self.rightAnchor constant:horizontalOffset].active = YES; } [blank.topAnchor constraintEqualToAnchor:self.topAnchor constant:self.frame.origin.y].active = YES; - [blank.widthAnchor constraintEqualToConstant:((self.superview.bounds.size.width - 16) + bannerWidthFactor)].active = YES; + [blank.widthAnchor constraintEqualToConstant:((self.frame.size.width) + bannerWidthFactor)].active = YES; [blank.heightAnchor constraintEqualToConstant:bannerHeight].active = YES; self.percentLabel.translatesAutoresizingMaskIntoConstraints = NO; @@ -131,7 +131,7 @@ NSMutableArray *deviceInstances; self.label.text = [NSString stringWithFormat:@"%@", deviceName]; [self.percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]]; self.battery.chargePercent = (batteryPercentage*0.01); - if(charging) self.battery.chargingState = 1; + if(charging) { self.battery.chargingState = 1; } else { self.battery.chargingState = 0; } self.battery.showsInlineChargingIndicator = YES; if(LPM) self.battery.saverModeActive = YES; if(kCFCoreFoundationVersionNumber > 1600) { diff --git a/Kai.h b/Kai.h index 98c665b..59a547d 100644 --- a/Kai.h +++ b/Kai.h @@ -112,8 +112,15 @@ static void applyPrefs() { preferencesChanged(); - //here I remotely refresh the KAIView. isUpdating = YES; + + [[KAIBattery sharedInstance] updateBattery]; + [(CSAdjunctListView *)([KAIBattery sharedInstance].superview.superview) KaiUpdate]; + + isUpdating = NO; + + //here I remotely refresh the KAIView. + /*isUpdating = YES; [UIView animateWithDuration:0.3 animations:^{ [KAIBattery sharedInstance].alpha = 0; } completion:^(BOOL finished){ @@ -124,6 +131,6 @@ static void applyPrefs() } completion:^(BOOL finished){ isUpdating = NO; }]; - }]; + }];*/ } \ No newline at end of file diff --git a/Kai.xm b/Kai.xm index 64c69bd..5fc44e2 100644 --- a/Kai.xm +++ b/Kai.xm @@ -6,14 +6,14 @@ -(void)_layoutStackView { - NSInteger lastSlot = [[self stackView].subviews count] -1; + //NSInteger lastSlot = [[self stackView].subviews count] -1; //this code is used to determine if kai is at the bottom of the stack view - if([[self stackView].subviews objectAtIndex:lastSlot] != [KAIBattery sharedInstance] && belowMusic) { + //if([[self stackView].subviews objectAtIndex:lastSlot] != [KAIBattery sharedInstance] && belowMusic) { //if it is not, but the option to have kai below music is on, i simply remove from it's current pos. //and insert into last slot. - [[self stackView] removeArrangedSubview:[KAIBattery sharedInstance]]; - [[self stackView] insertArrangedSubview:[KAIBattery sharedInstance] atIndex:lastSlot]; - } + //[[self stackView] removeArrangedSubview:[KAIBattery sharedInstance]]; + //[[self stackView] insertArrangedSubview:[KAIBattery sharedInstance] atIndex:lastSlot]; + //} //makes kai lay itself out when the stack does [self KaiUpdate]; @@ -78,6 +78,13 @@ if(!isUpdating) { isUpdating = YES; + + [[KAIBattery sharedInstance] updateBattery]; + [self KaiUpdate]; + + isUpdating = NO; + + /*isUpdating = YES; [UIView animateWithDuration:0.3 animations:^{ //nice fade out @@ -94,7 +101,7 @@ isUpdating = NO; }]; - }]; + }];*/ } diff --git a/kaiprefs/KAIRootListController.m b/kaiprefs/KAIRootListController.m index ba22e37..7bb6cf4 100644 --- a/kaiprefs/KAIRootListController.m +++ b/kaiprefs/KAIRootListController.m @@ -83,7 +83,7 @@ NSBundle *tweakBundle; - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat offsetY = scrollView.contentOffset.y; - if (offsetY > 140) { + if (offsetY > 120) { [UIView animateWithDuration:0.2 animations:^{ self.iconView.alpha = 1.0; self.titleLabel.alpha = 0.0;