mirror of
https://github.com/arichornlover/uYouEnhanced.git
synced 2026-01-11 22:40:19 +00:00
72 lines
3.1 KiB
Objective-C
72 lines
3.1 KiB
Objective-C
#import "ColourOptionsController.h"
|
|
#import "uYouPlus.h"
|
|
|
|
@interface ColourOptionsController ()
|
|
@end
|
|
|
|
@implementation ColourOptionsController
|
|
|
|
- (void)loadView {
|
|
[super loadView];
|
|
|
|
self.title = @"Custom Theme Color";
|
|
|
|
UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(close)];
|
|
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(save)];
|
|
self.navigationItem.rightBarButtonItems = @[closeButton, saveButton];
|
|
|
|
UIBarButtonItem *resetButton = [[UIBarButtonItem alloc] initWithTitle:@"Reset" style:UIBarButtonItemStylePlain target:self action:@selector(reset)];
|
|
self.navigationItem.leftBarButtonItem = resetButton;
|
|
|
|
self.supportsAlpha = NO;
|
|
NSData *colorData = [[NSUserDefaults standardUserDefaults] objectForKey:@"kCustomThemeColor"];
|
|
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:colorData error:nil];
|
|
[unarchiver setRequiresSecureCoding:NO];
|
|
UIColor *color = [unarchiver decodeObjectForKey:NSKeyedArchiveRootObjectKey];
|
|
self.selectedColor = color;
|
|
|
|
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
|
|
CGFloat scale = MIN(self.view.bounds.size.width / 768, self.view.bounds.size.height / 1024);
|
|
self.view.transform = CGAffineTransformMakeScale(scale, scale);
|
|
}
|
|
}
|
|
|
|
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
|
|
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
|
|
|
|
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad && UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
|
|
CGFloat scale = MIN(size.width / 768, size.height / 1024);
|
|
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
|
|
self.view.transform = CGAffineTransformMakeScale(scale, scale);
|
|
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
|
|
}];
|
|
}
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation ColourOptionsController(Privates)
|
|
|
|
- (void)close {
|
|
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
|
|
}
|
|
|
|
- (void)save {
|
|
NSData *colorData = [NSKeyedArchiver archivedDataWithRootObject:self.selectedColor requiringSecureCoding:nil error:nil];
|
|
[[NSUserDefaults standardUserDefaults] setObject:colorData forKey:@"kCustomThemeColor"];
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
|
UIAlertController *alertSaved = [UIAlertController alertControllerWithTitle:@"Color Saved" message:nil preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
[alertSaved addAction:[UIAlertAction actionWithTitle:@"Okay" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
|
|
}]];
|
|
|
|
[self presentViewController:alertSaved animated:YES completion:nil];
|
|
}
|
|
|
|
- (void)reset {
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"kCustomThemeColor"];
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
}
|
|
|
|
@end
|