Browse Source

progress towards rewrite (code trash rn)

pull/1/head
Burrit0z 4 years ago
parent
commit
16f294d77f
6 changed files with 45 additions and 23 deletions
  1. +0
    -1
      KAIBattery.h
  2. +20
    -11
      KAIBattery.mm
  3. +2
    -2
      KAIBatteryCell.mm
  4. +9
    -2
      Kai.h
  5. +13
    -6
      Kai.xm
  6. +1
    -1
      kaiprefs/KAIRootListController.m

+ 0
- 1
KAIBattery.h View File

@interface KAIBattery : UIView @interface KAIBattery : UIView
@property (nonatomic, strong) NSMutableArray *displayingDevices; @property (nonatomic, strong) NSMutableArray *displayingDevices;
@property (nonatomic, strong) NSArray *devices;
@property (nonatomic, assign) NSInteger number; @property (nonatomic, assign) NSInteger number;
@property (nonatomic, strong) NSLayoutConstraint *heightConstraint; @property (nonatomic, strong) NSLayoutConstraint *heightConstraint;
@property (nonatomic, assign) BOOL isUpdating; @property (nonatomic, assign) BOOL isUpdating;

+ 20
- 11
KAIBattery.mm View File

self = [super init]; self = [super init];
instance = self; instance = self;
if (self) { if (self) {
self.displayingDevices = [[NSMutableArray alloc] init];
[self updateBattery]; [self updateBattery];
self.userInteractionEnabled = NO; self.userInteractionEnabled = NO;
} }
BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance]; BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices"); NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");


for( UIView *view in self.subviews ) {
/*for( UIView *view in self.subviews ) {
@try { @try {
[view removeFromSuperview]; [view removeFromSuperview];
} @catch (NSException *exception) { } @catch (NSException *exception) {
//Panik //Panik
} }
}
}*/


for (BCBatteryDevice *device in devices) { for (BCBatteryDevice *device in devices) {
//NSString *deviceName = MSHookIvar<NSString *>(device, "_name");
NSString *deviceName = MSHookIvar<NSString *>(device, "_name");
double batteryPercentage = MSHookIvar<long long>(device, "_percentCharge"); double batteryPercentage = MSHookIvar<long long>(device, "_percentCharge");
BOOL charging = MSHookIvar<long long>(device, "_charging"); BOOL charging = MSHookIvar<long long>(device, "_charging");
BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive"); BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");


if(showAll) { if(showAll) {
shouldAdd = YES; shouldAdd = YES;
NSLog(@"Kai: SHOULD ADD");
} else if(!showAll && charging) { } else if(!showAll && charging) {
shouldAdd = YES; shouldAdd = YES;
NSLog(@"Kai: SHOULD ADD");
} }


BOOL shouldRefresh = NO; BOOL shouldRefresh = NO;
*/ */
if(cell.lastChargingState != charging || cell.lastLPM != LPM || cell.lastPercent != batteryPercentage) { if(cell.lastChargingState != charging || cell.lastLPM != LPM || cell.lastPercent != batteryPercentage) {
shouldRefresh = YES; shouldRefresh = YES;
NSLog(@"Kai: SHOULD REFRESH");
} }


if(shouldAdd) {
if(shouldAdd && [deviceName length]!=0) {


if([self.displayingDevices containsObject:device] && shouldRefresh) { 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) { } else if(!shouldAdd) {


if([self.displayingDevices containsObject:device]) { if([self.displayingDevices containsObject:device]) {
[cell removeFromSuperview]; [cell removeFromSuperview];
[self.displayingDevices removeObject:device]; [self.displayingDevices removeObject:device];
NSLog(@"Kai: Removed cell: %@ for device: %@", cell, device);
} }


} }

+ 2
- 2
KAIBatteryCell.mm View File

[blank.rightAnchor constraintEqualToAnchor:self.rightAnchor constant:horizontalOffset].active = YES; [blank.rightAnchor constraintEqualToAnchor:self.rightAnchor constant:horizontalOffset].active = YES;
} }
[blank.topAnchor constraintEqualToAnchor:self.topAnchor constant:self.frame.origin.y].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; [blank.heightAnchor constraintEqualToConstant:bannerHeight].active = YES;


self.percentLabel.translatesAutoresizingMaskIntoConstraints = NO; self.percentLabel.translatesAutoresizingMaskIntoConstraints = NO;
self.label.text = [NSString stringWithFormat:@"%@", deviceName]; self.label.text = [NSString stringWithFormat:@"%@", deviceName];
[self.percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]]; [self.percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]];
self.battery.chargePercent = (batteryPercentage*0.01); 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; self.battery.showsInlineChargingIndicator = YES;
if(LPM) self.battery.saverModeActive = YES; if(LPM) self.battery.saverModeActive = YES;
if(kCFCoreFoundationVersionNumber > 1600) { if(kCFCoreFoundationVersionNumber > 1600) {

+ 9
- 2
Kai.h View File

{ {
preferencesChanged(); preferencesChanged();


//here I remotely refresh the KAIView.
isUpdating = YES; 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:^{ [UIView animateWithDuration:0.3 animations:^{
[KAIBattery sharedInstance].alpha = 0; [KAIBattery sharedInstance].alpha = 0;
} completion:^(BOOL finished){ } completion:^(BOOL finished){
} completion:^(BOOL finished){ } completion:^(BOOL finished){
isUpdating = NO; isUpdating = NO;
}]; }];
}];
}];*/


} }

+ 13
- 6
Kai.xm View File



-(void)_layoutStackView { -(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 //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. //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. //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 //makes kai lay itself out when the stack does
[self KaiUpdate]; [self KaiUpdate];
if(!isUpdating) { if(!isUpdating) {


isUpdating = YES; isUpdating = YES;

[[KAIBattery sharedInstance] updateBattery];
[self KaiUpdate];

isUpdating = NO;

/*isUpdating = YES;
[UIView animateWithDuration:0.3 animations:^{ [UIView animateWithDuration:0.3 animations:^{


//nice fade out //nice fade out
isUpdating = NO; isUpdating = NO;
}]; }];


}];
}];*/


} }



+ 1
- 1
kaiprefs/KAIRootListController.m View File

- (void)scrollViewDidScroll:(UIScrollView *)scrollView { - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat offsetY = scrollView.contentOffset.y; CGFloat offsetY = scrollView.contentOffset.y;


if (offsetY > 140) {
if (offsetY > 120) {
[UIView animateWithDuration:0.2 animations:^{ [UIView animateWithDuration:0.2 animations:^{
self.iconView.alpha = 1.0; self.iconView.alpha = 1.0;
self.titleLabel.alpha = 0.0; self.titleLabel.alpha = 0.0;

Loading…
Cancel
Save