mirror of
https://github.com/Burrit0z/kai
synced 2025-07-01 10:46:48 +00:00
progress towards rewrite (code trash rn)
This commit is contained in:
@ -1,6 +1,5 @@
|
|||||||
@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;
|
||||||
|
@ -7,6 +7,7 @@ KAIBattery *instance;
|
|||||||
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;
|
||||||
}
|
}
|
||||||
@ -25,16 +26,16 @@ long long lastPercentage;
|
|||||||
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");
|
||||||
@ -43,8 +44,10 @@ long long lastPercentage;
|
|||||||
|
|
||||||
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;
|
||||||
@ -58,25 +61,31 @@ long long lastPercentage;
|
|||||||
*/
|
*/
|
||||||
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];
|
NSLog(@"Kai: Updating cell: %@ for device:%@", cell, device);
|
||||||
} else if(![self.displayingDevices containsObject:device]) {
|
} else if(![self.displayingDevices containsObject:deviceName]) {
|
||||||
KAIBatteryCell *newCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0, y, self.frame.size.width, self.frame.size.width)];
|
KAIBatteryCell *newCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0, y, self.frame.size.width, bannerHeight) device:device];
|
||||||
[self addSubview:newCell];
|
[self.superview addSubview:newCell];
|
||||||
[self.displayingDevices addObject:device];
|
[self.displayingDevices addObject:deviceName];
|
||||||
y+=bannerHeight + spacing;
|
//y+=bannerHeight + spacing;
|
||||||
self.number +=1;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ NSMutableArray *deviceInstances;
|
|||||||
[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;
|
||||||
@ -131,7 +131,7 @@ NSMutableArray *deviceInstances;
|
|||||||
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) {
|
||||||
|
11
Kai.h
11
Kai.h
@ -112,8 +112,15 @@ static void applyPrefs()
|
|||||||
{
|
{
|
||||||
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){
|
||||||
@ -124,6 +131,6 @@ static void applyPrefs()
|
|||||||
} completion:^(BOOL finished){
|
} completion:^(BOOL finished){
|
||||||
isUpdating = NO;
|
isUpdating = NO;
|
||||||
}];
|
}];
|
||||||
}];
|
}];*/
|
||||||
|
|
||||||
}
|
}
|
19
Kai.xm
19
Kai.xm
@ -6,14 +6,14 @@
|
|||||||
|
|
||||||
-(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] removeArrangedSubview:[KAIBattery sharedInstance]];
|
||||||
[[self stackView] insertArrangedSubview:[KAIBattery sharedInstance] atIndex:lastSlot];
|
//[[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];
|
||||||
@ -78,6 +78,13 @@
|
|||||||
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
|
||||||
@ -94,7 +101,7 @@
|
|||||||
isUpdating = NO;
|
isUpdating = NO;
|
||||||
}];
|
}];
|
||||||
|
|
||||||
}];
|
}];*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ NSBundle *tweakBundle;
|
|||||||
- (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;
|
||||||
|
Reference in New Issue
Block a user