Skip to content

Commit 5bbc01e

Browse files
authored
回滚
1 parent 9de6553 commit 5bbc01e

File tree

1 file changed

+102
-213
lines changed

1 file changed

+102
-213
lines changed

DYYY.xm

Lines changed: 102 additions & 213 deletions
Original file line numberDiff line numberDiff line change
@@ -919,226 +919,116 @@ static UIImage *DYYYLoadCustomImage(NSString *fileName, CGSize targetSize) {
919919
}
920920

921921
%end
922-
923-
// Keeps the forced progress overlay visible without hijacking feed gestures.
924-
static inline void DYYYUpdateProgressOverlayInteractivity(AWEFeedProgressSlider *slider, BOOL allowInteraction) {
925-
if (!slider) {
926-
return;
927-
}
928-
929-
if (slider.userInteractionEnabled != allowInteraction) {
930-
slider.userInteractionEnabled = allowInteraction;
931-
}
932-
933-
UIView *parentView = slider.superview;
934-
if (parentView && parentView.userInteractionEnabled != allowInteraction) {
935-
parentView.userInteractionEnabled = allowInteraction;
936-
}
937-
938-
UIView *controllerView = (UIView *)slider.progressSliderDelegate;
939-
if ([controllerView isKindOfClass:%c(AWEPlayInteractionProgressController)] && controllerView.userInteractionEnabled != allowInteraction) {
940-
controllerView.userInteractionEnabled = allowInteraction;
941-
}
942-
}
943-
944-
static char kDYYYLeftProgressLabelKey;
945-
static char kDYYYRightProgressLabelKey;
946-
static char kDYYYProgressLabelColorKey;
947-
948-
static inline UILabel *DYYYProgressLabel(AWEFeedProgressSlider *slider, BOOL isLeft) { return objc_getAssociatedObject(slider, isLeft ? &kDYYYLeftProgressLabelKey : &kDYYYRightProgressLabelKey); }
949-
950-
static inline void DYYYRemoveProgressLabel(AWEFeedProgressSlider *slider, BOOL isLeft) {
951-
UILabel *label = DYYYProgressLabel(slider, isLeft);
952-
if (!label) {
953-
return;
954-
}
955-
[label removeFromSuperview];
956-
objc_setAssociatedObject(slider, isLeft ? &kDYYYLeftProgressLabelKey : &kDYYYRightProgressLabelKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
957-
}
958-
959-
static inline void DYYYCleanupProgressLabels(AWEFeedProgressSlider *slider) {
960-
DYYYRemoveProgressLabel(slider, YES);
961-
DYYYRemoveProgressLabel(slider, NO);
962-
}
963-
964-
static inline UILabel *DYYYEnsureProgressLabel(AWEFeedProgressSlider *slider, BOOL isLeft, UIFont *font) {
965-
if (!slider) {
966-
return nil;
967-
}
968-
969-
UIView *parentView = slider.superview;
970-
if (!parentView) {
971-
DYYYRemoveProgressLabel(slider, isLeft);
972-
return nil;
973-
}
974-
975-
void *key = isLeft ? &kDYYYLeftProgressLabelKey : &kDYYYRightProgressLabelKey;
976-
UILabel *label = objc_getAssociatedObject(slider, key);
977-
if (!label) {
978-
label = [[UILabel alloc] init];
979-
label.backgroundColor = [UIColor clearColor];
980-
label.font = font;
981-
objc_setAssociatedObject(slider, key, label, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
982-
} else if (font && label.font != font) {
983-
label.font = font;
984-
}
985-
986-
if (label.superview != parentView) {
987-
[label removeFromSuperview];
988-
[parentView addSubview:label];
989-
}
990-
991-
label.hidden = NO;
992-
return label;
993-
}
994-
995-
static inline void DYYYApplyProgressLabelColorIfNeeded(UILabel *label, NSString *colorHexString, BOOL forceApply) {
996-
if (!label) {
997-
return;
998-
}
999-
1000-
NSString *normalizedHex = colorHexString.length > 0 ? colorHexString : nil;
1001-
NSString *lastAppliedHex = objc_getAssociatedObject(label, &kDYYYProgressLabelColorKey);
1002-
BOOL colorChanged = (lastAppliedHex || normalizedHex) && ![lastAppliedHex isEqualToString:normalizedHex];
1003-
1004-
if (!forceApply && !colorChanged) {
1005-
return;
1006-
}
1007-
1008-
objc_setAssociatedObject(label, &kDYYYProgressLabelColorKey, normalizedHex ? [normalizedHex copy] : nil, OBJC_ASSOCIATION_COPY_NONATOMIC);
1009-
[DYYYUtils applyColorSettingsToLabel:label colorHexString:normalizedHex];
1010-
}
1011-
1012922
%hook AWEFeedProgressSlider
1013923

1014924
- (void)setAlpha:(CGFloat)alpha {
1015-
BOOL showScheduleDisplay = DYYYGetBool(@"DYYYShowScheduleDisplay");
1016-
BOOL hideVideoProgress = DYYYGetBool(@"DYYYHideVideoProgress");
1017-
CGFloat requestedAlpha = alpha;
1018-
1019-
if (!showScheduleDisplay) {
1020-
%orig;
1021-
BOOL allowInteraction = requestedAlpha > 0.05f;
1022-
DYYYUpdateProgressOverlayInteractivity(self, allowInteraction);
1023-
return;
1024-
}
1025-
1026-
if (hideVideoProgress) {
1027-
%orig(0.0f);
1028-
if (!self.hidden) {
1029-
self.hidden = YES;
925+
if (DYYYGetBool(@"DYYYShowScheduleDisplay")) {
926+
if (DYYYGetBool(@"DYYYHideVideoProgress")) {
927+
%orig(0);
928+
} else {
929+
%orig(1.0);
1030930
}
1031931
} else {
1032-
%orig(1.0f);
1033-
if (self.hidden) {
1034-
self.hidden = NO;
1035-
}
932+
%orig;
1036933
}
1037-
1038-
BOOL allowInteraction = !hideVideoProgress && requestedAlpha > 0.05f;
1039-
DYYYUpdateProgressOverlayInteractivity(self, allowInteraction);
1040934
}
1041935

936+
static CGFloat leftLabelLeftMargin = -1;
937+
static CGFloat rightLabelRightMargin = -1;
938+
1042939
- (void)setLimitUpperActionArea:(BOOL)arg1 {
1043940
%orig;
1044941

1045-
if (!DYYYGetBool(@"DYYYShowScheduleDisplay")) {
1046-
DYYYCleanupProgressLabels(self);
1047-
[self setNeedsLayout];
1048-
return;
1049-
}
1050-
1051-
UIView *parentView = self.superview;
1052-
if (!parentView) {
1053-
DYYYCleanupProgressLabels(self);
1054-
return;
1055-
}
1056-
1057942
NSString *durationFormatted = [self.progressSliderDelegate formatTimeFromSeconds:floor(self.progressSliderDelegate.model.videoDuration / 1000)];
1058-
NSString *safeDurationString = durationFormatted.length > 0 ? durationFormatted : @"00:00";
1059943

1060-
CGRect sliderOriginalFrameInParent = [self convertRect:self.bounds toView:parentView];
1061-
CGRect sliderFrame = self.frame;
944+
if (DYYYGetBool(@"DYYYShowScheduleDisplay")) {
945+
UIView *parentView = self.superview;
946+
if (!parentView)
947+
return;
1062948

1063-
CGFloat verticalOffset = -12.5;
1064-
NSString *offsetValueString = [[NSUserDefaults standardUserDefaults] objectForKey:@"DYYYTimelineVerticalPosition"];
1065-
if (offsetValueString.length > 0) {
1066-
CGFloat configOffset = [offsetValueString floatValue];
1067-
if (configOffset != 0) {
1068-
verticalOffset = configOffset;
1069-
}
1070-
}
949+
[[parentView viewWithTag:10001] removeFromSuperview];
950+
[[parentView viewWithTag:10002] removeFromSuperview];
1071951

1072-
NSString *scheduleStyle = [[NSUserDefaults standardUserDefaults] objectForKey:@"DYYYScheduleStyle"];
1073-
BOOL showRemainingTime = [scheduleStyle isEqualToString:@"进度条右侧剩余"];
1074-
BOOL showCompleteTime = [scheduleStyle isEqualToString:@"进度条右侧完整"];
1075-
BOOL showLeftRemainingTime = [scheduleStyle isEqualToString:@"进度条左侧剩余"];
1076-
BOOL showLeftCompleteTime = [scheduleStyle isEqualToString:@"进度条左侧完整"];
952+
CGRect sliderOriginalFrameInParent = [self convertRect:self.bounds toView:parentView];
953+
CGRect sliderFrame = self.frame;
1077954

1078-
NSString *labelColorHex = [[NSUserDefaults standardUserDefaults] objectForKey:@"DYYYProgressLabelColor"];
955+
CGFloat verticalOffset = -12.5;
956+
NSString *offsetValueString = [[NSUserDefaults standardUserDefaults] objectForKey:@"DYYYTimelineVerticalPosition"];
957+
if (offsetValueString.length > 0) {
958+
CGFloat configOffset = [offsetValueString floatValue];
959+
if (configOffset != 0)
960+
verticalOffset = configOffset;
961+
}
1079962

1080-
CGFloat labelYPosition = sliderOriginalFrameInParent.origin.y + verticalOffset;
1081-
CGFloat labelHeight = 15.0;
1082-
UIFont *labelFont = [UIFont systemFontOfSize:8];
963+
NSString *scheduleStyle = [[NSUserDefaults standardUserDefaults] objectForKey:@"DYYYScheduleStyle"];
964+
BOOL showRemainingTime = [scheduleStyle isEqualToString:@"进度条右侧剩余"];
965+
BOOL showCompleteTime = [scheduleStyle isEqualToString:@"进度条右侧完整"];
966+
BOOL showLeftRemainingTime = [scheduleStyle isEqualToString:@"进度条左侧剩余"];
967+
BOOL showLeftCompleteTime = [scheduleStyle isEqualToString:@"进度条左侧完整"];
1083968

1084-
BOOL shouldShowLeftLabel = !showRemainingTime && !showCompleteTime;
1085-
BOOL shouldShowRightLabel = !showLeftRemainingTime && !showLeftCompleteTime;
969+
NSString *labelColorHex = [[NSUserDefaults standardUserDefaults] objectForKey:@"DYYYProgressLabelColor"];
1086970

1087-
if (shouldShowLeftLabel) {
1088-
UILabel *leftLabel = DYYYEnsureProgressLabel(self, YES, labelFont);
1089-
if (leftLabel) {
1090-
NSString *placeholderText = showLeftCompleteTime ? [NSString stringWithFormat:@"00:00/%@", safeDurationString] : @"00:00";
1091-
NSString *existingLeftText = leftLabel.text ?: @"";
1092-
BOOL leftTextChanged = ![existingLeftText isEqualToString:placeholderText];
1093-
if (leftTextChanged) {
1094-
leftLabel.text = placeholderText;
1095-
[leftLabel sizeToFit];
971+
CGFloat labelYPosition = sliderOriginalFrameInParent.origin.y + verticalOffset;
972+
CGFloat labelHeight = 15.0;
973+
UIFont *labelFont = [UIFont systemFontOfSize:8];
974+
975+
if (!showRemainingTime && !showCompleteTime) {
976+
UILabel *leftLabel = [[UILabel alloc] init];
977+
leftLabel.backgroundColor = [UIColor clearColor];
978+
leftLabel.font = labelFont;
979+
leftLabel.tag = 10001;
980+
if (showLeftRemainingTime)
981+
leftLabel.text = @"00:00";
982+
else if (showLeftCompleteTime)
983+
leftLabel.text = [NSString stringWithFormat:@"00:00/%@", durationFormatted];
984+
else
985+
leftLabel.text = @"00:00";
986+
987+
[leftLabel sizeToFit];
988+
989+
if (leftLabelLeftMargin == -1) {
990+
leftLabelLeftMargin = sliderFrame.origin.x;
1096991
}
1097992

1098-
CGRect leftFrame = leftLabel.frame;
1099-
leftFrame.origin.x = sliderFrame.origin.x;
1100-
leftFrame.origin.y = labelYPosition;
1101-
leftFrame.size.height = labelHeight;
1102-
leftLabel.frame = leftFrame;
993+
leftLabel.frame = CGRectMake(leftLabelLeftMargin, labelYPosition, leftLabel.frame.size.width, labelHeight);
994+
[parentView addSubview:leftLabel];
1103995

1104-
DYYYApplyProgressLabelColorIfNeeded(leftLabel, labelColorHex, leftTextChanged);
996+
[DYYYUtils applyColorSettingsToLabel:leftLabel colorHexString:labelColorHex];
1105997
}
1106-
} else {
1107-
DYYYRemoveProgressLabel(self, YES);
1108-
}
1109998

1110-
if (shouldShowRightLabel) {
1111-
UILabel *rightLabel = DYYYEnsureProgressLabel(self, NO, labelFont);
1112-
if (rightLabel) {
1113-
NSString *placeholderText;
1114-
if (showRemainingTime) {
1115-
placeholderText = @"00:00";
1116-
} else if (showCompleteTime) {
1117-
placeholderText = [NSString stringWithFormat:@"00:00/%@", safeDurationString];
1118-
} else {
1119-
placeholderText = safeDurationString;
1120-
}
999+
if (!showLeftRemainingTime && !showLeftCompleteTime) {
1000+
UILabel *rightLabel = [[UILabel alloc] init];
1001+
rightLabel.backgroundColor = [UIColor clearColor];
1002+
rightLabel.font = labelFont;
1003+
rightLabel.tag = 10002;
1004+
if (showRemainingTime)
1005+
rightLabel.text = @"00:00";
1006+
else if (showCompleteTime)
1007+
rightLabel.text = [NSString stringWithFormat:@"00:00/%@", durationFormatted];
1008+
else
1009+
rightLabel.text = durationFormatted;
11211010

1122-
NSString *existingRightText = rightLabel.text ?: @"";
1123-
BOOL rightTextChanged = ![existingRightText isEqualToString:placeholderText];
1124-
if (rightTextChanged) {
1125-
rightLabel.text = placeholderText;
1126-
[rightLabel sizeToFit];
1011+
[rightLabel sizeToFit];
1012+
1013+
if (rightLabelRightMargin == -1) {
1014+
rightLabelRightMargin = sliderFrame.origin.x + sliderFrame.size.width - rightLabel.frame.size.width;
11271015
}
11281016

1129-
CGRect rightFrame = rightLabel.frame;
1130-
rightFrame.origin.x = sliderFrame.origin.x + sliderFrame.size.width - CGRectGetWidth(rightFrame);
1131-
rightFrame.origin.y = labelYPosition;
1132-
rightFrame.size.height = labelHeight;
1133-
rightLabel.frame = rightFrame;
1017+
rightLabel.frame = CGRectMake(rightLabelRightMargin, labelYPosition, rightLabel.frame.size.width, labelHeight);
1018+
[parentView addSubview:rightLabel];
11341019

1135-
DYYYApplyProgressLabelColorIfNeeded(rightLabel, labelColorHex, rightTextChanged);
1020+
[DYYYUtils applyColorSettingsToLabel:rightLabel colorHexString:labelColorHex];
11361021
}
1022+
1023+
[self setNeedsLayout];
11371024
} else {
1138-
DYYYRemoveProgressLabel(self, NO);
1025+
UIView *parentView = self.superview;
1026+
if (parentView) {
1027+
[[parentView viewWithTag:10001] removeFromSuperview];
1028+
[[parentView viewWithTag:10002] removeFromSuperview];
1029+
}
1030+
[self setNeedsLayout];
11391031
}
1140-
1141-
[self setNeedsLayout];
11421032
}
11431033

11441034
%end
@@ -1163,12 +1053,12 @@ static inline void DYYYApplyProgressLabelColorIfNeeded(UILabel *label, NSString
11631053

11641054
if (DYYYGetBool(@"DYYYShowScheduleDisplay")) {
11651055
AWEFeedProgressSlider *progressSlider = self.progressSlider;
1166-
if (!progressSlider) {
1056+
UIView *parentView = progressSlider.superview;
1057+
if (!parentView)
11671058
return;
1168-
}
11691059

1170-
UILabel *leftLabel = DYYYProgressLabel(progressSlider, YES);
1171-
UILabel *rightLabel = DYYYProgressLabel(progressSlider, NO);
1060+
UILabel *leftLabel = [parentView viewWithTag:10001];
1061+
UILabel *rightLabel = [parentView viewWithTag:10002];
11721062

11731063
NSString *labelColorHex = [[NSUserDefaults standardUserDefaults] objectForKey:@"DYYYProgressLabelColor"];
11741064

@@ -1177,8 +1067,6 @@ static inline void DYYYApplyProgressLabelColorIfNeeded(UILabel *label, NSString
11771067
BOOL showCompleteTime = [scheduleStyle isEqualToString:@"进度条右侧完整"];
11781068
BOOL showLeftRemainingTime = [scheduleStyle isEqualToString:@"进度条左侧剩余"];
11791069
BOOL showLeftCompleteTime = [scheduleStyle isEqualToString:@"进度条左侧完整"];
1180-
CGRect sliderFrame = progressSlider.frame;
1181-
CGFloat labelHeight = 15.0f;
11821070

11831071
// 更新左标签
11841072
if (arg1 >= 0 && leftLabel) {
@@ -1194,18 +1082,14 @@ static inline void DYYYApplyProgressLabelColorIfNeeded(UILabel *label, NSString
11941082
newLeftText = [self formatTimeFromSeconds:arg1];
11951083
}
11961084

1197-
NSString *existingLeftText = leftLabel.text ?: @"";
1198-
BOOL leftTextChanged = ![existingLeftText isEqualToString:newLeftText];
1199-
CGRect leftFrame = leftLabel.frame;
1200-
if (leftTextChanged) {
1085+
if (![leftLabel.text isEqualToString:newLeftText]) {
12011086
leftLabel.text = newLeftText;
12021087
[leftLabel sizeToFit];
1203-
leftFrame = leftLabel.frame;
1088+
CGRect leftFrame = leftLabel.frame;
1089+
leftFrame.size.height = 15.0;
1090+
leftLabel.frame = leftFrame;
12041091
}
1205-
leftFrame.origin.x = sliderFrame.origin.x;
1206-
leftFrame.size.height = labelHeight;
1207-
leftLabel.frame = leftFrame;
1208-
DYYYApplyProgressLabelColorIfNeeded(leftLabel, labelColorHex, leftTextChanged);
1092+
[DYYYUtils applyColorSettingsToLabel:leftLabel colorHexString:labelColorHex];
12091093
}
12101094

12111095
// 更新右标签
@@ -1222,22 +1106,27 @@ static inline void DYYYApplyProgressLabelColorIfNeeded(UILabel *label, NSString
12221106
newRightText = [self formatTimeFromSeconds:arg2];
12231107
}
12241108

1225-
NSString *existingRightText = rightLabel.text ?: @"";
1226-
BOOL rightTextChanged = ![existingRightText isEqualToString:newRightText];
1227-
CGRect rightFrame = rightLabel.frame;
1228-
if (rightTextChanged) {
1109+
if (![rightLabel.text isEqualToString:newRightText]) {
12291110
rightLabel.text = newRightText;
12301111
[rightLabel sizeToFit];
1231-
rightFrame = rightLabel.frame;
1112+
CGRect rightFrame = rightLabel.frame;
1113+
rightFrame.size.height = 15.0;
1114+
rightLabel.frame = rightFrame;
12321115
}
1233-
rightFrame.origin.x = sliderFrame.origin.x + sliderFrame.size.width - CGRectGetWidth(rightFrame);
1234-
rightFrame.size.height = labelHeight;
1235-
rightLabel.frame = rightFrame;
1236-
DYYYApplyProgressLabelColorIfNeeded(rightLabel, labelColorHex, rightTextChanged);
1116+
[DYYYUtils applyColorSettingsToLabel:rightLabel colorHexString:labelColorHex];
12371117
}
12381118
}
12391119
}
12401120

1121+
- (void)setHidden:(BOOL)hidden {
1122+
%orig;
1123+
BOOL hideVideoProgress = DYYYGetBool(@"DYYYHideVideoProgress");
1124+
BOOL showScheduleDisplay = DYYYGetBool(@"DYYYShowScheduleDisplay");
1125+
if (hideVideoProgress && showScheduleDisplay && !hidden) {
1126+
self.alpha = 0;
1127+
}
1128+
}
1129+
12411130
%end
12421131

12431132
%hook AWEPlayInteractionTimestampElement

0 commit comments

Comments
 (0)