2022-12-29 10:39:34 +01:00
|
|
|
import DesignSystem
|
2023-01-17 11:36:01 +01:00
|
|
|
import SwiftUI
|
2022-12-04 09:50:25 +01:00
|
|
|
|
|
|
|
struct IconSelectorView: View {
|
2022-12-31 14:01:00 +01:00
|
|
|
enum Icon: Int, CaseIterable, Identifiable {
|
2022-12-04 09:50:25 +01:00
|
|
|
var id: String {
|
2022-12-31 14:01:00 +01:00
|
|
|
"\(rawValue)"
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2022-12-31 14:01:00 +01:00
|
|
|
init(string: String) {
|
|
|
|
if string == Icon.primary.appIconName {
|
|
|
|
self = .primary
|
|
|
|
} else {
|
2023-01-21 07:21:51 +01:00
|
|
|
self = .init(rawValue: Int(String(string.replacing("AppIconAlternate", with: "")))!)!
|
2022-12-31 14:01:00 +01:00
|
|
|
}
|
|
|
|
}
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2022-12-31 14:01:00 +01:00
|
|
|
case primary = 0
|
|
|
|
case alt1, alt2, alt3, alt4, alt5, alt6, alt7, alt8
|
|
|
|
case alt9, alt10, alt11, alt12, alt13, alt14
|
2023-01-07 16:53:34 +01:00
|
|
|
case alt15, alt16, alt17, alt18, alt19
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2022-12-31 14:01:00 +01:00
|
|
|
var appIconName: String {
|
2022-12-27 21:35:41 +01:00
|
|
|
switch self {
|
2022-12-31 14:01:00 +01:00
|
|
|
case .primary:
|
|
|
|
return "AppIcon"
|
|
|
|
default:
|
|
|
|
return "AppIconAlternate\(rawValue)"
|
2022-12-27 21:35:41 +01:00
|
|
|
}
|
|
|
|
}
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2022-12-31 14:01:00 +01:00
|
|
|
var iconName: String {
|
|
|
|
"icon\(rawValue)"
|
|
|
|
}
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2022-12-29 10:39:34 +01:00
|
|
|
@EnvironmentObject private var theme: Theme
|
2022-12-31 14:01:00 +01:00
|
|
|
@State private var currentIcon = UIApplication.shared.alternateIconName ?? Icon.primary.appIconName
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2022-12-04 09:50:25 +01:00
|
|
|
private let columns = [GridItem(.adaptive(minimum: 125, maximum: 1024))]
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2022-12-04 09:50:25 +01:00
|
|
|
var body: some View {
|
|
|
|
ScrollView {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
LazyVGrid(columns: columns, spacing: 6) {
|
|
|
|
ForEach(Icon.allCases) { icon in
|
|
|
|
Button {
|
2022-12-31 14:01:00 +01:00
|
|
|
currentIcon = icon.appIconName
|
2022-12-04 09:50:25 +01:00
|
|
|
if icon.rawValue == Icon.primary.rawValue {
|
|
|
|
UIApplication.shared.setAlternateIconName(nil)
|
|
|
|
} else {
|
2022-12-31 14:01:00 +01:00
|
|
|
UIApplication.shared.setAlternateIconName(icon.appIconName)
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
ZStack(alignment: .bottomTrailing) {
|
2022-12-27 21:35:41 +01:00
|
|
|
Image(uiImage: .init(named: icon.iconName) ?? .init())
|
2022-12-04 09:50:25 +01:00
|
|
|
.resizable()
|
|
|
|
.aspectRatio(contentMode: .fit)
|
|
|
|
.frame(minHeight: 125, maxHeight: 1024)
|
|
|
|
.cornerRadius(6)
|
|
|
|
.shadow(radius: 3)
|
2022-12-31 14:01:00 +01:00
|
|
|
if icon.appIconName == currentIcon {
|
2022-12-04 09:50:25 +01:00
|
|
|
Image(systemName: "checkmark.seal.fill")
|
|
|
|
.padding(4)
|
|
|
|
.tint(.green)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(6)
|
2023-01-19 18:14:08 +01:00
|
|
|
.navigationTitle("settings.app.icon.navigation-title")
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
2022-12-29 10:39:34 +01:00
|
|
|
.background(theme.primaryBackgroundColor)
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
|
|
|
}
|