diff --git a/Changelog b/Changelog
index 7ebf9e6..69ae30a 100644
--- a/Changelog
+++ b/Changelog
@@ -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
diff --git a/KAIBatteryPlatter.mm b/KAIBatteryPlatter.mm
index 9c4ff4c..7db9463 100755
--- a/KAIBatteryPlatter.mm
+++ b/KAIBatteryPlatter.mm
@@ -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
diff --git a/Kai.h b/Kai.h
index 623a051..093ed7f 100755
--- a/Kai.h
+++ b/Kai.h
@@ -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);
diff --git a/Kai.xm b/Kai.xm
index 640787e..4a1cf0b 100755
--- a/Kai.xm
+++ b/Kai.xm
@@ -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
diff --git a/kaiprefs/Resources/Root.plist b/kaiprefs/Resources/Root.plist
index 9f5f667..ac63529 100644
--- a/kaiprefs/Resources/Root.plist
+++ b/kaiprefs/Resources/Root.plist
@@ -332,18 +332,34 @@
cell
- PSSwitchCell
- default
-
- defaults
- com.burritoz.kaiprefs
- key
- belowMusic
+ PSGroupCell
label
- Show kai Below Music
+ Vertical Placement
+
+
+ cell
+ PSSegmentCell
+ defaults
+ com.burritoz.kaiprefs
+ default
+ 1
+ key
+ placement
+ validValues
+
+ 1
+ 2
+ 3
+
+ validTitles
+
+ Top
+ Below Media Player
+ Bottom
+
PostNotification
com.burritoz.kaiprefs.apply
-
+
cell
PSGroupCell