From 44ade05e53ee64728506987d4627372d9629b305 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Wed, 21 Feb 2024 14:06:56 -0600 Subject: [PATCH] Displays checkmark next to current alternate app icon --- .../Settings/AltAppIconsViewController.swift | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/AltStore/Settings/AltAppIconsViewController.swift b/AltStore/Settings/AltAppIconsViewController.swift index 10b016a6..44e9f0bc 100644 --- a/AltStore/Settings/AltAppIconsViewController.swift +++ b/AltStore/Settings/AltAppIconsViewController.swift @@ -20,6 +20,8 @@ extension UIApplication private final class AltIcon: Decodable { + static let defaultIconName: String = "AppIcon" + var name: String var imageName: String @@ -150,6 +152,15 @@ private extension AltAppIconsViewController config.imageProperties.cornerRadius = imageWidth / 5.0 // Copied from AppIconImageView cell.contentConfiguration = config + + if UIApplication.shared.alternateIconName == icon.imageName || (UIApplication.shared.alternateIconName == nil && icon.imageName == AltIcon.defaultIconName) + { + cell.accessories = [.checkmark(options: .init(tintColor: .white))] + } + else + { + cell.accessories = [] + } var backgroundConfiguration = UIBackgroundConfiguration.listPlainCell() backgroundConfiguration.backgroundColorTransformer = UIConfigurationColorTransformer { [weak cell] c in @@ -181,11 +192,12 @@ extension AltAppIconsViewController override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - self.collectionView.selectItem(at: indexPath, animated: true, scrollPosition: .centeredVertically) - let icon = self.dataSource.item(at: indexPath) guard UIApplication.shared.alternateIconName != icon.imageName else { return } + // Deselect previous icon + select new icon + collectionView.reloadData() + // If assigning primary icon, pass "nil" as alternate icon name. let imageName = (icon.imageName == "AppIcon") ? nil : icon.imageName UIApplication.shared.setAlternateIconName(imageName) { error in @@ -196,16 +208,13 @@ extension AltAppIconsViewController preferredStyle: .alert) alertController.addAction(.ok) self.present(alertController, animated: true) + + collectionView.reloadData() } else { NotificationCenter.default.post(name: UIApplication.didChangeAppIconNotification, object: icon) } - - if let selectedIndexPath = self.collectionView.indexPathsForSelectedItems?.first - { - self.collectionView.deselectItem(at: selectedIndexPath, animated: true) - } } } }