mirror of
https://github.com/arichornlover/uYouEnhanced.git
synced 2026-04-21 16:02:00 +00:00
Replace UIAlertView with YTAlertView
This commit is contained in:
parent
d9e66a2422
commit
31e8568c4d
1 changed files with 11 additions and 46 deletions
|
|
@ -4,10 +4,8 @@
|
||||||
@interface AppIconOptionsController () <UITableViewDataSource, UITableViewDelegate>
|
@interface AppIconOptionsController () <UITableViewDataSource, UITableViewDelegate>
|
||||||
|
|
||||||
@property (strong, nonatomic) UITableView *tableView;
|
@property (strong, nonatomic) UITableView *tableView;
|
||||||
@property (strong, nonatomic) UIImageView *iconPreview;
|
|
||||||
@property (strong, nonatomic) NSArray<NSString *> *appIcons;
|
@property (strong, nonatomic) NSArray<NSString *> *appIcons;
|
||||||
@property (assign, nonatomic) NSInteger selectedIconIndex;
|
@property (assign, nonatomic) NSInteger selectedIconIndex;
|
||||||
@property (assign, nonatomic) NSInteger defaultIconIndex;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
@ -23,7 +21,7 @@
|
||||||
[titleLabel sizeToFit];
|
[titleLabel sizeToFit];
|
||||||
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:titleLabel];
|
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:titleLabel];
|
||||||
|
|
||||||
self.selectedIconIndex = 0;
|
self.selectedIconIndex = -1;
|
||||||
|
|
||||||
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
|
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
|
||||||
self.tableView.dataSource = self;
|
self.tableView.dataSource = self;
|
||||||
|
|
@ -42,11 +40,6 @@
|
||||||
|
|
||||||
self.navigationItem.rightBarButtonItems = @[resetButton, saveButton];
|
self.navigationItem.rightBarButtonItems = @[resetButton, saveButton];
|
||||||
|
|
||||||
self.iconPreview = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width - 80, self.view.bounds.size.height - 80, 60, 60)];
|
|
||||||
self.iconPreview.layer.cornerRadius = 10.0;
|
|
||||||
self.iconPreview.clipsToBounds = YES;
|
|
||||||
[self.view addSubview:self.iconPreview];
|
|
||||||
|
|
||||||
NSString *path = [[NSBundle mainBundle] pathForResource:@"uYouPlus" ofType:@"bundle"];
|
NSString *path = [[NSBundle mainBundle] pathForResource:@"uYouPlus" ofType:@"bundle"];
|
||||||
NSBundle *bundle = [NSBundle bundleWithPath:path];
|
NSBundle *bundle = [NSBundle bundleWithPath:path];
|
||||||
self.appIcons = [bundle pathsForResourcesOfType:@"png" inDirectory:@"AppIcons"];
|
self.appIcons = [bundle pathsForResourcesOfType:@"png" inDirectory:@"AppIcons"];
|
||||||
|
|
@ -56,11 +49,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray<NSString *> *)sortedAppIcons {
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger section {
|
||||||
return [self.appIcons sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
||||||
return self.appIcons.count;
|
return self.appIcons.count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,12 +62,12 @@
|
||||||
if (!cell) {
|
if (!cell) {
|
||||||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
|
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
|
||||||
}
|
}
|
||||||
[self sortedAppIcons];
|
|
||||||
NSString *iconPath = self.appIcons[indexPath.row];
|
NSString *iconPath = self.appIcons[indexPath.row];
|
||||||
cell.textLabel.text = [iconPath.lastPathComponent stringByDeletingPathExtension];
|
cell.textLabel.text = [iconPath.lastPathComponent stringByDeletingPathExtension];
|
||||||
|
|
||||||
UIImage *iconImage = [UIImage imageWithContentsOfFile:iconPath];
|
UIImage *iconImage = [UIImage imageWithContentsOfFile:iconPath];
|
||||||
cell.imageView.image = [self resizedImageWithImage:iconImage];
|
cell.imageView.image = iconImage;
|
||||||
cell.imageView.layer.cornerRadius = 10.0;
|
cell.imageView.layer.cornerRadius = 10.0;
|
||||||
cell.imageView.clipsToBounds = YES;
|
cell.imageView.clipsToBounds = YES;
|
||||||
|
|
||||||
|
|
@ -94,16 +83,8 @@
|
||||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||||
|
|
||||||
if (indexPath.row == 0) {
|
self.selectedIconIndex = indexPath.row;
|
||||||
self.selectedIconIndex = -1;
|
[self.tableView reloadData];
|
||||||
[self.tableView reloadData];
|
|
||||||
self.iconPreview.image = nil;
|
|
||||||
} else {
|
|
||||||
self.defaultIconIndex = 0;
|
|
||||||
NSString *selectedIconPath = self.appIcons[indexPath.row - 1];
|
|
||||||
UIImage *selectedIconImage = [UIImage imageWithContentsOfFile:selectedIconPath];
|
|
||||||
self.iconPreview.image = [self resizedImageWithImage:selectedIconImage];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)resetIcon {
|
- (void)resetIcon {
|
||||||
|
|
@ -115,18 +96,12 @@
|
||||||
NSLog(@"Icon reset successfully");
|
NSLog(@"Icon reset successfully");
|
||||||
[self showAlertWithTitle:@"Success" message:@"Icon reset successfully"];
|
[self showAlertWithTitle:@"Success" message:@"Icon reset successfully"];
|
||||||
[self.tableView reloadData];
|
[self.tableView reloadData];
|
||||||
self.iconPreview.image = nil;
|
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)saveIcon {
|
- (void)saveIcon {
|
||||||
NSString *selectedIconPath;
|
NSString *selectedIconPath = self.selectedIconIndex >= 0 ? self.appIcons[self.selectedIconIndex] : nil;
|
||||||
if (self.selectedIconIndex == -1) {
|
|
||||||
selectedIconPath = nil;
|
|
||||||
} else {
|
|
||||||
selectedIconPath = self.appIcons[self.selectedIconIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
[[UIApplication sharedApplication] setAlternateIconName:selectedIconPath completionHandler:^(NSError * _Nullable error) {
|
[[UIApplication sharedApplication] setAlternateIconName:selectedIconPath completionHandler:^(NSError * _Nullable error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
@ -139,22 +114,12 @@
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UIImage *)resizedImageWithImage:(UIImage *)image {
|
|
||||||
CGFloat scale = [UIScreen mainScreen].scale;
|
|
||||||
CGSize newSize = CGSizeMake(image.size.width / scale, image.size.height / scale);
|
|
||||||
UIGraphicsBeginImageContextWithOptions(newSize, NO, scale);
|
|
||||||
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
|
|
||||||
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
||||||
UIGraphicsEndImageContext();
|
|
||||||
return resizedImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)showAlertWithTitle:(NSString *)title message:(NSString *)message {
|
- (void)showAlertWithTitle:(NSString *)title message:(NSString *)message {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
|
YTAlertView *alert = [[YTAlertView alloc] init];
|
||||||
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
|
alert.title = title;
|
||||||
[alert addAction:okAction];
|
alert.subtitle = message;
|
||||||
[self presentViewController:alert animated:YES completion:nil];
|
[alert show];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue