forked from dayanch96/YTMusicUltimate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSeekButtons.x
97 lines (74 loc) · 3.8 KB
/
SeekButtons.x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#import "Headers/YTMNowPlayingViewController.h"
#import "Headers/YTMNowPlayingView.h"
#import "Headers/YTAssetLoader.h"
#import "Headers/Localization.h"
static NSInteger seekTime() {
NSDictionary *YTMUltimateDict = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"YTMUltimate"];
if (YTMUltimateDict && YTMUltimateDict[@"seekTime"]) {
NSInteger index = [YTMUltimateDict[@"seekTime"] integerValue];
NSArray *seekTimes = @[@0, @10, @20, @30, @60];
return [seekTimes[index] integerValue];
}
return 0;
}
static BOOL YTMU(NSString *key) {
NSDictionary *YTMUltimateDict = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"YTMUltimate"];
return [YTMUltimateDict[key] boolValue];
}
%hook YTMNowPlayingViewController
- (void)viewDidLoad {
%orig;
if (!YTMU(@"YTMUltimateIsEnabled") || !YTMU(@"seekButtons")) {
return;
}
YTMNowPlayingView *nowPlayingView = [self valueForKey:@"_nowPlayingView"];
if (nowPlayingView) {
YTMPlayerControlsView *controlsView = nowPlayingView.playerControlsView;
[controlsView.prevButton removeTarget:self action:@selector(didTapPrevButton) forControlEvents:UIControlEventTouchUpInside];
[controlsView.nextButton removeTarget:self action:@selector(didTapNextButton) forControlEvents:UIControlEventTouchUpInside];
[controlsView.prevButton addTarget:self action:@selector(didTapSeekBackwardButton) forControlEvents:UIControlEventTouchUpInside];
[controlsView.nextButton addTarget:self action:@selector(didTapSeekForwardButton) forControlEvents:UIControlEventTouchUpInside];
UILongPressGestureRecognizer *longPressPrev = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressPrev:)];
[longPressPrev setMinimumPressDuration:0.5];
[controlsView.prevButton addGestureRecognizer:longPressPrev];
UILongPressGestureRecognizer *longPressNext = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressNext:)];
[longPressNext setMinimumPressDuration:0.5];
[controlsView.nextButton addGestureRecognizer:longPressNext];
NSInteger backValue = seekTime() == 0 ? 10 : seekTime();
NSInteger forwardValue = seekTime() == 0 ? 30 : seekTime();
YTAssetLoader *al = [[%c(YTAssetLoader) alloc] initWithBundle:[NSBundle mainBundle]];
UIImage *backImage = [al imageNamed:[NSString stringWithFormat:@"ic_seek_back_%ld_40", backValue]];
UIImage *forwardImage = [al imageNamed:[NSString stringWithFormat:@"ic_seek_forward_%ld_40", forwardValue]];
[controlsView.prevButton setImage:backImage forState:UIControlStateNormal];
[controlsView.prevButton setImage:backImage forState:UIControlStateSelected];
[controlsView.nextButton setImage:forwardImage forState:UIControlStateNormal];
[controlsView.nextButton setImage:forwardImage forState:UIControlStateSelected];
}
}
// - (void)didTapPrevButton {
// YTMU(@"YTMUltimateIsEnabled") && YTMU(@"seekButtons") ? [self didTapSeekBackwardButton] : %orig;
// }
// - (void)didTapNextButton {
// YTMU(@"YTMUltimateIsEnabled") && YTMU(@"seekButtons") ? [self didTapSeekForwardButton] : %orig;
// }
%new
- (void)longPressPrev:(UILongPressGestureRecognizer *)gesture {
if (gesture.state == UIGestureRecognizerStateBegan) {
[self didTapPrevButton];
}
}
%new
- (void)longPressNext:(UILongPressGestureRecognizer *)gesture {
if (gesture.state == UIGestureRecognizerStateBegan) {
[self didTapNextButton];
}
}
%end
%hook YTColdConfig
- (NSInteger)iosPlayerClientSharedConfigTransportControlsSeekForwardTime {
return (seekTime() == 0) ? %orig : seekTime();
}
- (NSInteger)iosPlayerClientSharedConfigTransportControlsSeekBackwardTime {
return (seekTime() == 0) ? %orig : seekTime();
}
%end