This repository has been archived by the owner on Jun 19, 2023. It is now read-only.
forked from Galactic-Dev/iSponsorBlock
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSponsorBlockViewController.m
412 lines (349 loc) · 25.8 KB
/
SponsorBlockViewController.m
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#import "SponsorBlockViewController.h"
@implementation SponsorBlockViewController
-(void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor systemBackgroundColor];
[self addChildViewController:self.playerViewController];
[self.view addSubview:self.playerViewController.view];
[self setupViews];
}
-(void)setupViews {
[self.segmentsInDatabaseLabel removeFromSuperview];
[self.userSegmentsLabel removeFromSuperview];
[self.submitSegmentsButton removeFromSuperview];
[self.whitelistChannelLabel removeFromSuperview];
self.sponsorSegmentViews = [NSMutableArray array];
self.userSponsorSegmentViews = [NSMutableArray array];
if(!self.startEndSegmentButton){
self.startEndSegmentButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.startEndSegmentButton.backgroundColor = UIColor.systemBlueColor;
[self.startEndSegmentButton addTarget:self action:@selector(startEndSegmentButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
if(self.playerViewController.userSkipSegments.lastObject.endTime != -1) [self.startEndSegmentButton setTitle:@"Segment Starts Now" forState:UIControlStateNormal];
else [self.startEndSegmentButton setTitle:@"Segment Ends Now" forState:UIControlStateNormal];
self.startEndSegmentButton.titleLabel.adjustsFontSizeToFitWidth = YES;
[self.playerViewController.view addSubview:self.startEndSegmentButton];
self.startEndSegmentButton.layer.cornerRadius = 12;
self.startEndSegmentButton.frame = CGRectMake(0,0,512,50);
self.startEndSegmentButton.translatesAutoresizingMaskIntoConstraints = NO;
[self.startEndSegmentButton.topAnchor constraintEqualToAnchor:self.playerViewController.view.bottomAnchor constant:10].active = YES;
[self.startEndSegmentButton.centerXAnchor constraintEqualToAnchor:self.playerViewController.view.centerXAnchor].active = YES;
[self.startEndSegmentButton.widthAnchor constraintEqualToConstant:self.view.frame.size.width/2].active = YES;
[self.startEndSegmentButton.heightAnchor constraintEqualToConstant:50].active = YES;
self.startEndSegmentButton.clipsToBounds = YES;
}
self.whitelistChannelLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.whitelistChannelLabel.text = @"Whitelist Channel";
[self.playerViewController.view addSubview:self.whitelistChannelLabel];
self.whitelistChannelLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.whitelistChannelLabel.topAnchor constraintEqualToAnchor:self.startEndSegmentButton.bottomAnchor constant:10].active = YES;
[self.whitelistChannelLabel.centerXAnchor constraintEqualToAnchor:self.startEndSegmentButton.centerXAnchor].active = YES;
[self.whitelistChannelLabel.widthAnchor constraintEqualToConstant:185].active = YES;
[self.whitelistChannelLabel.heightAnchor constraintEqualToConstant:31].active = YES;
self.whitelistChannelLabel.userInteractionEnabled = YES;
UISwitch *whitelistSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0,0,51,31)];
[whitelistSwitch addTarget:self action:@selector(whitelistSwitchToggled:) forControlEvents:UIControlEventValueChanged];
[self.whitelistChannelLabel addSubview:whitelistSwitch];
whitelistSwitch.translatesAutoresizingMaskIntoConstraints = NO;
[whitelistSwitch.leadingAnchor constraintEqualToAnchor:self.whitelistChannelLabel.trailingAnchor constant:-51].active = YES;
[whitelistSwitch.centerYAnchor constraintEqualToAnchor:self.whitelistChannelLabel.centerYAnchor].active = YES;
if([kWhitelistedChannels containsObject:self.playerViewController.channelID]) {
[whitelistSwitch setOn:YES animated:NO];
}
else {
[whitelistSwitch setOn:NO animated:NO];
}
//I'm using the playerBar skipSegments instead of the playerViewController ones because of the show in seek bar option
if([self.playerViewController.view.overlayView.playerBar.playerBar skipSegments].count > 0 || self.playerViewController.view.overlayView.playerBar.segmentablePlayerBar.skipSegments.count > 0) {
self.segmentsInDatabaseLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.segmentsInDatabaseLabel.userInteractionEnabled = YES;
self.segmentsInDatabaseLabel.text = @"There are already segments in the database:";
self.segmentsInDatabaseLabel.numberOfLines = 1;
self.segmentsInDatabaseLabel.adjustsFontSizeToFitWidth = YES;
self.segmentsInDatabaseLabel.textAlignment = NSTextAlignmentCenter;
[self.playerViewController.view addSubview:self.segmentsInDatabaseLabel];
self.segmentsInDatabaseLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.segmentsInDatabaseLabel.topAnchor constraintEqualToAnchor:self.whitelistChannelLabel.bottomAnchor constant:-15].active = YES;
[self.segmentsInDatabaseLabel.centerXAnchor constraintEqualToAnchor:self.playerViewController.view.centerXAnchor].active = YES;
[self.segmentsInDatabaseLabel.widthAnchor constraintEqualToAnchor:self.playerViewController.view.widthAnchor].active = YES;
[self.segmentsInDatabaseLabel.heightAnchor constraintEqualToConstant:75.0f].active = YES;
NSArray *segmentViewsForSegments;
if(self.playerViewController.view.overlayView.playerBar.playerBar) {
segmentViewsForSegments = self.playerViewController.view.overlayView.playerBar.playerBar.skipSegments;
}
else {
segmentViewsForSegments = self.playerViewController.view.overlayView.playerBar.segmentablePlayerBar.skipSegments;
}
self.sponsorSegmentViews = [self segmentViewsForSegments:segmentViewsForSegments editable:NO];
for(int i = 0; i < self.sponsorSegmentViews.count; i++) {
[self.segmentsInDatabaseLabel addSubview:self.sponsorSegmentViews[i]];
[self.sponsorSegmentViews[i] addInteraction:[[UIContextMenuInteraction alloc] initWithDelegate:self]];
self.sponsorSegmentViews[i].translatesAutoresizingMaskIntoConstraints = NO;
[self.sponsorSegmentViews[i].widthAnchor constraintEqualToConstant:self.playerViewController.view.frame.size.width/self.sponsorSegmentViews.count-10].active = YES;
[self.sponsorSegmentViews[i].heightAnchor constraintEqualToConstant:30].active = YES;
[self.sponsorSegmentViews[i].topAnchor constraintEqualToAnchor:self.segmentsInDatabaseLabel.bottomAnchor constant:-25].active = YES;
if(self.sponsorSegmentViews.count == 1) {
[self.sponsorSegmentViews[i].centerXAnchor constraintEqualToAnchor:self.segmentsInDatabaseLabel.centerXAnchor].active = YES;
break;
}
if(i > 0){
[self.sponsorSegmentViews[i].leftAnchor constraintEqualToAnchor:self.sponsorSegmentViews[i-1].rightAnchor constant:5].active = YES;
}
else {
[self.sponsorSegmentViews[i].leftAnchor constraintEqualToAnchor:self.segmentsInDatabaseLabel.leftAnchor constant:5*(self.sponsorSegmentViews.count / 2)].active = YES;
}
}
}
if(self.playerViewController.userSkipSegments.count > 0){
self.userSegmentsLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.userSegmentsLabel.userInteractionEnabled = YES;
self.userSegmentsLabel.text = @"Your Segments:";
self.userSponsorSegmentViews = [self segmentViewsForSegments:self.playerViewController.userSkipSegments editable:YES];
for(int i = 0; i < self.userSponsorSegmentViews.count; i++){
[self.userSegmentsLabel addSubview:self.userSponsorSegmentViews[i]];
[self.userSponsorSegmentViews[i] addInteraction:[[UIContextMenuInteraction alloc] initWithDelegate:self]];
self.userSponsorSegmentViews[i].translatesAutoresizingMaskIntoConstraints = NO;
[self.userSponsorSegmentViews[i].widthAnchor constraintEqualToConstant:self.playerViewController.view.frame.size.width/self.userSponsorSegmentViews.count-10].active = YES;
[self.userSponsorSegmentViews[i].heightAnchor constraintEqualToConstant:30].active = YES;
[self.userSponsorSegmentViews[i].topAnchor constraintEqualToAnchor:self.userSegmentsLabel.bottomAnchor constant:-25].active = YES;
if(self.userSponsorSegmentViews.count == 1) {
[self.userSponsorSegmentViews[i].centerXAnchor constraintEqualToAnchor:self.userSegmentsLabel.centerXAnchor].active = YES;
break;
}
if(i > 0){
[self.userSponsorSegmentViews[i].leftAnchor constraintEqualToAnchor:self.userSponsorSegmentViews[i-1].rightAnchor constant:5].active = YES;
}
else {
[self.userSponsorSegmentViews[i].leftAnchor constraintEqualToAnchor:self.userSegmentsLabel.leftAnchor constant:5*(self.userSponsorSegmentViews.count / 2)].active = YES;
}
}
self.userSegmentsLabel.numberOfLines = 2;
self.userSegmentsLabel.adjustsFontSizeToFitWidth = YES;
self.userSegmentsLabel.textAlignment = NSTextAlignmentCenter;
[self.playerViewController.view addSubview:self.userSegmentsLabel];
self.userSegmentsLabel.translatesAutoresizingMaskIntoConstraints = NO;
if([self.playerViewController.view.overlayView.playerBar.playerBar skipSegments].count > 0 || self.playerViewController.view.overlayView.playerBar.segmentablePlayerBar.skipSegments.count > 0) [self.userSegmentsLabel.topAnchor constraintEqualToAnchor:self.segmentsInDatabaseLabel.bottomAnchor constant:-10].active = YES;
else [self.userSegmentsLabel.topAnchor constraintEqualToAnchor:self.whitelistChannelLabel.bottomAnchor constant:-10].active = YES;
[self.userSegmentsLabel.centerXAnchor constraintEqualToAnchor:self.playerViewController.view.centerXAnchor].active = YES;
[self.userSegmentsLabel.widthAnchor constraintEqualToAnchor:self.playerViewController.view.widthAnchor].active = YES;
[self.userSegmentsLabel.heightAnchor constraintEqualToConstant:75.0f].active = YES;
self.submitSegmentsButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.submitSegmentsButton.backgroundColor = UIColor.systemBlueColor;
[self.submitSegmentsButton addTarget:self action:@selector(submitSegmentsButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.submitSegmentsButton setTitle:@"Submit Segments" forState:UIControlStateNormal];
[self.playerViewController.view addSubview:self.submitSegmentsButton];
self.submitSegmentsButton.layer.cornerRadius = 12;
self.submitSegmentsButton.frame = CGRectMake(0,0,512,50);
self.submitSegmentsButton.translatesAutoresizingMaskIntoConstraints = NO;
[self.submitSegmentsButton.topAnchor constraintEqualToAnchor:self.userSegmentsLabel.bottomAnchor constant:15].active = YES;
[self.submitSegmentsButton.centerXAnchor constraintEqualToAnchor:self.playerViewController.view.centerXAnchor].active = YES;
[self.submitSegmentsButton.widthAnchor constraintEqualToConstant:self.view.frame.size.width/2].active = YES;
[self.submitSegmentsButton.heightAnchor constraintEqualToConstant:50].active = YES;
self.submitSegmentsButton.clipsToBounds = YES;
}
}
-(void)whitelistSwitchToggled:(UISwitch *)sender {
if(sender.isOn) {
[kWhitelistedChannels addObject:self.playerViewController.channelID];
}
else {
[kWhitelistedChannels removeObject:self.playerViewController.channelID];
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *settingsPath = [documentsDirectory stringByAppendingPathComponent:@"iSponsorBlock.plist"];
NSMutableDictionary *settings = [NSMutableDictionary dictionary];
[settings addEntriesFromDictionary:[NSDictionary dictionaryWithContentsOfFile:settingsPath]];
[settings setValue:kWhitelistedChannels forKey:@"whitelistedChannels"];
[settings writeToURL:[NSURL fileURLWithPath:settingsPath isDirectory:NO] error:nil];
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("com.galacticdev.isponsorblockprefs.changed"), NULL, NULL, YES);
}
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
[self.startEndSegmentButton removeFromSuperview];
[self.segmentsInDatabaseLabel removeFromSuperview];
[self.userSegmentsLabel removeFromSuperview];
[self.submitSegmentsButton removeFromSuperview];
[self.whitelistChannelLabel removeFromSuperview];
[self.previousParentViewController addChildViewController:self.playerViewController];
[self.previousParentViewController.view addSubview:self.playerViewController.view];
self.overlayView.isDisplayingSponsorBlockViewController = NO;
self.overlayView.sponsorBlockButton.hidden = NO;
self.overlayView.sponsorStartedEndedButton.hidden = NO;
[self.overlayView setOverlayVisible:YES];
}
-(void)startEndSegmentButtonPressed:(UIButton *)sender {
if([sender.titleLabel.text isEqualToString:@"Segment Starts Now"]){
[self.playerViewController.userSkipSegments addObject:[[SponsorSegment alloc] initWithStartTime:self.playerViewController.currentVideoMediaTime endTime:-1 category:nil UUID:nil]];
[sender setTitle:@"Segment Ends Now" forState:UIControlStateNormal];
}
else {
self.playerViewController.userSkipSegments.lastObject.endTime = self.playerViewController.currentVideoMediaTime;
if(self.playerViewController.userSkipSegments.lastObject.endTime != self.playerViewController.currentVideoMediaTime) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Error" message:[NSString stringWithFormat:@"End Time That You Set Was Less Than the Start Time, Please Select a Time After %ld:%02ld",lroundf(self.playerViewController.userSkipSegments.lastObject.startTime)/60, lroundf(self.playerViewController.userSkipSegments.lastObject.startTime)%60] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
return;
}
[sender setTitle:@"Segment Starts Now" forState:UIControlStateNormal];
}
[self setupViews];
}
-(void)submitSegmentsButtonPressed:(UIButton *)sender {
for(SponsorSegment *segment in self.playerViewController.userSkipSegments) {
if(segment.endTime == -1 || !segment.category) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Error" message:@"You Have Unfinished Segments\n Please Add a Category and/or End Time to Your Segments" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
return;
}
}
[SponsorBlockRequest postSponsorTimes:self.playerViewController.currentVideoID sponsorSegments:self.playerViewController.userSkipSegments userID:kUserID withViewController:self.previousParentViewController];
[self.previousParentViewController dismissViewControllerAnimated:YES completion:nil];
}
-(NSMutableArray *)segmentViewsForSegments:(NSArray <SponsorSegment *> *)segments editable:(BOOL)editable{
for(SponsorSegment *segment in segments){
if(!editable){
[self.sponsorSegmentViews addObject:[[SponsorSegmentView alloc] initWithFrame:CGRectMake(0,0,50,30) sponsorSegment:segment editable:editable]];
}
else {
[self.userSponsorSegmentViews addObject:[[SponsorSegmentView alloc] initWithFrame:CGRectMake(0,0,50,30) sponsorSegment:segment editable:editable]];
}
}
if(!editable) return self.sponsorSegmentViews;
return self.userSponsorSegmentViews;
}
- (UIContextMenuConfiguration *)contextMenuInteraction:(UIContextMenuInteraction *)interaction
configurationForMenuAtLocation:(CGPoint)location {
SponsorSegmentView *sponsorSegmentView = interaction.view;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"iSponsorBlock.plist"];
NSMutableDictionary *settings = [NSMutableDictionary dictionary];
[settings addEntriesFromDictionary:[NSDictionary dictionaryWithContentsOfFile:path]];
UIContextMenuConfiguration *config = [UIContextMenuConfiguration configurationWithIdentifier:nil
previewProvider:nil
actionProvider:^UIMenu* _Nullable(NSArray<UIMenuElement*>* _Nonnull suggestedActions) {
NSMutableArray *categoryActions = [NSMutableArray array];
[categoryActions addObject:[UIAction actionWithTitle:@"Sponsor" image:nil identifier:nil handler:^(__kindof UIAction* _Nonnull action) {
if(sponsorSegmentView.editable) {
sponsorSegmentView.sponsorSegment.category = @"sponsor";
[self setupViews];
return;
}
[SponsorBlockRequest categoryVoteForSegment:sponsorSegmentView.sponsorSegment userID:[settings objectForKey:@"userID"] category:@"sponsor" withViewController:self];
}]];
[categoryActions addObject:[UIAction actionWithTitle:@"Intermission/Intro Animation" image:nil identifier:nil handler:^(__kindof UIAction* _Nonnull action) {
if(sponsorSegmentView.editable) {
sponsorSegmentView.sponsorSegment.category = @"intro";
[self setupViews];
return;
}
[SponsorBlockRequest categoryVoteForSegment:sponsorSegmentView.sponsorSegment userID:[settings objectForKey:@"userID"] category:@"intro" withViewController:self];
}]];
[categoryActions addObject:[UIAction actionWithTitle:@"Outro" image:nil identifier:nil handler:^(__kindof UIAction* _Nonnull action) {
if(sponsorSegmentView.editable) {
sponsorSegmentView.sponsorSegment.category = @"outro";
[self setupViews];
return;
}
[SponsorBlockRequest categoryVoteForSegment:sponsorSegmentView.sponsorSegment userID:[settings objectForKey:@"userID"] category:@"outro" withViewController:self];
}]];
[categoryActions addObject:[UIAction actionWithTitle:@"Interaction Reminder (Subcribe/Like)" image:nil identifier:nil handler:^(__kindof UIAction* _Nonnull action) {
if(sponsorSegmentView.editable) {
sponsorSegmentView.sponsorSegment.category = @"interaction";
[self setupViews];
return;
}
[SponsorBlockRequest categoryVoteForSegment:sponsorSegmentView.sponsorSegment userID:[settings objectForKey:@"userID"] category:@"interaction" withViewController:self];
}]];
[categoryActions addObject:[UIAction actionWithTitle:@"Unpaid/Self Promotion" image:nil identifier:nil handler:^(__kindof UIAction* _Nonnull action) {
if(sponsorSegmentView.editable) {
sponsorSegmentView.sponsorSegment.category = @"selfpromo";
[self setupViews];
return;
}
[SponsorBlockRequest categoryVoteForSegment:sponsorSegmentView.sponsorSegment userID:[settings objectForKey:@"userID"] category:@"selfpromo" withViewController:self];
}]];
[categoryActions addObject:[UIAction actionWithTitle:@"Music: Non-Music Section" image:nil identifier:nil handler:^(__kindof UIAction* _Nonnull action) {
if(sponsorSegmentView.editable) {
sponsorSegmentView.sponsorSegment.category = @"music_offtopic";
[self setupViews];
return;
}
[SponsorBlockRequest categoryVoteForSegment:sponsorSegmentView.sponsorSegment userID:[settings objectForKey:@"userID"] category:@"music_offtopic" withViewController:self];
}]];
NSMutableArray* actions = [NSMutableArray array];
if (sponsorSegmentView.editable)
{
[actions addObject:[UIAction actionWithTitle:@"Edit Start Time" image:[UIImage systemImageNamed:@"arrow.left.to.line"] identifier:nil handler:^(__kindof UIAction* _Nonnull action) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Edit" message:@"Edit Start Time: (ex. type 1:15)" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
f.numberStyle = NSNumberFormatterDecimalStyle;
NSArray *strings = [alert.textFields[0].text componentsSeparatedByString:@":"];
if(strings.count != 2) return;
NSString *minutesString = strings[0];
NSString *secondsString = strings[1];
CGFloat minutes = [[f numberFromString:minutesString] floatValue];
CGFloat seconds = [[f numberFromString:secondsString] floatValue];
sponsorSegmentView.sponsorSegment.startTime = (minutes*60)+seconds;
[self setupViews];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alert addAction:defaultAction];
[alert addAction:cancelAction];
[alert addTextFieldWithConfigurationHandler:nil];
[self presentViewController:alert animated:YES completion:nil];
}]];
[actions addObject:[UIAction actionWithTitle:@"Edit End Time" image:[UIImage systemImageNamed:@"arrow.right.to.line"] identifier:nil handler:^(__kindof UIAction* _Nonnull action) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Edit" message:@"Edit End Time:" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
f.numberStyle = NSNumberFormatterDecimalStyle;
NSArray *strings = [alert.textFields[0].text componentsSeparatedByString:@":"];
if(strings.count != 2) return;
NSString *minutesString = strings[0];
NSString *secondsString = strings[1];
CGFloat minutes = [[f numberFromString:minutesString] floatValue];
CGFloat seconds = [[f numberFromString:secondsString] floatValue];
sponsorSegmentView.sponsorSegment.endTime = (minutes*60)+seconds;
[self setupViews];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alert addAction:defaultAction];
[alert addAction:cancelAction];
[alert addTextFieldWithConfigurationHandler:nil];
[self presentViewController:alert animated:YES completion:nil];
}]];
UIMenu *categoriesMenu = [UIMenu menuWithTitle:@"Edit Category" image:[UIImage systemImageNamed:@"square.grid.2x2"] identifier:nil options:0 children:categoryActions];
[actions addObject:categoriesMenu];
[actions addObject:[UIAction actionWithTitle:@"Delete" image:[UIImage systemImageNamed:@"trash"] identifier:nil handler:^(__kindof UIAction* _Nonnull action) {
[self.playerViewController.userSkipSegments removeObject:sponsorSegmentView.sponsorSegment];
[self setupViews];
}]];
UIMenu* menu = [UIMenu menuWithTitle:@"Edit Segment" children:actions];
return menu;
}
else {
[actions addObject:[UIAction actionWithTitle:@"Upvote" image:[UIImage systemImageNamed:@"hand.thumbsup.fill"] identifier:nil handler:^(__kindof UIAction* _Nonnull action) {
[SponsorBlockRequest normalVoteForSegment:sponsorSegmentView.sponsorSegment userID:[settings objectForKey:@"userID"] type:YES withViewController:self];
}]];
[actions addObject:[UIAction actionWithTitle:@"Downvote" image:[UIImage systemImageNamed:@"hand.thumbsdown.fill"] identifier:nil handler:^(__kindof UIAction* _Nonnull action) {
[SponsorBlockRequest normalVoteForSegment:sponsorSegmentView.sponsorSegment userID:[settings objectForKey:@"userID"] type:NO withViewController:self];
}]];
UIMenu *categoriesMenu = [UIMenu menuWithTitle:@"Vote to Change Cateogory" image:[UIImage systemImageNamed:@"square.grid.2x2"] identifier:nil options:0 children:categoryActions];
UIMenu* menu = [UIMenu menuWithTitle:@"Vote on Segment" children:[actions arrayByAddingObject:categoriesMenu]];
return menu;
}
}];
return config;
}
@end