Browse Source

better placement options

master
Burrit0z 3 years ago
parent
commit
2250468f6f
5 changed files with 74 additions and 22 deletions
  1. +1
    -0
      Changelog
  2. +2
    -2
      KAIBatteryPlatter.mm
  3. +4
    -2
      Kai.h
  4. +42
    -9
      Kai.xm
  5. +25
    -9
      kaiprefs/Resources/Root.plist

+ 1
- 0
Changelog View File

@@ -58,3 +58,4 @@
1.5.0:
- Replace the code that handles hiding kai when media plays
- Fix edge cases where battery info would not update completely until an update was called for again
- There are now 3 placement options: Top, Below Media Player, and Bottom

+ 2
- 2
KAIBatteryPlatter.mm View File

@@ -240,8 +240,8 @@ NSMutableArray *cellsForDeviceNames = [[NSMutableArray alloc] init];
[s removeArrangedSubview:self];
[self removeFromSuperview];
} else if (self.number != 0 && self.superview == nil && shouldBeAdded == YES) {
[[[[objc_getClass("CSAdjunctListView") class] sharedListViewForKai] stackView] addArrangedSubview:self];
// [self performSelector:@selector(calculateHeight) withObject:self afterDelay:0.1];
Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
[cls reorderKai];
}

[UIView animateWithDuration:0.3

+ 4
- 2
Kai.h View File

@@ -10,6 +10,8 @@
- (UIStackView *)stackView;
- (void)_layoutStackView;
- (void)setStackView:(UIStackView *)arg1;
- (NSInteger)getMediaIndexForClass:(Class)cls;
- (void)performReorder;
+ (id)sharedListViewForKai;
+ (void)reorderKai;
@end
@@ -45,7 +47,6 @@ BOOL enabled;
BOOL disableGlyphs;
BOOL hidePercent;
BOOL showAll;
BOOL belowMusic;
BOOL hideDeviceLabel;
BOOL hideChargingAnimation;
BOOL showAllMinusInternal;
@@ -57,6 +58,7 @@ BOOL extraPaddingAfter;
NSInteger bannerStyle;
NSInteger bannerAlign;
NSInteger textColor;
NSInteger placement;
double spacing;
double glyphSize;
double bannerHeight;
@@ -123,7 +125,7 @@ static void preferencesChanged() {
hideDeviceLabel = boolValueForKey(@"hideDeviceLabel", NO);
bannerAlign = numberForValue(@"bannerAlign", 2);
horizontalOffset = numberForValue(@"horizontalOffset", 0);
belowMusic = boolValueForKey(@"belowMusic", NO);
placement = numberForValue(@"placement", 1);
hideChargingAnimation = boolValueForKey(@"hideChargingAnimation", YES);
textColor = numberForValue(@"textColor", 0);
bannerAlpha = numberForValue(@"bannerAlpha", 1);

+ 42
- 9
Kai.xm View File

@@ -63,7 +63,7 @@ CSAdjunctListView *list;

if(![arg1.subviews containsObject:battery]) { // if not added
// add kai to the stack view
[arg1 addArrangedSubview:battery];
[self performReorder];
}
[battery updateBattery];

@@ -101,6 +101,46 @@ CSAdjunctListView *list;

}

%new
- (NSInteger)getMediaIndexForClass:(Class)cls {
UIView *mediaPlayer;
int index = 0;
for(UIView *subview in [self stackView].subviews) {
if([subview isKindOfClass:cls]) {
return index;
}
index++;
}
return NSNotFound;
}

%new
- (void)performReorder {
UIStackView *stack = [self stackView];
if(placement == 1) { //top
BOOL isAperio = NO;

@try {
isAperio = [stack.subviews[0] isKindOfClass:%c(APEPlatter)];
// index 0 would be the platter, 1 would be placeholder
} @catch(NSException *exc) {}

[stack removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
[stack insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:isAperio];
// so, 0 if not aperio, 1 if aperio
} else if(placement == 2) { //after media
Class mediaClass = kCFCoreFoundationVersionNumber > 1600 ? %c(CSAdjunctItemView) : %c(SBDashBoardAdjunctItemView);
NSInteger mediaIndex = [self getMediaIndexForClass:mediaClass];
if(mediaIndex == NSNotFound) mediaIndex = 0;

[stack removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
[stack insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:mediaIndex];
} else if(placement == 3) { // bottom
[stack removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
[stack addArrangedSubview:[KAIBatteryPlatter sharedInstance]];
}
}

%new
+ (id)sharedListViewForKai {
return list;
@@ -109,14 +149,7 @@ CSAdjunctListView *list;
%new
+ (void)reorderKai {
NSLog(@"[Kai]: Reordering kai");
UIStackView *stack = [[self sharedListViewForKai] stackView];
if(belowMusic) { // cursed
[stack removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
[stack addArrangedSubview:[KAIBatteryPlatter sharedInstance]];
} else {
[stack removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
[stack insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:0];
}
[[self sharedListViewForKai] performReorder];
}

%end

+ 25
- 9
kaiprefs/Resources/Root.plist View File

@@ -332,18 +332,34 @@
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<false/>
<key>defaults</key>
<string>com.burritoz.kaiprefs</string>
<key>key</key>
<string>belowMusic</string>
<string>PSGroupCell</string>
<key>label</key>
<string>Show kai Below Music</string>
<string>Vertical Placement</string>
</dict>
<dict>
<key>cell</key>
<string>PSSegmentCell</string>
<key>defaults</key>
<string>com.burritoz.kaiprefs</string>
<key>default</key>
<string>1</string>
<key>key</key>
<string>placement</string>
<key>validValues</key>
<array>
<string>1</string>
<string>2</string>
<string>3</string>
</array>
<key>validTitles</key>
<array>
<string>Top</string>
<string>Below Media Player</string>
<string>Bottom</string>
</array>
<key>PostNotification</key>
<string>com.burritoz.kaiprefs.apply</string>
</dict>
</dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>

Loading…
Cancel
Save