# HG changeset patch # User Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> # Date 1614377283 0 # Node ID e965cd71bc3bef154e6c7cb4feafb3a03a9d5847 # Parent 1675ccedeb06166b73d4aadbf9d4081d69d3da04 Implement Icon Selector in production diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear.xcodeproj/project.pbxproj --- a/LazyBear.xcodeproj/project.pbxproj Fri Feb 26 21:26:40 2021 +0000 +++ b/LazyBear.xcodeproj/project.pbxproj Fri Feb 26 22:08:03 2021 +0000 @@ -7,9 +7,12 @@ objects = { /* Begin PBXBuildFile section */ + 950B674925E99FA900BF8593 /* IconPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950B674825E99FA900BF8593 /* IconPicker.swift */; }; + 950B674C25E9A03E00BF8593 /* alternativeIcons.json in Resources */ = {isa = PBXBuildFile; fileRef = 950B674B25E9A03E00BF8593 /* alternativeIcons.json */; }; + 950B674F25E9A0AE00BF8593 /* IconModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950B674E25E9A0AE00BF8593 /* IconModel.swift */; }; + 950B675225E9A51700BF8593 /* IconRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950B675125E9A51700BF8593 /* IconRow.swift */; }; 9549D63325E1903F0085C3CD /* Charts in Frameworks */ = {isa = PBXBuildFile; productRef = 9549D63225E1903F0085C3CD /* Charts */; }; 9549D63625E191520085C3CD /* Normalize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9549D63525E191520085C3CD /* Normalize.swift */; }; - 9564E66A25E989EC00A54D7D /* TestAlternative.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9564E66925E989EC00A54D7D /* TestAlternative.swift */; }; 95672B8F25DDA54700DCBE4A /* LazyBearApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95672B8E25DDA54700DCBE4A /* LazyBearApp.swift */; }; 95672B9125DDA54700DCBE4A /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95672B9025DDA54700DCBE4A /* ContentView.swift */; }; 95672B9325DDA54700DCBE4A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 95672B9225DDA54700DCBE4A /* Assets.xcassets */; }; @@ -51,10 +54,13 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 950B674825E99FA900BF8593 /* IconPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconPicker.swift; sourceTree = ""; }; + 950B674B25E9A03E00BF8593 /* alternativeIcons.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = alternativeIcons.json; sourceTree = ""; }; + 950B674E25E9A0AE00BF8593 /* IconModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconModel.swift; sourceTree = ""; }; + 950B675125E9A51700BF8593 /* IconRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconRow.swift; sourceTree = ""; }; 950BA46B25E944F500D065EF /* Production.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Production.xcconfig; sourceTree = ""; }; 950BA46C25E944FC00D065EF /* Sandbox.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Sandbox.xcconfig; sourceTree = ""; }; 9549D63525E191520085C3CD /* Normalize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Normalize.swift; sourceTree = ""; }; - 9564E66925E989EC00A54D7D /* TestAlternative.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestAlternative.swift; sourceTree = ""; }; 95672B8B25DDA54700DCBE4A /* LazyBear.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LazyBear.app; sourceTree = BUILT_PRODUCTS_DIR; }; 95672B8E25DDA54700DCBE4A /* LazyBearApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazyBearApp.swift; sourceTree = ""; }; 95672B9025DDA54700DCBE4A /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; @@ -142,7 +148,6 @@ 95672B8D25DDA54700DCBE4A /* LazyBear */ = { isa = PBXGroup; children = ( - 95F0463425E98788006A5A17 /* Alternative icons */, 958A734E25E016FD00FD7ECA /* LazyBear.entitlements */, 95672B9C25DDA54800DCBE4A /* Info.plist */, 95672B9925DDA54800DCBE4A /* LazyBear.xcdatamodeld */, @@ -153,11 +158,11 @@ 95672B9025DDA54700DCBE4A /* ContentView.swift */, 95BFAE4D25E2B0C200A70EC3 /* HUDManager.swift */, 95672B9725DDA54700DCBE4A /* Persistence.swift */, - 9564E66925E989EC00A54D7D /* TestAlternative.swift */, 95B1874925DDAC4D0068A364 /* UI */, 95B1874825DDAC470068A364 /* Models */, 958A735525E01F7E00FD7ECA /* Functions */, 958A733225E00B9200FD7ECA /* Local data */, + 95F0463425E98788006A5A17 /* Resources */, 950BA46D25E9450B00D065EF /* Tests */, 95672B9425DDA54700DCBE4A /* Preview Content */, ); @@ -177,6 +182,7 @@ children = ( 95ACB5AB25E03A7D00A3CCC8 /* themes.json */, 95F045FA25E96A58006A5A17 /* newsLanguages.json */, + 950B674B25E9A03E00BF8593 /* alternativeIcons.json */, ); path = "Local data"; sourceTree = ""; @@ -207,6 +213,7 @@ 95ABDD3725E167E500310776 /* NewsModel.swift */, 95BFAE5325E2C52300A70EC3 /* HistoricalPriceModel.swift */, 95F045FD25E96AA1006A5A17 /* NewsLanguageModel.swift */, + 950B674E25E9A0AE00BF8593 /* IconModel.swift */, ); path = Models; sourceTree = ""; @@ -221,6 +228,8 @@ 958A735E25E0311B00FD7ECA /* Settings.swift */, 95F0460725E9704F006A5A17 /* ThemePicker.swift */, 95F0460A25E970DB006A5A17 /* NewsLanguagePicker.swift */, + 950B674825E99FA900BF8593 /* IconPicker.swift */, + 950B675125E9A51700BF8593 /* IconRow.swift */, 95F0460F25E976B5006A5A17 /* SettingRow.swift */, 95ABDD3025E1602D00310776 /* PriceView.swift */, 95ACB5A825E0397B00A3CCC8 /* CompanyView.swift */, @@ -232,13 +241,13 @@ path = UI; sourceTree = ""; }; - 95F0463425E98788006A5A17 /* Alternative icons */ = { + 95F0463425E98788006A5A17 /* Resources */ = { isa = PBXGroup; children = ( 95F0462625E98376006A5A17 /* default.png */, 95F0461B25E98015006A5A17 /* angry.png */, ); - path = "Alternative icons"; + path = Resources; sourceTree = ""; }; /* End PBXGroup section */ @@ -312,6 +321,7 @@ 95ACB5AC25E03A7D00A3CCC8 /* themes.json in Resources */, 95F045FB25E96A58006A5A17 /* newsLanguages.json in Resources */, 95672B9325DDA54700DCBE4A /* Assets.xcassets in Resources */, + 950B674C25E9A03E00BF8593 /* alternativeIcons.json in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -324,6 +334,7 @@ files = ( 95ABDD3825E167E500310776 /* NewsModel.swift in Sources */, 95ABDD3C25E1717300310776 /* NewsRow.swift in Sources */, + 950B674925E99FA900BF8593 /* IconPicker.swift in Sources */, 958A735725E01F9E00FD7ECA /* ReadJson.swift in Sources */, 958A734925E010F900FD7ECA /* Search.swift in Sources */, 958A735F25E0311B00FD7ECA /* Settings.swift in Sources */, @@ -337,8 +348,8 @@ 95BFAE5825E2C5A700A70EC3 /* HistoricalPriceView.swift in Sources */, 9549D63625E191520085C3CD /* Normalize.swift in Sources */, 95672B9125DDA54700DCBE4A /* ContentView.swift in Sources */, - 9564E66A25E989EC00A54D7D /* TestAlternative.swift in Sources */, 95F0460425E96DBB006A5A17 /* UserSettings+CoreDataClass.swift in Sources */, + 950B674F25E9A0AE00BF8593 /* IconModel.swift in Sources */, 958A733B25E00C3100FD7ECA /* Company+CoreDataProperties.swift in Sources */, 95ACB5AF25E03AA100A3CCC8 /* ThemeModel.swift in Sources */, 95672B8F25DDA54700DCBE4A /* LazyBearApp.swift in Sources */, @@ -348,6 +359,7 @@ 958A734C25E010FF00FD7ECA /* SearchBar.swift in Sources */, 95F0460B25E970DB006A5A17 /* NewsLanguagePicker.swift in Sources */, 95ABDD3125E1602D00310776 /* PriceView.swift in Sources */, + 950B675225E9A51700BF8593 /* IconRow.swift in Sources */, 95BFAE4B25E2AEA000A70EC3 /* HUD.swift in Sources */, 95F0460525E96DBB006A5A17 /* UserSettings+CoreDataProperties.swift in Sources */, 958A733A25E00C3100FD7ECA /* Company+CoreDataClass.swift in Sources */, diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear/Alternative icons/angry.png Binary file LazyBear/Alternative icons/angry.png has changed diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear/Alternative icons/default.png Binary file LazyBear/Alternative icons/default.png has changed diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear/Assets.xcassets/Alternative icon/Contents.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Assets.xcassets/Alternative icon/Contents.json Fri Feb 26 22:08:03 2021 +0000 @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear/Assets.xcassets/Alternative icon/angryIcon.imageset/Contents.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Assets.xcassets/Alternative icon/angryIcon.imageset/Contents.json Fri Feb 26 22:08:03 2021 +0000 @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "angry.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear/Assets.xcassets/Alternative icon/angryIcon.imageset/angry.png Binary file LazyBear/Assets.xcassets/Alternative icon/angryIcon.imageset/angry.png has changed diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear/Assets.xcassets/Alternative icon/defaultIcon.imageset/Contents.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Assets.xcassets/Alternative icon/defaultIcon.imageset/Contents.json Fri Feb 26 22:08:03 2021 +0000 @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "default.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear/Assets.xcassets/Alternative icon/defaultIcon.imageset/default.png Binary file LazyBear/Assets.xcassets/Alternative icon/defaultIcon.imageset/default.png has changed diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear/Functions/ReadJson.swift --- a/LazyBear/Functions/ReadJson.swift Fri Feb 26 21:26:40 2021 +0000 +++ b/LazyBear/Functions/ReadJson.swift Fri Feb 26 22:08:03 2021 +0000 @@ -9,6 +9,7 @@ let themes: [ThemeModel] = load("themes.json") let newsLanguages: [NewsLanguageModel] = load("newsLanguages.json") +let icons: [IconModel] = load("alternativeIcons.json") func load(_ filename: String) -> T { let data: Data diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear/Info.plist --- a/LazyBear/Info.plist Fri Feb 26 21:26:40 2021 +0000 +++ b/LazyBear/Info.plist Fri Feb 26 22:08:03 2021 +0000 @@ -67,7 +67,7 @@ CFBundleAlternateIcons - AppIcon-1 + angryIcon CFBundleIconFiles diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear/LazyBearApp.swift --- a/LazyBear/LazyBearApp.swift Fri Feb 26 21:26:40 2021 +0000 +++ b/LazyBear/LazyBearApp.swift Fri Feb 26 22:08:03 2021 +0000 @@ -13,7 +13,7 @@ var body: some Scene { WindowGroup { - TestAlternative() + ContentView() .environment(\.managedObjectContext, persistenceController.container.viewContext) } } diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear/Local data/alternativeIcons.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Local data/alternativeIcons.json Fri Feb 26 22:08:03 2021 +0000 @@ -0,0 +1,10 @@ +[ + { + "name": "Default", + "file": "defaultIcon" + }, + { + "name": "Angry bear", + "file": "angryIcon" + } +] diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear/Models/IconModel.swift --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Models/IconModel.swift Fri Feb 26 22:08:03 2021 +0000 @@ -0,0 +1,13 @@ +// +// IconModel.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 26/2/21. +// + +import SwiftUI + +struct IconModel: Codable, Hashable { + var name: String + var file: String +} diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear/Resources/angry.png Binary file LazyBear/Resources/angry.png has changed diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear/Resources/default.png Binary file LazyBear/Resources/default.png has changed diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear/TestAlternative.swift --- a/LazyBear/TestAlternative.swift Fri Feb 26 21:26:40 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -// -// TestAlternative.swift -// LazyBear -// -// Created by Dennis Concepción Martín on 26/2/21. -// - -import SwiftUI - -struct TestAlternative: View { - var body: some View { - VStack { - Button(action: { UIApplication.shared.setAlternateIconName(nil) }) { - Text("Default") - } - Button(action: { changeIcon(key: "AppIcon-1") }) { - Text("Angry") - } - } - } - - private func changeIcon(key: String) { - UIApplication.shared.setAlternateIconName(key) { error in - if let error = error { - print(error.localizedDescription) - } else { - print("Success!") - } - } - } -} - -struct TestAlternative_Previews: PreviewProvider { - static var previews: some View { - TestAlternative() - } -} diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear/UI/IconPicker.swift --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/UI/IconPicker.swift Fri Feb 26 22:08:03 2021 +0000 @@ -0,0 +1,26 @@ +// +// IconPicker.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 26/2/21. +// + +import SwiftUI + +struct IconPicker: View { + var body: some View { + List(icons, id:\.name) { icon in + IconRow(icon: icon) + } + .listStyle(GroupedListStyle()) + } +} + +struct IconPicker_Previews: PreviewProvider { + static var previews: some View { + NavigationView { + IconPicker() + + } + } +} diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear/UI/IconRow.swift --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/UI/IconRow.swift Fri Feb 26 22:08:03 2021 +0000 @@ -0,0 +1,49 @@ +// +// IconRow.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 26/2/21. +// + +import SwiftUI + +struct IconRow: View { + var icon: IconModel + + var body: some View { + Button(action: { changeIcon(key: icon.file) }) { + HStack { + Image(icon.file) + .resizable() + .frame(width: 70, height: 70) + + Text(icon.name) + Spacer() + + if UIApplication.shared.alternateIconName ?? "defaultIcon" == icon.file { + Text("Selected") + } + } + } + } + + private func changeIcon(key: String) { + if key != "defaultIcon" { + UIApplication.shared.setAlternateIconName(key) { error in + if let error = error { + print(error.localizedDescription) + } else { + print("Success!") + } + } + } else { + UIApplication.shared.setAlternateIconName(nil) + } + } +} + +struct IconRow_Previews: PreviewProvider { + static var previews: some View { + IconRow(icon: icons[0]) + } +} diff -r 1675ccedeb06 -r e965cd71bc3b LazyBear/UI/Settings.swift --- a/LazyBear/UI/Settings.swift Fri Feb 26 21:26:40 2021 +0000 +++ b/LazyBear/UI/Settings.swift Fri Feb 26 22:08:03 2021 +0000 @@ -20,6 +20,9 @@ let language = userSettings.first?.newsLanguage ?? "en" ThemePicker(theme: theme) NewsLanguagePicker(language: language) + NavigationLink(destination: IconPicker()) { + Text("App icon") + } Section { SettingRow(image: "at", text: "About", colour: .systemBlue)