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

1.5.0: 1.5.0:
- Replace the code that handles hiding kai when media plays - 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 - 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

[s removeArrangedSubview:self]; [s removeArrangedSubview:self];
[self removeFromSuperview]; [self removeFromSuperview];
} else if (self.number != 0 && self.superview == nil && shouldBeAdded == YES) { } 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 [UIView animateWithDuration:0.3

+ 4
- 2
Kai.h View File

- (UIStackView *)stackView; - (UIStackView *)stackView;
- (void)_layoutStackView; - (void)_layoutStackView;
- (void)setStackView:(UIStackView *)arg1; - (void)setStackView:(UIStackView *)arg1;
- (NSInteger)getMediaIndexForClass:(Class)cls;
- (void)performReorder;
+ (id)sharedListViewForKai; + (id)sharedListViewForKai;
+ (void)reorderKai; + (void)reorderKai;
@end @end
BOOL disableGlyphs; BOOL disableGlyphs;
BOOL hidePercent; BOOL hidePercent;
BOOL showAll; BOOL showAll;
BOOL belowMusic;
BOOL hideDeviceLabel; BOOL hideDeviceLabel;
BOOL hideChargingAnimation; BOOL hideChargingAnimation;
BOOL showAllMinusInternal; BOOL showAllMinusInternal;
NSInteger bannerStyle; NSInteger bannerStyle;
NSInteger bannerAlign; NSInteger bannerAlign;
NSInteger textColor; NSInteger textColor;
NSInteger placement;
double spacing; double spacing;
double glyphSize; double glyphSize;
double bannerHeight; double bannerHeight;
hideDeviceLabel = boolValueForKey(@"hideDeviceLabel", NO); hideDeviceLabel = boolValueForKey(@"hideDeviceLabel", NO);
bannerAlign = numberForValue(@"bannerAlign", 2); bannerAlign = numberForValue(@"bannerAlign", 2);
horizontalOffset = numberForValue(@"horizontalOffset", 0); horizontalOffset = numberForValue(@"horizontalOffset", 0);
belowMusic = boolValueForKey(@"belowMusic", NO);
placement = numberForValue(@"placement", 1);
hideChargingAnimation = boolValueForKey(@"hideChargingAnimation", YES); hideChargingAnimation = boolValueForKey(@"hideChargingAnimation", YES);
textColor = numberForValue(@"textColor", 0); textColor = numberForValue(@"textColor", 0);
bannerAlpha = numberForValue(@"bannerAlpha", 1); bannerAlpha = numberForValue(@"bannerAlpha", 1);

+ 42
- 9
Kai.xm View File



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




} }


%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 %new
+ (id)sharedListViewForKai { + (id)sharedListViewForKai {
return list; return list;
%new %new
+ (void)reorderKai { + (void)reorderKai {
NSLog(@"[Kai]: Reordering kai"); 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 %end

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

</dict> </dict>
<dict> <dict>
<key>cell</key> <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> <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> <key>PostNotification</key>
<string>com.burritoz.kaiprefs.apply</string> <string>com.burritoz.kaiprefs.apply</string>
</dict>
</dict>
<dict> <dict>
<key>cell</key> <key>cell</key>
<string>PSGroupCell</string> <string>PSGroupCell</string>

Loading…
Cancel
Save