Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.0.0] app icon 변경 액션 추가 #33

Merged
merged 5 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions KuringApp/KuringApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
A9DAFA562AB1F04B0064F748 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9DAFA552AB1F04B0064F748 /* ContentView.swift */; };
A9DAFA582AB1F04C0064F748 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A9DAFA572AB1F04C0064F748 /* Assets.xcassets */; };
A9DAFA5B2AB1F04C0064F748 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A9DAFA5A2AB1F04C0064F748 /* Preview Assets.xcassets */; };
DF331DAB2AC917E100D0BB08 /* kuring_app.png in Resources */ = {isa = PBXBuildFile; fileRef = DF331DA72AC917E000D0BB08 /* kuring_app.png */; };
DF331DAC2AC917E100D0BB08 /* kuring_app_classic.png in Resources */ = {isa = PBXBuildFile; fileRef = DF331DA82AC917E000D0BB08 /* kuring_app_classic.png */; };
DF331DAD2AC917E100D0BB08 /* kuring_app_sketch.png in Resources */ = {isa = PBXBuildFile; fileRef = DF331DA92AC917E000D0BB08 /* kuring_app_sketch.png */; };
DF331DAE2AC917E100D0BB08 /* kuring_app_blueprint.png in Resources */ = {isa = PBXBuildFile; fileRef = DF331DAA2AC917E000D0BB08 /* kuring_app_blueprint.png */; };
DFE7AB152AC332DB00230934 /* SettingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFE7AB142AC332DB00230934 /* SettingView.swift */; };
DFE7AB172AC33D6700230934 /* AppIconSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFE7AB162AC33D6700230934 /* AppIconSelector.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -43,6 +49,13 @@
A9DAFA572AB1F04C0064F748 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
A9DAFA5A2AB1F04C0064F748 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
A9DAFA662AB1F09B0064F748 /* KuringModulePackage */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = KuringModulePackage; path = ../KuringModulePackage; sourceTree = "<group>"; };
DF062D4A2AC87B6D00FC48C0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
DF331DA72AC917E000D0BB08 /* kuring_app.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = kuring_app.png; sourceTree = "<group>"; };
DF331DA82AC917E000D0BB08 /* kuring_app_classic.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = kuring_app_classic.png; sourceTree = "<group>"; };
DF331DA92AC917E000D0BB08 /* kuring_app_sketch.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = kuring_app_sketch.png; sourceTree = "<group>"; };
DF331DAA2AC917E000D0BB08 /* kuring_app_blueprint.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = kuring_app_blueprint.png; sourceTree = "<group>"; };
DFE7AB142AC332DB00230934 /* SettingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingView.swift; sourceTree = "<group>"; };
DFE7AB162AC33D6700230934 /* AppIconSelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppIconSelector.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -130,6 +143,8 @@
A9DAFA522AB1F04B0064F748 /* KuringApp */ = {
isa = PBXGroup;
children = (
DF062D4A2AC87B6D00FC48C0 /* Info.plist */,
DFE7AB132AC332D200230934 /* Setting */,
A9DAFA532AB1F04B0064F748 /* KuringApp.swift */,
A9B4F0132ABCA86500354C00 /* NoticeApp.swift */,
A9B4F0152ABCA93400354C00 /* NoticeApp.Path.swift */,
Expand All @@ -153,6 +168,27 @@
path = "Preview Content";
sourceTree = "<group>";
};
DF062D4B2AC8800000FC48C0 /* AppLogos */ = {
isa = PBXGroup;
children = (
DF331DAA2AC917E000D0BB08 /* kuring_app_blueprint.png */,
DF331DA82AC917E000D0BB08 /* kuring_app_classic.png */,
DF331DA92AC917E000D0BB08 /* kuring_app_sketch.png */,
DF331DA72AC917E000D0BB08 /* kuring_app.png */,
);
path = AppLogos;
sourceTree = "<group>";
};
DFE7AB132AC332D200230934 /* Setting */ = {
isa = PBXGroup;
children = (
DF062D4B2AC8800000FC48C0 /* AppLogos */,
DFE7AB142AC332DB00230934 /* SettingView.swift */,
DFE7AB162AC33D6700230934 /* AppIconSelector.swift */,
);
path = Setting;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -218,7 +254,11 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DF331DAD2AC917E100D0BB08 /* kuring_app_sketch.png in Resources */,
DF331DAE2AC917E100D0BB08 /* kuring_app_blueprint.png in Resources */,
A9DAFA5B2AB1F04C0064F748 /* Preview Assets.xcassets in Resources */,
DF331DAB2AC917E100D0BB08 /* kuring_app.png in Resources */,
DF331DAC2AC917E100D0BB08 /* kuring_app_classic.png in Resources */,
A9DAFA582AB1F04C0064F748 /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -230,6 +270,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DFE7AB152AC332DB00230934 /* SettingView.swift in Sources */,
A9B4F0142ABCA86500354C00 /* NoticeApp.swift in Sources */,
A965B7AB2AC0750E0026ECDC /* SubscriptionView.swift in Sources */,
A9B4F01A2ABCAF9800354C00 /* NoticeList.swift in Sources */,
Expand All @@ -242,6 +283,7 @@
A9B4F0182ABCA9AF00354C00 /* NoticeDetailView.swift in Sources */,
A965B7AF2AC084D20026ECDC /* SubscriptionApp.swift in Sources */,
A9DAFA542AB1F04B0064F748 /* KuringApp.swift in Sources */,
DFE7AB172AC33D6700230934 /* AppIconSelector.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -378,6 +420,7 @@
DEVELOPMENT_TEAM = 77CD4KLN3Y;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = KuringApp/Info.plist;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
Expand Down Expand Up @@ -407,6 +450,7 @@
DEVELOPMENT_TEAM = 77CD4KLN3Y;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = KuringApp/Info.plist;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"images" : [
{
"filename" : "kuring_app.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions KuringApp/KuringApp/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIcons</key>
<dict>
<key>CFBundleAlternateIcons</key>
<dict>
<key>kuring_app</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>kuring_app</string>
</array>
</dict>
<key>kuring_app_classic</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>kuring_app_classic</string>
</array>
</dict>
<key>kuring_app_blueprint</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>kuring_app_blueprint</string>
</array>
</dict>
<key>kuring_app_sketch</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>kuring_app_sketch</string>
</array>
</dict>
</dict>
</dict>
</dict>
</plist>
143 changes: 143 additions & 0 deletions KuringApp/KuringApp/Setting/AppIconSelector.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
//
// AppIconSelector.swift
// KuringApp
//
// Created by 박성수 on 2023/09/27.
//

import SwiftUI
import ComposableArchitecture

extension DependencyValues {
public var appIcons: AppIcons {
get { self[AppIcons.self] }
set { self[AppIcons.self] = newValue }
}
}

public struct AppIcons: DependencyKey {
public static let liveValue: AppIcons = AppIcons()

@MainActor
func changeTo(_ icon: KuringIcon) async {
guard UIApplication.shared.supportsAlternateIcons else { return }
do {
try await UIApplication.shared.setAlternateIconName(icon.rawValue)
} catch let error {
print(error.localizedDescription)
}
}
}

enum KuringIcon: String, CaseIterable, Identifiable {
var id: String { self.rawValue }
case kuring_app
case kuring_app_classic
case kuring_app_blueprint
case kuring_app_sketch

var korValue: String {
switch self {
case .kuring_app: return "쿠링 기본"
case .kuring_app_classic: return "쿠링 클래식"
case .kuring_app_blueprint: return "쿠링 블루프린트"
case .kuring_app_sketch: return "쿠링 스케치"
}
}
}

struct AppIconSelectFeature: Reducer {
struct State: Equatable {
var appIcons: IdentifiedArrayOf<KuringIcon> = IdentifiedArray(uniqueElements: KuringIcon.allCases)
var selectedIcon: KuringIcon?
}

enum Action: Equatable {
case appIconSelected(KuringIcon)
case saveButtonTapped

// MARK: To SettingView
case delegate(Delegate)
enum Delegate: Equatable {
case alternativeAppIconSave(KuringIcon)
}
}

@Dependency(\.appIcons) var appIcons

var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
case let .appIconSelected(icon):
state.selectedIcon = icon
return .none

case .saveButtonTapped:
return .run { [selectedIcon = state.selectedIcon] send in
guard let selectedIcon else { return }
await appIcons.changeTo(selectedIcon)
await send(.delegate(.alternativeAppIconSave(selectedIcon)))
}

case .delegate:
return .none
}
}
}
}

struct AppIconSelector: View {
let store: StoreOf<AppIconSelectFeature>

var body: some View {
WithViewStore(self.store, observe: { $0 }) { viewStore in
List(viewStore.appIcons) { icon in
HStack {
VStack {
Image(uiImage: UIImage(named: icon.rawValue)!)
.resizable()
.frame(width: 70, height: 70)
.cornerRadius(10)
}
.padding(.trailing)

Button {
viewStore.send(.appIconSelected(icon))
} label: {
Text(icon.korValue)
.foregroundStyle(.black)
}

if icon == viewStore.state.selectedIcon {
withAnimation {
Image(systemName: "checkmark.circle")
}
}
}
}
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button {
viewStore.send(.saveButtonTapped)
} label: {
Text("저장")
}
}
}
}
}
}

#Preview {
AppIconSelector(
store: Store(
initialState:
AppIconSelectFeature.State(
selectedIcon: KuringIcon.kuring_app
),
reducer: {
AppIconSelectFeature()
}
)
)
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading