mirror of
				https://github.com/SoPat712/YTLitePlus.git
				synced 2025-10-31 04:44:14 -04:00 
			
		
		
		
	Improved AppIconOptionsController Interface
This commit is contained in:
		| @@ -6,6 +6,7 @@ | |||||||
| @property (strong, nonatomic) NSArray<NSString *> *appIcons; | @property (strong, nonatomic) NSArray<NSString *> *appIcons; | ||||||
| @property (assign, nonatomic) NSInteger selectedIconIndex; | @property (assign, nonatomic) NSInteger selectedIconIndex; | ||||||
| @property (strong, nonatomic) UIImageView *backButton; | @property (strong, nonatomic) UIImageView *backButton; | ||||||
|  | @property (assign, nonatomic) UIUserInterfaceStyle pageStyle; | ||||||
|  |  | ||||||
| @end | @end | ||||||
|  |  | ||||||
| @@ -15,30 +16,24 @@ | |||||||
|     [super viewDidLoad]; |     [super viewDidLoad]; | ||||||
|  |  | ||||||
|     self.title = @"Change App Icon"; |     self.title = @"Change App Icon"; | ||||||
|     [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"YTSans-Bold" size:17], NSForegroundColorAttributeName: [UIColor whiteColor]}]; |     [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"YTSans-Bold" size:22], NSForegroundColorAttributeName: [UIColor whiteColor]}]; | ||||||
|  |  | ||||||
|     self.selectedIconIndex = -1; |     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; | ||||||
|     self.tableView.delegate = self; |     self.tableView.delegate = self; | ||||||
|  |     self.tableView.backgroundColor = (self.pageStyle == UIUserInterfaceStyleLight) ? [UIColor whiteColor] : [UIColor blackColor]; | ||||||
|     [self.view addSubview:self.tableView]; |     [self.view addSubview:self.tableView]; | ||||||
|  |  | ||||||
|     UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(back)]; |     UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Back.png" inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil] style:UIBarButtonItemStylePlain target:self action:@selector(back)]; | ||||||
|     UIImage *backImage = [UIImage imageNamed:@"yt_outline_chevron_left_ios_24pt" inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil]; |     [backButton setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor blackColor], NSFontAttributeName: [UIFont fontWithName:@"YTSans-Medium" size:20]} forState:UIControlStateNormal]; | ||||||
|     if (!backImage) { |  | ||||||
|         backButton.image = [UIImage systemImageNamed:@"chevron.backward"]; |  | ||||||
|     } else { |  | ||||||
|         backButton.image = backImage; |  | ||||||
|     } |  | ||||||
|     [backButton setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: [UIFont fontWithName:@"YTSans-Medium" size:17]} forState:UIControlStateNormal]; |  | ||||||
|     self.navigationItem.leftBarButtonItem = backButton; |     self.navigationItem.leftBarButtonItem = backButton; | ||||||
|  |  | ||||||
|     UIBarButtonItem *resetButton = [[UIBarButtonItem alloc] initWithTitle:@"Reset" style:UIBarButtonItemStylePlain target:self action:@selector(resetIcon)]; |     UIBarButtonItem *resetButton = [[UIBarButtonItem alloc] initWithImage:[UIImage systemImageNamed:@"arrow.clockwise.circle.fill"] style:UIBarButtonItemStylePlain target:self action:@selector(resetIcon)]; | ||||||
|     [resetButton setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: [UIFont fontWithName:@"YTSans-Medium" size:17]} forState:UIControlStateNormal]; |  | ||||||
|  |  | ||||||
|     UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(saveIcon)]; |     UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(saveIcon)]; | ||||||
|     [saveButton setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: [UIFont fontWithName:@"YTSans-Medium" size:17]} forState:UIControlStateNormal]; |     [saveButton setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:203.0/255.0 green:22.0/255.0 blue:51.0/255.0 alpha:1.0], NSFontAttributeName: [UIFont fontWithName:@"YTSans-Medium" size:20]} forState:UIControlStateNormal]; | ||||||
|  |  | ||||||
|     self.navigationItem.rightBarButtonItems = @[saveButton, resetButton]; |     self.navigationItem.rightBarButtonItems = @[saveButton, resetButton]; | ||||||
|  |  | ||||||
| @@ -55,10 +50,6 @@ | |||||||
|     return self.appIcons.count; |     return self.appIcons.count; | ||||||
| } | } | ||||||
|  |  | ||||||
| - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { |  | ||||||
|     return 60.0; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | ||||||
|     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; |     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; | ||||||
|     if (!cell) { |     if (!cell) { | ||||||
| @@ -66,12 +57,21 @@ | |||||||
|     } |     } | ||||||
|      |      | ||||||
|     NSString *iconPath = self.appIcons[indexPath.row]; |     NSString *iconPath = self.appIcons[indexPath.row]; | ||||||
|     cell.textLabel.text = [iconPath.lastPathComponent stringByDeletingPathExtension]; |  | ||||||
|      |  | ||||||
|     UIImage *iconImage = [UIImage imageWithContentsOfFile:iconPath]; |     UIImage *iconImage = [UIImage imageWithContentsOfFile:iconPath]; | ||||||
|     cell.imageView.image = iconImage; |  | ||||||
|     cell.imageView.layer.cornerRadius = 10.0; |     cell.backgroundColor = [UIColor whiteColor]; | ||||||
|     cell.imageView.clipsToBounds = YES; |     cell.selectionStyle = UITableViewCellSelectionStyleNone; | ||||||
|  |  | ||||||
|  |     UIImageView *iconImageView = [[UIImageView alloc] initWithImage:iconImage]; | ||||||
|  |     iconImageView.contentMode = UIViewContentModeScaleAspectFit; | ||||||
|  |     iconImageView.frame = CGRectMake(16, 10, 30, 30); | ||||||
|  |     [cell.contentView addSubview:iconImageView]; | ||||||
|  |  | ||||||
|  |     UILabel *iconNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(56, 5, self.view.frame.size.width - 56, 30)]; | ||||||
|  |     iconNameLabel.text = [iconPath.lastPathComponent stringByDeletingPathExtension]; | ||||||
|  |     iconNameLabel.textColor = [UIColor blackColor]; | ||||||
|  |     iconNameLabel.font = [UIFont systemFontOfSize:16.0 weight:UIFontWeightMedium]; | ||||||
|  |     [cell.contentView addSubview:iconNameLabel]; | ||||||
|  |  | ||||||
|     if (indexPath.row == self.selectedIconIndex) { |     if (indexPath.row == self.selectedIconIndex) { | ||||||
|         cell.accessoryType = UITableViewCellAccessoryCheckmark; |         cell.accessoryType = UITableViewCellAccessoryCheckmark; | ||||||
| @@ -79,6 +79,10 @@ | |||||||
|         cell.accessoryType = UITableViewCellAccessoryNone; |         cell.accessoryType = UITableViewCellAccessoryNone; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     UIView *separatorView = [[UIView alloc] initWithFrame:CGRectMake(0, cell.contentView.frame.size.height - 1, cell.contentView.frame.size.width, 1)]; | ||||||
|  |     separatorView.backgroundColor = [UIColor lightGrayColor]; | ||||||
|  |     [cell.contentView addSubview:separatorView]; | ||||||
|  |  | ||||||
|     return cell; |     return cell; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -104,16 +108,27 @@ | |||||||
|  |  | ||||||
| - (void)saveIcon { | - (void)saveIcon { | ||||||
|     NSString *selectedIconPath = self.selectedIconIndex >= 0 ? self.appIcons[self.selectedIconIndex] : nil; |     NSString *selectedIconPath = self.selectedIconIndex >= 0 ? self.appIcons[self.selectedIconIndex] : nil; | ||||||
|      |     if (selectedIconPath) { | ||||||
|     [[UIApplication sharedApplication] setAlternateIconName:selectedIconPath completionHandler:^(NSError * _Nullable error) { |         NSURL *iconURL = [NSURL fileURLWithPath:selectedIconPath]; | ||||||
|         if (error) { |         if ([[UIApplication sharedApplication] respondsToSelector:@selector(setAlternateIconName:completionHandler:)]) { | ||||||
|             NSLog(@"Error setting alternate icon: %@", error.localizedDescription); |             [[UIApplication sharedApplication] setAlternateIconName:selectedIconPath completionHandler:^(NSError * _Nullable error) { | ||||||
|             [self showAlertWithTitle:@"Error" message:@"Failed to set alternate icon"]; |                 if (error) { | ||||||
|  |                     NSLog(@"Error setting alternate icon: %@", error.localizedDescription); | ||||||
|  |                     [self showAlertWithTitle:@"Error" message:@"Failed to set alternate icon"]; | ||||||
|  |                 } else { | ||||||
|  |                     NSLog(@"Alternate icon set successfully"); | ||||||
|  |                     [self showAlertWithTitle:@"Success" message:@"Alternate icon set successfully"]; | ||||||
|  |                 } | ||||||
|  |             }]; | ||||||
|         } else { |         } else { | ||||||
|             NSLog(@"Alternate icon set successfully"); |             NSMutableDictionary *dict = [NSMutableDictionary dictionary]; | ||||||
|             [self showAlertWithTitle:@"Success" message:@"Alternate icon set successfully"]; |             [dict setObject:iconURL forKey:@"iconURL"]; | ||||||
|  |             NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"]; | ||||||
|  |             [dict writeToFile:filePath atomically:YES]; | ||||||
|  |  | ||||||
|  |             [self showAlertWithTitle:@"Alternate Icon" message:@"Please restart the app to apply the alternate icon"]; | ||||||
|         } |         } | ||||||
|     }]; |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| - (void)showAlertWithTitle:(NSString *)title message:(NSString *)message { | - (void)showAlertWithTitle:(NSString *)title message:(NSString *)message { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 arichornlover
					arichornlover