mirror of
https://github.com/arichornlover/uYouEnhanced.git
synced 2026-05-15 16:23:31 +00:00
Better remove space implementation
This commit is contained in:
parent
12a8f227e0
commit
da933fd188
2 changed files with 86 additions and 45 deletions
|
|
@ -277,55 +277,96 @@ BOOL isAd(YTIElementRenderer *self) {
|
||||||
// Hide Premium promos in "You" and "Library" tab - @bhackel
|
// Hide Premium promos in "You" and "Library" tab - @bhackel
|
||||||
%group gHidePremiumPromos
|
%group gHidePremiumPromos
|
||||||
// Hide "Get Youtube Premium" in the "You" tab
|
// Hide "Get Youtube Premium" in the "You" tab
|
||||||
%hook YTLinkCell
|
%hook YTAsyncCollectionView
|
||||||
|
// Property for tracking if the cell was hidden
|
||||||
- (void)layoutSubviews {
|
- (void)layoutSubviews {
|
||||||
%orig;
|
%orig;
|
||||||
// Get the badge of this cell, as it is language-independent and unique
|
// Check each subview for the "Get YouTube Premium" cell
|
||||||
YTIconBadgeView *badgeView = [self valueForKey:@"_iconBadgeView"];
|
UIView *foundSubview = nil;
|
||||||
// First null check for badgeView
|
for (UIView *subview in self.subviews) {
|
||||||
if (!badgeView) {
|
// The cell is of type YTLinkCell
|
||||||
return;
|
if (![subview isKindOfClass:NSClassFromString(@"YTLinkCell")]) {
|
||||||
}
|
continue;
|
||||||
// Walk down the subviews to get to a specific view
|
|
||||||
UIView *subview = badgeView.subviews.firstObject;
|
|
||||||
// Second null check for the first subview
|
|
||||||
if (!subview) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
UIImageView *imageView = subview.subviews.firstObject;
|
|
||||||
// Third null/inavlid check for the imageView
|
|
||||||
if (!imageView || ![imageView respondsToSelector:@selector(description)]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Get the description of this view
|
|
||||||
NSString *description = [imageView description];
|
|
||||||
// Check if "yt_outline_youtube_logo_icon" is in the description
|
|
||||||
if ([description containsString:@"yt_outline_youtube_logo_icon"]) {
|
|
||||||
// Only perform changes once
|
|
||||||
if (self.hidden) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// Move all subviews that are below this one upwards to remove blank space
|
// Get the badge of this cell, as it is language-independent and unique
|
||||||
CGFloat viewHeight = self.frame.size.height;
|
YTIconBadgeView *badgeView = [subview valueForKey:@"_iconBadgeView"];
|
||||||
bool foundThisSubview = false;
|
if (!badgeView) {
|
||||||
for (UIView *subview in self.superview.subviews) {
|
continue;
|
||||||
if (foundThisSubview) {
|
}
|
||||||
CGFloat oldX = subview.frame.origin.x;
|
// Walk down the subviews to get to a specific view
|
||||||
CGFloat newY = subview.frame.origin.y - viewHeight;
|
UIView *firstSubview = badgeView.subviews.firstObject;
|
||||||
CGFloat width = subview.frame.size.width;
|
if (!subview) {
|
||||||
CGFloat height = subview.frame.size.height;
|
continue;
|
||||||
subview.frame = CGRectMake(oldX, newY, width, height);
|
}
|
||||||
}
|
UIImageView *secondSubview = firstSubview.subviews.firstObject;
|
||||||
// If we find this subview, we know that all subviews below it are to be moved
|
if (!secondSubview || ![secondSubview respondsToSelector:@selector(description)]) {
|
||||||
if (subview == self) {
|
continue;
|
||||||
foundThisSubview = true;
|
}
|
||||||
}
|
// Check if "yt_outline_youtube_logo_icon" is in the description
|
||||||
|
NSString *description = secondSubview.description;
|
||||||
|
if ([description containsString:@"yt_outline_youtube_logo_icon"]) {
|
||||||
|
foundSubview = subview;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
// Remove this cell from existence
|
|
||||||
self.hidden = YES;
|
|
||||||
self.frame = CGRectZero;
|
|
||||||
[self removeFromSuperview];
|
|
||||||
}
|
}
|
||||||
|
if (self.hidden) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move all subviews that are below this cell upwards to remove blank space
|
||||||
|
CGFloat viewHeight = foundSubview.frame.size.height;
|
||||||
|
bool foundThisSubview = false;
|
||||||
|
// Create a copy of foundSubview.superview.subviews
|
||||||
|
NSArray *subviewsCopy = [foundSubview.superview.subviews copy];
|
||||||
|
for (UIView *subview in subviewsCopy) {
|
||||||
|
if (foundThisSubview) {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Debug"
|
||||||
|
message:@"moved a view up"
|
||||||
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK"
|
||||||
|
style:UIAlertActionStyleDefault
|
||||||
|
handler:nil];
|
||||||
|
|
||||||
|
[alert addAction:okAction];
|
||||||
|
// Find the appropriate view controller to present this alert
|
||||||
|
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
|
||||||
|
while (rootViewController.presentedViewController) {
|
||||||
|
rootViewController = rootViewController.presentedViewController;
|
||||||
|
}
|
||||||
|
[rootViewController presentViewController:alert animated:YES completion:nil];
|
||||||
|
});
|
||||||
|
CGFloat oldX = subview.frame.origin.x;
|
||||||
|
CGFloat newY = subview.frame.origin.y - viewHeight;
|
||||||
|
CGFloat width = subview.frame.size.width;
|
||||||
|
CGFloat height = subview.frame.size.height;
|
||||||
|
subview.frame = CGRectMake(oldX, newY, width, height);
|
||||||
|
}
|
||||||
|
// If we find this subview, we know that all subviews below it are to be moved
|
||||||
|
if (subview == foundSubview) {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Debug"
|
||||||
|
message:@"found this subview"
|
||||||
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK"
|
||||||
|
style:UIAlertActionStyleDefault
|
||||||
|
handler:nil];
|
||||||
|
|
||||||
|
[alert addAction:okAction];
|
||||||
|
// Find the appropriate view controller to present this alert
|
||||||
|
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
|
||||||
|
while (rootViewController.presentedViewController) {
|
||||||
|
rootViewController = rootViewController.presentedViewController;
|
||||||
|
}
|
||||||
|
[rootViewController presentViewController:alert animated:YES completion:nil];
|
||||||
|
});
|
||||||
|
foundThisSubview = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Remove this cell from existence
|
||||||
|
foundSubview.hidden = YES;
|
||||||
|
foundSubview.frame = CGRectZero;
|
||||||
|
|
||||||
}
|
}
|
||||||
%end
|
%end
|
||||||
%end
|
%end
|
||||||
|
|
|
||||||
|
|
@ -275,7 +275,7 @@ extern NSBundle *uYouPlusBundle();
|
||||||
SWITCH_ITEM2(LOC(@"Hide `Your data in YouTube` Section"), LOC(@"App restart is required."), @"disableYourDataInYouTubeSection_enabled");
|
SWITCH_ITEM2(LOC(@"Hide `Your data in YouTube` Section"), LOC(@"App restart is required."), @"disableYourDataInYouTubeSection_enabled");
|
||||||
SWITCH_ITEM2(LOC(@"Hide `Privacy` Section"), LOC(@"App restart is required."), @"disablePrivacySection_enabled");
|
SWITCH_ITEM2(LOC(@"Hide `Privacy` Section"), LOC(@"App restart is required."), @"disablePrivacySection_enabled");
|
||||||
SWITCH_ITEM2(LOC(@"Hide `Live Chat` Section"), LOC(@"App restart is required."), @"disableLiveChatSection_enabled");
|
SWITCH_ITEM2(LOC(@"Hide `Live Chat` Section"), LOC(@"App restart is required."), @"disableLiveChatSection_enabled");
|
||||||
SWITCH_ITEM2(LOC(@"Hide Premium Promos"), LOC(@"App restart is required."), @"hidePremiumPromos_enabled");
|
SWITCH_ITEM2(LOC(@"Hide `Get Youtube Premium` Section"), LOC(@"App restart is required."), @"hidePremiumPromos_enabled");
|
||||||
|
|
||||||
# pragma mark - UI interface options
|
# pragma mark - UI interface options
|
||||||
SECTION_HEADER(LOC(@"UI Interface Options"));
|
SECTION_HEADER(LOC(@"UI Interface Options"));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue